-
Notifications
You must be signed in to change notification settings - Fork 998
Description
The spec (https://opentelemetry.io/docs/specs/semconv/http/http-spans/#http-server-span) says:
The following attributes can be important for making sampling decisions and SHOULD be provided at span creation time (if provided at all):
- ...
http.request.header.<key>- ...
currently instrumentation-http@0.211.0 does not:
opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
Lines 648 to 670 in fcafab5
| const span = instrumentation._startHttpSpan(method, spanOptions, ctx); | |
| const rpcMetadata: RPCMetadata = { | |
| type: RPCType.HTTP, | |
| span, | |
| }; | |
| return context.with( | |
| setRPCMetadata(trace.setSpan(ctx, span), rpcMetadata), | |
| () => { | |
| context.bind(context.active(), request); | |
| context.bind(context.active(), response); | |
| if (instrumentation.getConfig().requestHook) { | |
| instrumentation._callRequestHook(span, request); | |
| } | |
| if (instrumentation.getConfig().responseHook) { | |
| instrumentation._callResponseHook(span, response); | |
| } | |
| instrumentation._headerCapture.server.captureRequestHeaders( | |
| span, | |
| header => request.headers[header] | |
| ); |
The header capture should move above the _startHttpSpan call.
This is only a SHOULD requirement, so this isn't a bug.
Moving this above will mean a slight refactor to this._headerCapture, so that it modifies an Attributes object in-place (or returns attributes to apply), rather than calling span.setAttribute(...) itself. See export function headerCapture in src/utils.ts.