Skip to main content

Gateway Tracing

A trace follows one request through the gateway. Each step is a span. Components pass the trace from one to the next with the W3C traceparent and tracestate headers.

The demonstration stack is an OpenTelemetry Collector and Jaeger. The router and the policy engine send spans to the collector over gRPC on port 4317. The collector also accepts OTLP over HTTP on port 4318 for other senders. The collector forwards the spans to Jaeger. You can send the same spans to any OTLP backend instead.

Enable tracing​

In configs/config.toml inside the gateway distribution, add a [tracing] section. The shipped file has no [tracing] section, so tracing stays off until you add one:

[tracing]
enabled = true # Set to true to enable tracing
endpoint = "otel-collector:4317" # OTLP collector gRPC endpoint
insecure = true # Connect without TLS
service_version = "1.0.0" # Service version
batch_timeout = "1s" # Batch timeout for exporting spans
max_export_batch_size = 512 # Maximum spans per batch
sampling_rate = 1.0 # Sample rate (1.0 = 100%, 0.5 = 50%)

Start the gateway with the tracing services:

docker compose --profile tracing up -d

This starts gateway-controller, gateway-runtime (which runs the router and the policy engine), the OpenTelemetry Collector, and Jaeger.

To run the gateway without that stack:

docker compose up -d
note

If tracing is enabled and the collector is not running, the components log export warnings. Set enabled = false to turn tracing off. Jaeger keeps traces in memory, so stopping it drops them unless you add a storage backend.

Stop the stack:

docker compose --profile tracing down

View traces in Jaeger​

  1. Open http://localhost:16686.
  2. Select a service: policy-engine or router.
  3. Optionally select an operation, or leave it as all.
  4. Set the lookback (5m, 15m, 1h, 6h, 12h, 1d, 2d, or custom). The default is the last hour.
  5. Optionally filter by tags (for example http.status_code=500), duration, or result limit. The default limit is 20.
  6. Click Find Traces.

Open a trace to see the timeline, how long each span took, and the parent and child spans. Open a span for its operation name, duration, tags, logs, and process.

  • Slow requests: set a minimum duration, such as 1000ms, then Find Traces.
  • Errors: filter with error=true or http.status_code=500.
  • One request: search by the trace ID from a log line or a traceparent header.

Select traces and click Compare Traces to compare them. Click Dependencies to see which services called which.

Change what is exported​

Sample fewer requests:

[tracing]
sampling_rate = 0.1 # Sample 10% of requests

1.0 samples every request. 0.5 samples half, 0.1 samples 10%, and 0.01 samples 1%. A lower rate costs less and can miss traces.

Set the service name for each component:

[policy_engine]
tracing_service_name = "policy-engine-prod-us-east-1"

[router]
tracing_service_name = "router-prod-us-east-1"

The defaults are policy-engine and router.

Add resource attributes to every span from both the router and the policy engine:

[tracing.resource_attributes]
"deployment.environment" = "prod"

Attributes from the OTEL_RESOURCE_ATTRIBUTES environment variable still apply, and the values in this block take precedence.

Change how spans are batched:

[tracing]
batch_timeout = "5s" # Wait up to 5s before exporting
max_export_batch_size = 1024 # Export up to 1024 spans per batch

A shorter timeout shows traces sooner. A longer timeout sends fewer, larger batches.

Send traces somewhere else​

Keep the gateway endpoint pointed at an OTLP collector, and change the collector exporters. The collector file is gateway/observability/otel-collector/config.yaml.

note

The demonstration stack runs the core build of the OpenTelemetry Collector, otel/opentelemetry-collector:0.112.0. It includes the otlp, otlphttp, zipkin, and debug exporters. The awsxray, googlecloud, azuremonitor, and datadog exporters and the tail_sampling processor are in the contrib build only. To use them, change the collector image to otel/opentelemetry-collector-contrib.

Moesif​

exporters:
# Export to Moesif
otlphttp:
endpoint: https://api.moesif.net
headers:
X-Moesif-Application-Id: 'your-moesif-application-id'

service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch, resource]
exporters: [otlphttp] # Send to Moesif

