How do you implement distributed tracing for GraphQL?
Answer
Distributed tracing in GraphQL helps identify performance bottlenecks at the field level. Approaches: (1) Apollo Tracing: Apollo Server's built-in tracing adds resolver timing to the response's extensions object — enable with the ApolloServerPluginInlineTrace plugin. Apollo Studio automatically collects and displays these traces. (2) OpenTelemetry: use @opentelemetry/api with a GraphQL instrumentation plugin (@opentelemetry/instrumentation-graphql) — creates spans for parse, validate, execute, and individual resolver calls. Send traces to Jaeger, Zipkin, Tempo, or Honeycomb. (3) Custom resolver middleware: wrap all resolvers with timing logic and send to your APM. (4) Logging: log slow resolvers (>100ms) with their full path and arguments. Key metrics to track: per-operation latency percentiles (p50, p95, p99), per-field resolver latency, cache hit rates, error rates by operation. Set up alerts for p99 latency regressions and error rate spikes.
Previous
What is GraphQL subscriptions with WebSocket protocol graphql-ws vs subscriptions-transport-ws?
Next
What are the trade-offs of using GraphQL vs REST for different use cases?
More GraphQL Questions
View all →- Advanced What is Apollo Federation v2 and how does the supergraph work?
- Advanced How do you implement entity resolution in Apollo Federation?
- Advanced What are the security vulnerabilities specific to GraphQL?
- Advanced How does the GraphQL query planning and execution pipeline work?
- Advanced What is the @defer and @stream directive and how do they work?