-
I have defined custom sampler using Are there any additional undocumented steps required to make context keys available to custom samplers? Or reflecting on context key array and context key name is the only option for now, since references differ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
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 |
Beta Was this translation helpful? Give feedback.
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 callrunnable.run()
. Instrumentation could modify this method and rewrite it totry (Scope ignore = Context.current().with(Suppress.KEY, true).makeCurrent()) { runnable.run() }