Skip to content
agentgateway has joined the Agentic AI Foundation — Learn more

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Set up and customize traces

Page as Markdown

Configure tracing in agentgateway: enable OTLP export, set up authentication and TLS, control the sampling rate, filter spans, and customize span attributes.

Agentgateway natively exports distributed traces over OTLP (OpenTelemetry Protocol). Traces include HTTP, MCP, and LLM spans with attributes that follow the OpenTelemetry semantic conventions for generative AI.

Enable tracing

To enable tracing in agentgateway, add a tracing block under the frontendPolicies section and point agentgateway to your OTLP-compatible backend. For sample tracing backend setups, see Sample tracing configurations.

You can enable tracing in the UI or in your configuration file.

Whether the UI can save depends on your storage mode. For more information, see Save changes from the UI.

  1. Open the Settings > Observability page, such as http://localhost:15000/ui/settings/observability.

  2. Click the Tracing card.

  3. In the Tracing drawer, configure the following fields.

    1. Host: Enter the hostname and port of the OTLP receiver, such as localhost:4317.
    2. Protocol: Keep gRPC. The UI does not write the default protocol: grpc value to your configuration.
    3. Random sampling: Enter true.
    Tracing drawer with the gRPC protocol in the Export section and random sampling set to true in the Sampling section
    Tracing drawer with the gRPC protocol in the Export section and random sampling set to true in the Sampling section
  4. Click Save policy. The Tracing card shows enabled.

The UI saves the policy under frontendPolicies.tracing in your configuration.

FieldDescription
hostHostname and port of the OTLP receiver. The value depends on your agentgateway installation method. For more information, see Sample tracing backend configurations.
randomSamplingtrue to sample every request, or a decimal between 0 and 1 for a percentage (for example, 0.1 for 10%). Defaults to false (no new traces initiated). For more information, see Control sampling rate.

Set up authentication and TLS

When connecting to an OTLP backend that requires authentication, such as a SaaS observability platform, use the policies.requestHeaderModifier section to add required authentication headers and policies.backendTLS to enable TLS for the connection. You can set them in the UI or in your configuration file.

Whether the UI can save depends on your storage mode. For more information, see Save changes from the UI.

  1. Open the Settings > Observability page, such as http://localhost:15000/ui/settings/observability, and click the Tracing card.
  2. In the Tracing drawer, configure the following fields.
    1. Host: Enter the hostname and port of your OTLP backend, such as <your-otlp-endpoint>.com:443.
    2. Backend policies: Enter the following YAML to enable TLS and set the authentication header.
      backendTLS: {}
      requestHeaderModifier:
        set:
          Authorization: "Basic <api-key>"
    3. Protocol: Select HTTP. If your backend uses a path other than the default, enter it in the Path field.
    4. Random sampling: Enter true.
  3. Click Save policy.

For a complete example, see the Langfuse integration.

FieldDescription
policies.requestHeaderModifier.setHeaders to set on every OTLP export request. Use this to pass API keys or auth tokens to your backend.
policies.backendTLSTLS settings for the backend connection. Set to {} to use TLS with system CAs (required for public HTTPS endpoints).

Control sampling rate

Use the randomSampling setting to control the fraction of requests for which spans are exported. Set randomSampling: true to sample 100% of requests, or provide a decimal between 0 and 1 for a percentage.

Three sampling settings decide whether a request is traced, and which one applies depends on the incoming request.

SettingApplies whenDefault
randomSamplingThe incoming request does not already carry a trace, so agentgateway must decide whether to start one.false
clientSamplingThe incoming request has a sampled traceparent (the sampled flag is 01).true
parentNotSampledThe incoming request has an unsampled traceparent (the sampled flag is 00).false

Only one setting applies to each request. Because clientSampling defaults to true, agentgateway continues sampled client traces even when randomSampling is false. An unsampled parent is respected by default. Set parentNotSampled: true to trace those requests anyway and propagate a sampled flag (01) upstream. Each setting accepts true, false, or a sampling fraction between 0 and 1.

In the following example, you want to sample 10% of requests.

  1. Open the Settings > Observability page, and click the Tracing card.
  2. In the Sampling section, enter 0.1 for Random sampling.
  3. Optional: Enter a value for Client sampling or Parent not sampled. Each field accepts true, false, or a sampling fraction.
  4. Click Save policy.

Filter spans

Use the filter field to write a CEL expression that controls which sampled spans are exported. A span is exported only when the expression evaluates to true. The filter runs after sampling, so it evaluates spans selected by any of the three sampling settings.

The following example exports only spans for requests with an HTTP response code of 400 or greater.

  1. Open the Settings > Observability page, and click the Tracing card.

  2. In the Sampling section, enter response.code >= 400 in the Filter field.

    Tracing drawer with random sampling set to true and the filter response.code >= 400
    Tracing drawer with random sampling set to true and the filter response.code >= 400
  3. Click Save policy.

You can combine conditions to export specific traffic. The following examples show common filter patterns:

GoalCEL expression
Export only errorsresponse.code >= 400
Export only LLM requestsgen_ai.provider != ""
Export by userrequest.headers["x-user-id"] == "user-123"
Export errors or slow requestsresponse.code >= 400 || duration > 5000

For the full list of available CEL variables, see the CEL variables reference.

Customize span attributes

Agentgateway emits standard OpenTelemetry attributes as shown in Default span attributes. You can add custom attributes to your spans or remove default ones. Note that customizing span attributes does not work on policy call child spans. For more information, see Policy call child spans.

Add span and resource attributes

Use the attributes field to add custom tags to individual spans. Attribute values are evaluated as CEL expressions on every request, so they can be dynamic. For example, you can use a CEL expression to add the user ID from a request header or the HTTP response code.

Use the resources field to describe the agentgateway process itself. Resource values are static values that are added to every span. For example, you can add the name of the agentgateway process, the environment it runs in, what version it is. Your tracing backend uses resource attributes to label and group spans in its service list. The most common resource attribute is service.name, which sets the name that is displayed in your tracing backend. It defaults to agentgateway if not set.

The following example sets a custom service name and deployment environment in resources, and adds the user ID and request path to each individual span by using attributes.

  1. Open the Settings > Observability page, and click the Tracing card.

  2. In the Attributes section, add the resource attributes.

    1. Under Resource attributes, click service.name, enter "my-agentgateway" as the value, and click Add. Keep the double quotes, because the value is a CEL string.
    2. Click deployment.environment, enter "production" as the value, and click Add.
  3. Under Span attributes, add the span attributes.

    1. Enter user.id as the name and request.headers["x-user-id"] as the value, and click Add.
    2. Enter request.path as the name and request.path as the value, and click Add.
    Tracing drawer Attributes section with user.id and request.path span attributes, and service.name and deployment.environment resource attributes
    Tracing drawer Attributes section with user.id and request.path span attributes, and service.name and deployment.environment resource attributes
  4. Click Save policy.

Remove span attributes

Use the remove field to drop attributes from spans before your attributes expressions are applied. This setting is useful for stripping default attributes that are redundant or that you do not want to export.

The following example removes the HTTP protocol version and client address from the span. The remove list matches the attribute names on the request span, as listed in Default span attributes. A name that is not on the span, such as the earlier src.addr or http.version, removes nothing.

  1. Open the Settings > Observability page, and click the Tracing card.

  2. In the Attributes section, add each attribute to Remove attributes.

    1. Enter client.address, and click Add.
    2. Enter network.protocol.version, and click Add.
    Tracing drawer Attributes section with client.address and network.protocol.version in the remove attributes list
    Tracing drawer Attributes section with client.address and network.protocol.version in the remove attributes list
  3. Click Save policy.

Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate ↵ select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.