Use the otlphttp exporter and HTTPS. The X-Moesif-Application-Id header is required.

To get the application ID, sign in at moesif.com, open Settings → Installation or API Keys, and copy the Collector Application ID.

To pass the ID as an environment variable:

exporters:
otlphttp:
endpoint: https://api.moesif.net
headers:
X-Moesif-Application-Id: '${MOESIF_APPLICATION_ID}'
otel-collector:
image: otel/opentelemetry-collector:0.112.0
environment:
- MOESIF_APPLICATION_ID=${MOESIF_APPLICATION_ID}
# ... rest of configuration
export MOESIF_APPLICATION_ID=your-moesif-application-id
docker compose --profile tracing up -d

In Moesif, open Events → Live Event Log. Time Series shows usage over time, and Alerts covers error rate, latency, and custom conditions.

Send to Jaeger and Moesif together:

exporters:
# Local Jaeger for development
otlp/jaeger:
endpoint: jaeger:4317
tls:
insecure: true

# Moesif for analytics
otlphttp/moesif:
endpoint: https://api.moesif.net
headers:
X-Moesif-Application-Id: '${MOESIF_APPLICATION_ID}'

service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch, resource]
exporters: [otlp/jaeger, otlphttp/moesif]

Zipkin​

Replace Jaeger with Zipkin:

zipkin:
image: openzipkin/zipkin:latest
ports:
- "9411:9411"
networks:
- gateway-network

Update OTLP Collector configuration to export to Zipkin:

exporters:
zipkin:
endpoint: http://zipkin:9411/api/v2/spans

Open Zipkin at http://localhost:9411.

Grafana Tempo​

tempo:
image: grafana/tempo:latest
command: ["-config.file=/etc/tempo.yaml"]
volumes:
- ./observability/tempo/tempo.yaml:/etc/tempo.yaml
- tempo-data:/tmp/tempo
ports:
- "3200:3200" # Tempo HTTP
- "4317:4317" # OTLP gRPC
networks:
- gateway-network

grafana:
image: grafana/grafana:latest
environment:
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
ports:
- "3000:3000"
volumes:
- ./observability/grafana/datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
networks:
- gateway-network
depends_on:
- tempo
[tracing]
endpoint = "tempo:4317"

AWS X-Ray​

exporters:
awsxray:
region: us-east-1
no_verify_ssl: false

Or use the AWS Distro for OpenTelemetry collector:

otel-collector:
image: public.ecr.aws/aws-observability/aws-otel-collector:latest
command: ["--config=/etc/otel-collector-config.yaml"]
environment:
- AWS_REGION=us-east-1

Google Cloud Trace​

Configure OTLP Collector to export to Google Cloud:

exporters:
googlecloud:
project: your-gcp-project-id
use_insecure: false

Azure Monitor​

Use Azure Monitor exporter:

exporters:
azuremonitor:
instrumentation_key: "your-instrumentation-key"

Datadog​

Configure OTLP Collector to export to Datadog:

exporters:
datadog:
api:
key: ${DD_API_KEY}
site: datadoghq.com

Or use the Datadog Agent:

datadog-agent:
image: datadog/agent:latest
environment:
- DD_API_KEY=${DD_API_KEY}
- DD_APM_ENABLED=true
- DD_APM_NON_LOCAL_TRAFFIC=true
- DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_GRPC_ENDPOINT=0.0.0.0:4317
ports:
- "4317:4317"
networks:
- gateway-network
[tracing]
endpoint = "datadog-agent:4317"

New Relic​

Configure OTLP Collector to export to New Relic:

exporters:
otlphttp:
endpoint: https://otlp.nr-data.net
headers:
api-key: ${NEW_RELIC_LICENSE_KEY}

Honeycomb​

exporters:
otlp:
endpoint: api.honeycomb.io:443
headers:
x-honeycomb-team: ${HONEYCOMB_API_KEY}

Lightstep​

exporters:
otlp:
endpoint: ingest.lightstep.com:443
headers:
lightstep-access-token: ${LIGHTSTEP_ACCESS_TOKEN}

Istio and Linkerd​

[tracing]
enabled = true
endpoint = "istio-telemetry.istio-system:4317"
[tracing]
enabled = true
endpoint = "linkerd-collector.linkerd:4317"

