Skip to content

instr-http SHOULD provide http.request.header.<key> at server span creation time #6393

@trentm

Description

@trentm

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions