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

# Distributed Tracing

> Visualize and analyze distributed traces in OpenLIT platform with detailed span analysis and performance insights

OpenLIT provides OpenTelemetry Auto instrumentation for various LLM providers, frameworks, and VectorDBs, providing you with insights into the behavior and performance of your AI applications.

This documentation covers tracing settings, understanding semantic conventions, and interpreting span attributes to enhance the monitoring and observability of your LLM applications.

<CardGroup cols={2}>
  <Card title="Quickstart: LLM Observablity" href="/latest/sdk/quickstart-ai-observability" icon="bolt">
    Production-ready AI monitoring setup in 2 simple steps with zero code changes
  </Card>

  <Card title="Integrations" href="/latest/sdk/integrations/overview" icon="circle-nodes">
    60+ AI integrations with automatic instrumentation and performance tracking
  </Card>
</CardGroup>

## Using an existing OTel Tracer

You have the flexibility to integrate your existing OpenTelemetry (OTel) tracer configuration with OpenLIT.
If you already have an OTel tracer instantiated in your application, you can pass it directly to `openlit.init(tracer=tracer)`.
This integration ensures that OpenLIT utilizes your custom tracer settings, allowing for a unified tracing setup across your application.

Example:

```python theme={null}
# Instantiate an OpenTelemetry Tracer
tracer = ...

# Pass the tracer to OpenLIT
openlit.init(tracer=tracer)
```

## Add custom resource attributes

The [`OTEL_RESOURCE_ATTRIBUTES`](https://opentelemetry.io/docs/languages/sdk-configuration/general/#otel_resource_attributes) environment variable allows you to provide additional OpenTelemetry resource attributes when starting your application with OpenLIT. OpenLIT already includes some default resource attributes:

* `telemetry.sdk.name: openlit`
* `service.name: YOUR_SERVICE_NAME`
* `deployment.environment: YOUR_ENVIRONMENT_NAME`

You can enhance these default resource attributes by adding your own using the `OTEL_RESOURCE_ATTRIBUTES` variable. Your custom attributes will be added on top of the existing OpenLIT attributes, providing additional context to your telemetry data. Simply format your attributes as `key1=value1,key2=value2`.

For example:

```shell theme={null}
export OTEL_RESOURCE_ATTRIBUTES="service.instance.id=YOUR_SERVICE_ID,k8s.pod.name=K8S_POD_NAME,k8s.namespace.name=K8S_NAMESPACE,k8s.node.name=K8S_NODE_NAME"
```

## Disable Tracing of Content

By default, OpenLIT adds the prompts and completions to Trace span attributes.

However, you may want to disable this logging for privacy reasons, as they may contain highly sensitive data from your users. You may also simply want to reduce the size of your traces.

Example:

```python theme={null}
openlit.init(capture_message_content=False)
```

## Limit Content Length

By default, OpenLIT captures full prompt and completion content without any truncation. If you want to limit the size of captured content (for example, to reduce trace storage costs or avoid excessively large spans), set `max_content_length` to a positive integer. Content exceeding the limit will be truncated with `...` appended.

A value of `None` (the default), `0`, or `-1` disables truncation entirely.

Example:

```python theme={null}
# Truncate all captured content to 500 characters
openlit.init(max_content_length=500)
```

You can also set this via the environment variable:

```bash theme={null}
export OPENLIT_MAX_CONTENT_LENGTH=500
```

## Disable Batch

By default, the SDK batches spans using the OpenTelemetry batch span processor. When working locally, sometimes you may wish to disable this behavior. You can do that with this flag.

Example:

```python theme={null}
openlit.init(disable_batch=True)
```

## Disable Instrumentations

By default, OpenLIT automatically detects which models and frameworks you are using and instruments them for you. You can override this and disable instrumentation for specific frameworks and models.

Example:

```python theme={null}
openlit.init(disabled_instrumentors=["anthropic", "langchain"])
```

## Manual Tracing

Using `openlit.trace`, you get access to manually create traces, allowing you to record every process within a single function.

```python python theme={null}
@openlit.trace
def generate_one_liner():
    completion = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {
                "role": "system",
                "content": "Return a one liner from any movie for me to guess",
            }
        ],
    )
```

The `trace` function automatically groups any LLM function invoked within `generate_one_liner`, providing you with organized groupings right out of the box.

You can do more with traces by running the `start_trace` context generator:

```python python theme={null}
with openlit.start_trace(name="<GIVE_TRACE_A_NAME>") as trace:
    # your code
```

Use `trace.set_result('')` to set the final result of the trace and `trace.set_metadata({})` to add custom metadata.

**Full Example**

```python python theme={null}
@openlit.trace
def generate_one_liner():
    completion = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {
                "role": "system",
                "content": "Return a one liner from any movie for me to guess",
            }
        ],
    )

def guess_one_liner(one_liner: str):
    with openlit.start_trace("Guess One-liner") as trace:
        completion = client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
                {
                    "role": "user",
                    "content": f"Guess movie from this line: {one_liner}",
                }
            ],
        )
        trace.set_result(completion.choices[0].message.content)
```

***

<CardGroup cols={3}>
  <Card title="Deploy OpenLIT" href="/latest/openlit/installation" icon="circle-down">
    Deployment options for scalable LLM monitoring infrastructure
  </Card>

  <Card title="Integrations" href="/latest/sdk/integrations/overview" icon="circle-nodes">
    60+ AI integrations with automatic instrumentation and performance tracking
  </Card>

  <Card title="Destinations" href="/latest/sdk/destinations/overview" icon="link">
    Send elemetry to Datadog, Grafana, New Relic, and other observability stacks
  </Card>
</CardGroup>

<Card title="Zero-code observability with the OpenLIT Controller" icon="tower-broadcast" href="/latest/controller/overview">
  Discover and instrument LLM traffic across Kubernetes, Docker, and Linux using eBPF — no code changes required.
</Card>
