opentelemetry-java-instrumentation icon indicating copy to clipboard operation
opentelemetry-java-instrumentation copied to clipboard

Marking agent auto instrumentation span as ok from code

Open anderssv opened this issue 9 months ago • 2 comments

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

We are calling a Postgres DB and getting exceptions for the normal flow of things (we shouldn't, but do). In the current code we set the span status to ok when we catch the exception. But this is not reflected in the child span started by the agent auto instrumentation.

We would like these to be set as OK, but need to do this from the call site (the parent span). Could it be possible to add a context attribute to say something to the agent about expected results?

We're using Applicationinsights agent, which is a repackaged OT agent to my understanding.

Describe the solution you'd like

A way to update the child as ok. A less optimal way could be to instruct the agent to disable auto instrumentation for the following call.

Describe alternatives you've considered

I see there are options to disable a certain auto instrumentation and filter on classes etc, but this is actually more fine grained than that.

Additional context

No response

anderssv avatar Feb 13 '25 08:02 anderssv

I'd try writing an extension https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/examples/extension that adds a span processor You'd need to implement https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/ExtendedSpanProcessor.java and use the onEnding callback.

laurit avatar Feb 18 '25 11:02 laurit

That will probably work, but requires a lot of packaging (separate jar) and possibly project setup.

I am a big fan of being able to do things in code at the specific call site for these things. And I do believe this is a quite common issue when using the agent. It would probably benefit many of us to be able to do this in a simple way.

We will probably re-factor away from catching exceptions in our specific case, but I do see other cases where this could be useful too.

anderssv avatar Feb 18 '25 12:02 anderssv

just adding the obligatory link to https://github.com/open-telemetry/oteps/pull/207 (@anderssv yes this should be easier, someday it will be, but unfortunately not today)

trask avatar Mar 27 '25 00:03 trask

This also is a relevant discussion: https://github.com/open-telemetry/opentelemetry-specification/issues/4131

Note that this specific issue is mainly because of using auto-instrumentation from the agent, as that means I don't have access to the code sites that creates a child span of the one I have control over.

anderssv avatar Mar 27 '25 09:03 anderssv