open-telemetry / open-telemetry/opentelemetry-java-instrumentation

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

Open
#11,700 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs triage
Dominant language
Java
Stars
2.6k
Forks
1.2k
Avg merge
2d 18h
Merged PRs (30d)
228

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The reported entry points are Context.current() and the injected ContextStorageBridge; first run the Java 17 reproduction with opentelemetry-grpc-1.6 and compare repeated current() results. Trace how the bridge supplies the current context, and consider the issue done when repeated calls preserve the expected equality without breaking the instrumentation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.