-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I convert a javaagent.shaded.io.opentelemetry.context to a io.opentelemetry.context.Context #13274
Comments
Installing the instrumentation manually does of course work around it, and the span can be customised.
implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-2.0")
HttpClient(Java) {
install(KtorClientTracing) {
setOpenTelemetry(GlobalOpenTelemetry.get()) // Uses OTEL from the agent.
}
} |
You can check out related document and estimate whether it can meet your requirement by adding an extension.
You can have a look at https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/javaagent-structure.md#bootstrap-class-loader |
@steverao thanks for this that clarified some aspects. I'm still not 100% sure how the Kotlin extensions get an unshaded context from the auto instrumentation. There's reference to a context bridge here but the module is not directly referenced in the readme you linked? Lines 31 to 32 in 234d619
It doesn't seem like a stretch then to have a generic unshading mapper extension? |
You can check out whether they can help you solve your final purpose that you want to add attributes to specific spans by using extensions. |
Agent uses shaded opentelemetry api to not conflict when the application also included opentelemetry api. If application provides opentelemetry api agent will instrument the api in the application and bride it with the api in the agent. Line 127 in 083a797
proceed in Line 55 in 083a797
coroutineContext.getOpenTelemetryContext() you'll need https://github.com/open-telemetry/opentelemetry-java/tree/main/extensions/kotlin. Didn't try it myself so could be wrong.
|
@laurit thanks for this it clarifies a lot! I suppose my intended usage would look like this: val data = client
.preparePost(...)
.execute { response ->
response.body<Dto>().also { data ->
with(Span.fromContext(coroutineContext.getOpenTelemetryContext())) {
setAttribute(SomeKey, data.interestingValue)
}
}
} With manual instrumentation as I described in #13274 (comment) I can do this: .execute { response ->
response.body<Dto>().also { data ->
with(Span.fromContext(response.call.coroutineContext.getOpenTelemetryContext())) {
setAttribute(SomeKey, data.interestingValue)
}
}
} This doesn't bridge with the agent. Following your guidance I can install a plugin: install(createClientPlugin("OTELIntercept") {
this.client.sendPipeline.intercept(HttpSendPipeline.Monitoring) {
context.attributes.put(AttributeKey<Span>("OTELSpan"), Span.fromContext(coroutineContext.getOpenTelemetryContext()))
proceed()
}
}) And then this works with the agent (could have stored the context but this felt nicer if the plugin is innersourced): val data = post.execute { response ->
response.body<Dto>().also { data ->
with(response.call.attributes[AttributeKey<Span>("OTELSpan")]) {
setAttribute(SomeKey, data.interestingValue)
}
}
} It would be great if the client context could be found from that |
If it works with the library instrumentation then it is reasonable to assume that it could also work with the agent. Please provide a minimal application that reproduces the issue along with any necessary instructions. |
I am hoping to add attributes to an active ktor client span specifically trying to get this context https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt#L27 from the pipieline.
However I easily hit:
One thing I'm not sure about is why this particular context is shaded, but if I use https://github.com/open-telemetry/opentelemetry-java/blob/main/extensions/kotlin/src/main/kotlin/io/opentelemetry/extension/kotlin/ContextExtensions.kt#L27 then the context is intact.
Are there any helper libraries I can use to 'unshade' the ktor context so that I can call
setAttribute
on it from the application?The text was updated successfully, but these errors were encountered: