How to Introduce a Secondary Tracer into JavaAgent?
#15729
Replies: 1 comment
-
Probably because agent excludes its own classes from instrumentation. See
OpenTelemetry sdk is in https://github.com/open-telemetry/opentelemetry-java You might wish to ask these questions there. I suspect that it would be best not to do this and seek an alternative path.
I believe it is not renamed, but you can easily verify it yourself just check under
As noted above they are excluded from instrumentation but |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to introduce a second
Tracer(orSdkTracer) alongside the SDK's default.The second
Tracershall use a different sampling strategy than the one the default one uses but shall otherwise be called whenever the SDK's default one is also called. The reason is that I need to create two traces, one of technical nature - where the default provided by the SDK is perfect and should not be impacted when the sampling strategy and behavior of the other tracer might change - and a second one where a different sampling strategy shall be used and potentially some span aggregations might be performed as well (using a second non-default exporter).The second tracer should be called whenever the default one of the SDK is called, i.e. I don't want to introduce the new tracer to all the auto-instrumentations that are already provided by the community, but would ideally like create a decorator / wrapper around the default
SdkTracerwhich under the hood creates the secondaryTracerinstance and delegates all calls to both the default and the secondary one.To return the wrapper, I would have to sub-class
SdkTracerProviderwhich is what the agent uses when bootstrapping the SDK instance (available viaGlobalOpenTelemetry.get(). Problem is:SdkTracerProviderisfinal, and so I cannot create an implementation that would return my intended wrapper. I also checked the auto-instrumentation customizers, but the one for theTracerProviderexpects anSdkTracerProviderinstance (rather than aTracerProviderinterface instance) in return - so I see no chance of returning aTracerProviderimplementation that would return the wrappedSdkTracer.So, I checked how to modify the behavior of the
io.opentelemetry.sdk.trace.SdkTracerProviderclass that is instantiated by the auto-configuration within the JavaAgent. I thought of doing that via bytecode modification by adding anAdvice.I have written an extension that tries to add an
Adviceto theio.opentelemetry.sdk.trace.SdkTracerProvider'sget(String instrumentation)method. But the advice code is never called, and it seems theSdkTracerProvideris never called.I verified that my
Advicecode is correct by explicitly creating an instance of theSdkTracerProviderin my app and calling itsget(...)method. But for some reason, myAdviceis not called when theSdkTracerProvideris used by the JavaAgent.I read about the JavaAgent shading certain classes, i.e. changing their package names, etc. to not clash with the same classes introduced / referenced by the application.
My questions are:
Tracernext to the default one, so that it can use a different sampling strategy (i.e. potentially records more / different spans than the default one does, WITHOUT changing the default's behavior)?Adviceto theSdkTracerProviderthat the JavaAgent uses under the hood and when it auto-configures the SDK that is then also made available viaGlobalOpenTelemetry.get()?Adviceor are these classes excluded from bytecode modifications?Beta Was this translation helpful? Give feedback.
All reactions