Skip to content
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

Every time call Conext.current() will return a different object #11700

Open
jianwu opened this issue Jun 28, 2024 · 2 comments
Open

Every time call Conext.current() will return a different object #11700

jianwu opened this issue Jun 28, 2024 · 2 comments
Labels
bug Something isn't working needs triage New issue that requires triage

Comments

@jianwu
Copy link

jianwu commented Jun 28, 2024

Describe the bug

Once we added dependency to this library: io.opentelemetry.instrumentation / opentelemetry-grpc-1.6
It will inject the ContextStorageBridge, with that, it changes the Context.current() behavior, it will return a new Object everytime call the method. That causes various issue such as it breaks the unit test that depends the equality of the Context.

Steps to reproduce

Add dependency to: io.opentelemetry.instrumentation / opentelemetry-grpc-1.6

Run following code:

package org.example;

import io.grpc.Context;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.context.Scope;


public class Main {
  public static void main(String[] args) {
    try (Scope scope = GlobalOpenTelemetry.get().getTracer("test").spanBuilder("test").startSpan().makeCurrent()) {
      System.out.println(Context.current().equals(Context.current()));
    }
  }
}

Expected behavior

It prints "false"

Actual behavior

it should print "true"

Javaagent or library instrumentation version

1.64.0

Environment

JDK: Java 17
OS: Mac os

Additional context

No response

@jianwu jianwu added bug Something isn't working needs triage New issue that requires triage labels Jun 28, 2024
@laurit
Copy link
Contributor

laurit commented Jul 5, 2024

@jianwu is there anything in gRPC documentation that requires Context.current() to return the same instance. Or is this an undocumented behavior that your application relies on?

@laurit laurit added the needs author feedback Waiting for additional feedback from the author label Jul 5, 2024
@jianwu
Copy link
Author

jianwu commented Jul 9, 2024

Not sure if this is specified. But this seems to be a common sense behavior. When you call a current() multiple times, if you return a different object every time, it will cause surprise and also performance issue. In our case, we have unit test that verify the GRpc context is not changed after calling some logic. And those unit test has nothing to do with OTel at all. Only because we added the dependency in a lower level common library. As the OTel version of ContextStorageOverride is dynamically discovered. It breaks those unit tests.

This breakage is hard to troubleshoot. Also I can't find a workaround for this issue and there's no meaningful equal() for GRpc context.

@github-actions github-actions bot removed the needs author feedback Waiting for additional feedback from the author label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New issue that requires triage
Projects
None yet
Development

No branches or pull requests

2 participants