Skip to content

Context propagation with Kafka Consumer #4546

Answered by trask
mNantern asked this question in Q&A
Discussion options

You must be logged in to vote

hi @mNantern!

You can read the traceparent from the Kafka message and create a scope based on it, and do your work under that scope, e.g.

String traceparent = ...

Context context =
    W3CTraceContextPropagator.getInstance()
        .extract(
            Context.root(),
            traceparent,
            new TextMapGetter<String>() {
              @Override
              public Iterable<String> keys(String carrier) {
                return Collections.singleton("traceparent");
              }
              @Override
              @Nullable
              public String get(String carrier, String key) {
                return key.equals("traceparent") ? carrier : null;
              }
   …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mNantern
Comment options

Answer selected by mNantern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants