> ## Documentation Index
> Fetch the complete documentation index at: https://www.getmaxim.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Spans

> Spans help you organize and track requests across microservices within traces. A trace represents the entire journey of a request through your system, while spans are smaller units of work within that trace.

## How to Set Up Spans?

Spans help you organize and track requests across microservices within traces. A trace represents the entire journey of a request through your system, while spans are smaller units of work within that trace.

<div className="w-full flex justify-end -mb-11">
  <LanguageSwitcher />
</div>

<Steps>
  <Step title="Initialize Spans with Trace Object">
    Create spans with trace object

    <CodeGroup>
      ```typescript JS/TS theme={null}
      const trace = logger.trace({id: "trace-id"});

      const span = trace.span({
          id: "span-id",
          name: "customer-support--classify-question",
      });
      ```

      ```python Python theme={null}
      trace = logger.trace({"id": "trace-id"})

      span = trace.span({
          "id":"span-id",
          "name":"customer-support--classify-question"
      })
      ```

      ```go Go theme={null}
      trace := logger.Trace(&logging.TraceConfig{
          Id: "trace-id",
      })

      span := trace.Span(&logging.SpanConfig{
          Id: "span-id",
          Name: "customer-support--classify-question",
      })
      ```

      ```java Java theme={null}
      Trace trace = logger.trace(new TraceConfig(
          "trace-id",
      ));

      Span span = trace.span(new SpanConfig(
          "span-id",
          "customer-support--classify-question"
      ));
      ```
    </CodeGroup>

    <Note>
      Replace 'trace.span' with 'span.span' when creating spans within an existing span
    </Note>
  </Step>

  <Step title="Alternative: Create Spans Using Logger Object">
    <CodeGroup>
      ```typescript JS/TS theme={null}
      const span = logger.traceSpan("trace-id", {
          id: "span-id",
          name: "customer-support--classify-question",
      });
      ```

      ```python Python theme={null}
      span = logger.trace_add_span("trace-id", {
          "id":"span-id",
          "name":"customer-support--classify-question"
      })
      ```

      ```go Go theme={null}
      span := logger.AddSpanToTrace("trace-id", &logging.SpanConfig{
          Id: "span-id",
          Name: "customer-support--classify-question",
      })
      ```

      ```java Java theme={null}
      Span span = logger.traceAddSpan("trace-id", new SpanConfig(
          "span-id",
          "customer-support--classify-question"
      ));
      ```
    </CodeGroup>
  </Step>
</Steps>

<img src="https://mintcdn.com/maximai/fHnWe0mnvuD5228y/images/docs/tracing/via-sdk/span.png?fit=max&auto=format&n=fHnWe0mnvuD5228y&q=85&s=833b225a9ad8564571196e99759ba57e" alt="Spans" width="2388" height="1704" data-path="images/docs/tracing/via-sdk/span.png" />

<Note>[Schedule a demo](https://getmaxim.ai/demo) to see how Maxim AI helps teams ship reliable agents.</Note>
