-
Notifications
You must be signed in to change notification settings - Fork 849
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
opencensus-shim / api: GlobalOpenTelemetry.get() should not call set() #4180
Comments
If it didn't have this side effect then an application might be started with libraries containing a mix of noop and properly configured
Not familiar with @jsuereth any input? |
Unfortunately opencensus automatically initializes on first call and has no way of controlling initialization order - this sort of issue is why in OTel we discourage the global. I agree that our current behavior is better for non-shim users. Because the shim is a transitional mechanism perhaps it's ok for this sort of case to rely on |
Thanks @anuraaga, I actually had the workaround with |
What if we add a class to the opencensus-shim, By the way, we have gRPC instrumentation already Not sure about plans for gcloud sdk instrumentation, I'm surprised not to see anything like that in DataDog (the original code that our instrumentation derives from) https://github.com/DataDog/dd-trace-java/tree/master/dd-java-agent/instrumentation Perhaps the gRPC instrumentation works well enough for gcloud SDK? @jsuereth may be able to give more thoughts on the instrumentation story for that too. |
I run into this same problem. Conditions similar/same as what gfelbing describes: attempting to use opentelemetry-opencensus-shim to get tracing from the BigTable client library and inadvertently registering the global noop before my intended (programmatic) OpenTelemetry configuration is enacted. Between OpenTelemetry, OpenCensus and the various Google SDK components, the amount of stuff happening during |
Hi @barend - we do already have the stack trace recording, is it not working for you? |
@punya Do you happen to know anyone that would be able to provide information on the plans for OpenTelemetry integration for gcloud SDK Java users? For the record, I tried writing some library instrumentation for google-http-client-java but wasn't able to since it doesn't present IOExceptions in a way that instrumentation would be able to access, while handling them natively with OpenCensus inline. Anyways I'd generally expect the future instrumentation story to be at the gcloud SDK level itself rather than its transport implementations. |
Thanks for reporting this issue and digging into the details. I'm not aware of specific plans at the Google Cloud SDK level. My rough understanding is:
If there's anything that OpenCensus can do to ease this transition (without breaking existing users), please let us know -- patches or suggestions of this type are very welcome. |
@punya I've only scratched the surface of the Google Cloud SDK. What I didn't recognise last week is that the GCP SDK telemetry uses a layer of indirection. I can't seem to recover the original page of documentation where I found it, but I remember that I configured my BigTable client to use Having now dug a bit deeper, this class implements It looks like the simplest way around problems on the interaction between the GCP SDKs, OpenCensus and the OpenTelemetry-OpenCensus-Shim is to implement these interfaces directly on top of OpenTelemetry, taking OpenCensus out of the picture. All of these are heavily annotated as internal and subject to change though. |
I wasn't aware of that layer of indirection myself, thanks @barend for pointing it out. If you do end up creating an OTel-based implementation of ApiTracerFactory, I'd be happy to dig up who owns that component within Google and ask about getting your implementation into gax-java (assuming that's something you want to pursue). |
I'm afraid I can't put that on top of my list right now, but I'll keep that in mind. Of course, I'd be just as happy if someone beat me to it. |
This has been partially addressed in #5010: the side affect in which However even without opting in, if As discussed here the advantage of this is that you have an invariant that every call to I'm going to close this issue. Feel free to reopen it if there are new arguments to change the behavior. |
For posterity - resetForTest doesn't actually work if you need to capture the opencensus traces. By the time you call resetForTest the opencensus-shim has already captured in a static variable a tracer derived from OpenTelemetry.noop(), so any subsequent attempts to change GlobalOpenTelemetry will not be used by the opencensus shim and thus not produce any traces. |
Describe the bug
We are currently migrating our microservices from OpenCensus to OpenTelemetry, using opencensus-shim to preserve traces from gcloud/grpc.
On startup, we are running into
Looking at the stacktrace, this happens because we are trying to access the gcloud project id before setting up the global opentelemetry using ServiceOptions from
google-cloud-core
:Steps to reproduce
Our specific case:
General case:
GlobalOpenTelemetry.get
/GlobalOpenTelemetry.getTracer
before buildAndRegisterGlobalLatter one is important as this can happen when using libraries that instrument OpenCensus, accessing the tracer e.g. in static fields.
What did you expect to see?
GlobalOpenTelemetry.get
should not set the GlobalOpenTelemetry.noop() in the fallback case but just return it.(→ remove line GlobalOpenTelemetry.java:67)
What did you see instead?
GlobalOpenTelemetry.get
has a side effect of setting the noop telemetry causing exception above.What version and what artifacts are you using?
Artifacts:
opentelemetry-api
,opentelemetry-sdk
,opentelemetry-opencensus-shim
Version:
1.10.1
How did you reference these artifacts? (excerpt from your
build.gradle
,pom.xml
, etc)In gradle subproject, used by all services:
Environment
Compiler: OpenJDK 11
OS: docker image gcr.io/distroless/java
Additional context
...
The text was updated successfully, but these errors were encountered: