Skip to content

Creating custom context key for use in custom sampler #12007

Answered by laurit
cirpene asked this question in Q&A
Discussion options

You must be logged in to vote

Context keys use identity comparison so you need to use the same key instance. Since agent and application code is isolated from each other and they don't share the opentelemetry api classes using the same key is not straightforward. Instead of using the key directly in you application code it may be easier to use the extension to instrument your application. Instead of setting the key in your application call a method like runWithSuppressed(Runnable runnable) in your application this method would just call runnable.run(). Instrumentation could modify this method and rewrite it to try (Scope ignore = Context.current().with(Suppress.KEY, true).makeCurrent()) { runnable.run() }

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@cirpene
Comment options

@laurit
Comment options

@cirpene
Comment options

@zerocooldog
Comment options

@cirpene
Comment options

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