Skip to content
agentgateway has joined the Agentic AI FoundationLearn more

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

Export logs over OTLP

Page as Markdown

Export agentgateway access logs as OTLP LogRecord objects to an OpenTelemetry Collector or any compatible backend.

Log export happens in addition to stdout output, so you can send logs to a collector without losing local visibility.

This guide walks through setting up an OpenTelemetry Collector to receive access logs from agentgateway.

Run the OTel Collector as a Docker container on the same host as agentgateway.

  1. Create an otel-collector-config.yaml file that defines an OTLP receiver and a logs pipeline.

    cat > otel-collector-config.yaml << 'EOF'
    receivers:
      otlp:
        protocols:
          grpc:
            endpoint: 0.0.0.0:4317
    
    processors:
      batch:
    
    exporters:
      debug:
        verbosity: detailed
    
    service:
      pipelines:
        logs:
          receivers: [otlp]
          processors: [batch]
          exporters: [debug]
    EOF

    Replace the debug exporter with the exporter for your logging backend (for example, Loki, Elasticsearch, or an OTLP-compatible storage system).

  2. Start the OTel Collector container and mount your config file.

    docker run -d --name otel-collector \
      -p 4317:4317 \
      -v $(pwd)/otel-collector-config.yaml:/etc/otelcol/config.yaml \
      otel/opentelemetry-collector:latest
  3. Configure agentgateway to send access logs to the collector.

    # yaml-language-server: $schema=https://agentgateway.dev/schema/config
    frontendPolicies:
      accessLog:
        otlp:
          host: localhost:4317
  4. Send a request through agentgateway, then check the collector output to verify that log records are arriving.

    docker logs otel-collector

    Each proxied request appears as a LogRecord entry in the collector output. Look for a block that starts with LogRecord # and includes attributes such as gateway, http.method, http.path, and http.status.

  5. When you are done, remove the OTel Collector container.

    docker rm -f otel-collector

Other configurations

Review other common configurations when exporting access logs to an OTLP-compatible backend.

Filter logs before export

You can filter which access logs are exported to your OTLP backend by setting the accessLog.otlp.filter field. This filter is independent of the top-level filter (frontendPolicies.accessLog.filter), which controls what access logs are written to stdout and stored in the database. Because the two filters are evaluated separately, you can send a different subset of logs to stdout or your database, and to your OTLP backend.

The following example sends only error responses to the OTLP collector while logging all requests to stdout.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
frontendPolicies:
  accessLog:
    otlp:
      host: localhost:4317
      filter: 'response.code >= 400'

The following example logs only error responses to stdout and the database, but sends all requests to the OTLP collector.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
frontendPolicies:
  accessLog:
    filter: 'response.code >= 400'
    otlp:
      host: localhost:4317

Customize exported fields

You can add or remove fields to the log entry that you export to the OTLP endpoint.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
frontendPolicies:
  accessLog:
    otlp:
      host: localhost:4317
      fields:
        add:
          trace_id: 'request.headers["x-trace-id"]'
        remove:
          - http.host
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/.