open-telemetry / open-telemetry/opentelemetry-java-instrumentation

Instrumentation config add traceid to http server response header

Open
#12,811 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs triage
Dominant language
Java
Stars
2.6k
Forks
1.2k
Avg merge
2d 18h
Merged PRs (30d)
228

Description

Is your feature request related to a problem? Please describe.

The scenario is to expect that the response header can be added quickly in the service close to the frontend without extending HttpServerResponseCustomizer

Does this requirement involve sepcs?

Describe the solution you'd like

The configuration is probably like this,default value is null

otel.instrumentation.common.http.server.tracei.header.name=X-Test-TraceId

Similar behavior to below

@AutoService(HttpServerResponseCustomizer.class)
public class TestAgentHttpResponseCustomizer implements HttpServerResponseCustomizer {

  @Override
  public <T> void customize(
      Context serverContext, T response, HttpServerResponseMutator<T> responseMutator) {

    SpanContext spanContext = Span.fromContext(serverContext).getSpanContext();
    String traceId = spanContext.getTraceId();

    responseMutator.appendHeader(response, "X-Test-TraceId", traceId);
  }
}
Describe alternatives you've considered

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing HttpServerResponseCustomizer entry point and how instrumentation configuration keys are defined and consumed. Check whether the proposed otel.instrumentation.common.http.server.tracei.header.name setting can apply across HTTP server instrumentations, then verify the configured header and trace ID behavior with the relevant HTTP response tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, observability
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.