Jaeger Query HTTP API (APIHandler)#
APIHandler is the struct that implements Jaeger's legacy query service HTTP API. It lives in cmd/jaeger/internal/extension/jaegerquery/internal/http_handler.go and is registered as a component of the jaegerquery OpenTelemetry Collector extension.
Struct and Construction#
APIHandler holds:
queryServiceโ a*querysvc.QueryService(traces, operations, services, dependencies, archive)metricsQueryServiceโ ametricstore.Readerfor SPM metricsqueryParserโ parses HTTP query parameters into storage query typesbasePath,apiPrefix,logger,tracerโ routing and observability config
Instantiate it with NewAPIHandler, passing functional options from HandlerOptions (e.g., HandlerOptions.Logger(...), HandlerOptions.BasePath(...), HandlerOptions.MetricsQueryService(...)). The default API prefix is "api" .
Route Registration#
RegisterRoutes registers all endpoints on a *http.ServeMux. All paths are prefixed with /{basePath}/{apiPrefix}:
| Method | Path | Handler | Purpose |
|---|---|---|---|
GET | /api/traces/{traceID} | getTrace | Fetch a single trace by ID |
POST | /api/archive/{traceID} | archiveTrace | Archive a trace |
GET | /api/traces | search | Search/find traces by query params |
GET | /api/services | getServices | List all known services |
GET | /api/operations | getOperations | List operations for a service (?service=) |
GET | /api/services/{service}/operations | getOperationsLegacy | Legacy operations endpoint (all span kinds) |
POST | /api/transform | transformOTLP | Convert OTLP payload to UI JSON format |
GET | /api/dependencies | dependencies | Get service dependency graph |
GET | /api/deep-dependencies | deepDependencies | Deep dependency graph (DDG) |
GET | /api/metrics/latencies | latencies | Latency percentile metrics |
GET | /api/metrics/calls | calls | Call rate metrics |
GET | /api/metrics/errors | errors | Error rate metrics |
GET | /api/quality-metrics | getQualityMetrics | Sample quality metrics |
Key Endpoint Behaviors#
GET /api/traces (search) โ Calls queryParser.parseTraceQueryParams to parse parameters (service, operation, start/end in microseconds, tag/tags, limit, minDuration/maxDuration). If traceID params are present, fetches traces by ID via GetTraces; otherwise, calls QueryService.FindTraces . Supports a raw=true flag to bypass trace adjustment.
GET /api/traces/{traceID} โ Parses the trace ID from the URL path, optionally accepts start/end (microseconds) and raw query params, then calls QueryService.GetTraces . Returns 404 if not found.
POST /api/archive/{traceID} โ Calls QueryService.ArchiveTrace; returns 501 Not Implemented if no archive writer is configured .
GET /api/dependencies โ Parses endTs (milliseconds) and lookback duration, optionally filters by ?service= . Duplicate dependency links are merged by summing call counts .
Metrics endpoints (/api/metrics/latencies, /calls, /errors) โ Share a common metrics helper that calls queryParser.parseMetricsQueryParams (required: services; optional: groupByOperation, spanKinds, endTs, lookback, step, ratePer), then dispatches to metricsQueryService. Returns 501 if the metrics backend is disabled .
Response Format#
All non-metrics responses use a structuredResponse envelope:
{ "data": [...], "total": N, "limit": 0, "offset": 0, "errors": [] }
Metrics responses are serialized as protobuf JSON (MetricFamily). Adding ?prettyPrint=true to any request enables indented output .
Errors always return JSON with an errors array containing code and msg fields. If disabled.ErrDisabled is returned by a backend, the status code is forced to 501 .
Downstream: QueryService#
APIHandler delegates all data access to querysvc.QueryService, which wraps a tracestore.Reader, depstore.Reader, and an adjuster.Adjuster pipeline. Adjusters (e.g., deduplication, clock skew correction) run automatically unless raw=true is set. See StandardAdjusters for the full pipeline.
Key Source Files#
| File | Purpose |
|---|---|
http_handler.go | APIHandler struct, route registration, all endpoint handlers |
query_parser.go | Parses HTTP params โ traceQueryParameters, dependenciesQueryParameters, metricstore.BaseQueryParameters |
handler_options.go | HandlerOption functional options for configuring APIHandler |
querysvc/service.go | QueryService โ data access facade wrapping storage readers and adjusters |
apiv3/ | Separate v3 API handlers (gRPC-gateway + HTTP) |