Collector configuration​

gateway/observability/otel-collector/config.yaml has receivers, processors, exporters, and a pipeline that connects them.

Receive OTLP:

receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318

Process spans:

processors:
# Batch spans for efficiency
batch:
timeout: 1s
send_batch_size: 1024

# Add resource attributes
resource:
attributes:
- key: environment
value: production
action: upsert
- key: cluster
value: us-west-2
action: upsert

# Memory limiter to prevent OOM
memory_limiter:
check_interval: 1s
limit_mib: 512

# Sampling processor
probabilistic_sampler:
sampling_percentage: 10 # Sample 10% of traces

Export them:

exporters:
# Send to Jaeger
otlp:
endpoint: jaeger:4317
tls:
insecure: true

# Debug output to console
debug:
verbosity: detailed
sampling_initial: 5
sampling_thereafter: 200
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch, resource]
exporters: [otlp, debug]

Send one pipeline to several backends:

exporters:
otlp/jaeger:
endpoint: jaeger:4317
tls:
insecure: true

otlp/tempo:
endpoint: tempo:4317
tls:
insecure: true

datadog:
api:
key: ${DD_API_KEY}

service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp/jaeger, otlp/tempo, datadog]

Keep error traces, slow traces, and a sample of the rest. This processor needs the contrib build of the collector:

processors:
tail_sampling:
policies:
- name: error-traces
type: status_code
status_code:
status_codes: [ERROR]
- name: slow-traces
type: latency
latency:
threshold_ms: 1000
- name: probabilistic
type: probabilistic
probabilistic:
sampling_percentage: 10

Pass a trace through the gateway​

Omit traceparent and the gateway starts a new trace. To continue a trace you already have:

curl http://localhost:8080/weather/v1.0/us/seattle \
-H "traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"

Choose a sampling rate​

Traffic VolumeSampling RateUse Case
< 100 req/s100% (1.0)Full visibility, low overhead
100-1000 req/s10-50% (0.1-0.5)Balanced visibility and cost
1000-10000 req/s1-10% (0.01-0.1)Cost-effective, statistical sampling
> 10000 req/s0.1-1% (0.001-0.01)Minimal overhead, error sampling

Use tail sampling, which needs the contrib build of the collector, if you want every error trace kept while ordinary traffic is sampled. In production, use TLS on the collector connection and a memory limit on the collector.

Troubleshooting​

No traces in Jaeger​

  1. Confirm tracing is on:
cat configs/config.toml | grep -A5 "tracing"

The file must contain a [tracing] section, and enabled must be true.

  1. Confirm the collector and Jaeger are running:
docker ps | grep otel-collector
docker ps | grep jaeger
curl http://localhost:16686/
  1. Read the collector and component logs:
docker compose logs otel-collector
docker compose logs gateway-runtime | grep -i trace
docker compose logs gateway-controller | grep -i trace
  1. Check that the containers can reach each other:
docker compose exec gateway-runtime ping -c 1 otel-collector

If spans are missing, the sampling rate may be too low, a component may not be exporting, or the traceparent header may have been dropped. Clock skew across containers shows up as wrong span times.

Export uses too much CPU or network​

[tracing]
sampling_rate = 0.1 # Reduce from 1.0 to 0.1
[tracing]
batch_timeout = "5s"
max_export_batch_size = 2048

Jaeger UI does not open​

docker ps | grep jaeger
docker compose logs jaeger
curl http://localhost:16686/

Port 16686 must be reachable on the host.

Turn tracing off​

In configs/config.toml:

[tracing]
enabled = false
docker compose restart gateway-controller gateway-runtime

Router tracing follows the gateway-controller configuration, so it stops when that configuration is applied.

Match a trace to a log​

Most log lines don't carry a trace ID. The policy engine writes trace_id only in a debug message when it extracts the trace context from request headers, and no component logs span_id. To match a trace to a log, set the policy engine log level to debug and search the logs for the trace ID from Jaeger.

Run both stacks together:

docker compose --profile logging --profile tracing up -d

See Gateway Logging.

Additional resources​

Was this page helpful?