Add logs, distributed traces, and metrics to a Tyk Gateway deployment using Docker Compose with an OpenTelemetry Collector, Prometheus, Loki, Tempo, and Grafana.
Tyk Gateway exports all three observability signals (structured logs, distributed traces, and metrics) via the OpenTelemetry Protocol (OTLP). This guide shows you how to enable each signal and route them to a local Grafana stack (Prometheus, Loki, Tempo) using an OpenTelemetry Collector.By the end of this guide you will have:
Structured JSON access logs from Tyk Gateway shipping to Loki
All three signals flow from Tyk Gateway to a single OpenTelemetry Collector endpoint. The Collector fans them out to the appropriate backend. Grafana queries all three.
Tyk Gateway does not export logs via OTLP. It writes structured JSON to stderr. The OTel Collector reads those logs from the Docker container log path using the filelog receiver.
sampling.rate: 1.0 captures every request, which is suitable for getting started. In production, lower this to 0.1 (10%) or use ParentBased sampling. See the Tyk Gateway configuration reference for all options.
Restart your deployment to apply the configuration changes to your Gateway and bring up the new services:
docker compose up -d
Send test requests through Tyk Gateway, then open Grafana at http://localhost:3001 and verify each signal.
If you are following this guide using the Tyk Self-Managed getting started setup, an httpbingo API is pre-configured. Generate test traffic with:
for i in $(seq 1 10); do curl -s -o /dev/null -w "HTTP %{http_code}\n" \ -H "Authorization: <your-api-key>" http://localhost:8080/httpbingo/get; done
Metrics: in Explore, select the Prometheus datasource and run:
{__name__="tyk.http.requests_total"}
You should see request counts rise as traffic flows through the Gateway.Logs: in Explore, select the Loki datasource and run:
{service_name="tyk-gateway"} | json
You should see structured access log entries with fields like api_id, path, status, latency_total, and trace_id.Traces: in Explore, select the Tempo datasource and search for recent traces. Each trace should show one span for the request.
If traces are not appearing, verify that TYK_GW_OPENTELEMETRY_TRACES_ENABLED=true is set and that the Gateway can reach otel-collector:4317. Check the OTel Collector logs with docker compose logs otel-collector for any connection errors.