apollographql / apollographql/federation

Associate Gateway traces across Apollo Studio and Open Telemetry

Open
#1,256 3 comments 0 reactions 0 assignees View on GitHub
:hugs: improvement
Dominant language
TypeScript
Stars
725
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

## Background

Today there is [Open Telemetry support for Apollo Federation](https://www.apollographql.com/blog/backend/architecture/introducing-open-telemetry-for-apollo-federation/) with [docs on Open Telemetry for Federation](https://www.apollographql.com/docs/federation/opentelemetry/) and a [demo](https://github.com/apollographql/supergraph-demo-fed2#tracing-with-open-telemetry).

You can associate Apollo Studio and Open Telemetry traces by sending a `x-trace-id` header and then passing it to the `UsageReportingPlugin` and `HttpInstrumentation` like the example from @lennyburdette below:

```ts
new ApolloServer({
gateway,
plugins: [
ApolloServerPluginUsageReporting({
sendHeaders: { only: ['x-trace-id'] },
}),
],
});

registerInstrumentations({
instrumentations: [
new HttpInstrumentation({
requestHook(span, request) {
if ("headers" in request) {
span.setAttributes({
'x-trace-id': request.headers['x-trace-id'],
});
}
},
}),
],
});
```
## What seems to be the problem?

There's no easy way to automatically originate the `trace-id` in the Gateway and then have that used both in the `UsageReportingPlugin` and `HttpInstrumentation`. While the solution above might work for many cases, it requires the client or ingress API gateway to send a unique `x-trace-id` for each request, so it can be passed through via the Gateway customization above.

## What can we do to help?

Ideally the Gateway would automatically capture or generate a `trace-id` and send it to Studio to associate the traces, so it automatically shows up in Studio without custom code.

Document the various approaches and make them easy to find from:
- [Blog: Open Telemetry support for Apollo Federation](https://www.apollographql.com/blog/backend/architecture/introducing-open-telemetry-for-apollo-federation/)
- [docs on Open Telemetry for Federation](https://www.apollographql.com/docs/federation/opentelemetry/)
- [supergraph-demo](https://github.com/apollographql/supergraph-demo-fed2#tracing-with-open-telemetry)

Contributor guide

Open the contributing guide

Research direction

Review the existing OpenTelemetry for Apollo Federation documentation, the linked support blog, and the supergraph-demo tracing example first. Document the available approaches for associating Gateway traces with Apollo Studio and make the guidance easy to find from all three referenced locations.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation, observability-sre
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.