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

Autoconfigured GlobalOpenTelemetry not flushing spans on shutdown, v1.23.0 #5218

Closed
rossabaker opened this issue Feb 15, 2023 · 2 comments · Fixed by #5221
Closed

Autoconfigured GlobalOpenTelemetry not flushing spans on shutdown, v1.23.0 #5218

rossabaker opened this issue Feb 15, 2023 · 2 comments · Fixed by #5221
Labels
Bug Something isn't working

Comments

@rossabaker
Copy link

Describe the bug
Using GlobalOpenTelemetry with auto-configuration enabled, the application is no longer flushing spans in the JVM shutdown hook. If I sleep for some time at the end of the main method, it works. It works reliably without sleep on 1.22.0.

Steps to reproduce

I am running the following code:

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;

class PlainJava {
    public static void main(String[] args) throws Exception {
        OpenTelemetry openTelemetry = GlobalOpenTelemetry.get();
        Tracer tracer = openTelemetry.getTracer("plain-java", "1.0.0");
        Span span = tracer.spanBuilder("my span").startSpan();
        try (Scope ss = span.makeCurrent()) {
            // In this scope, the span is the current/active span
        } finally {
            span.end();
        }
        // Thread.sleep(10000);
    }
}

This is running with -Dotel.java.global-autoconfigure.enabled=true and no other otel-related system properties or environment variables. A local Jaeger is listening on port 4317.

What did you expect to see?
I expected to see a trace with my span in my local Jaeger UI.

What did you see instead?
No trace was received.

What version and what artifacts are you using?
Artifacts:

  • opentelemetry-sdk
  • opentelemetry-sdk-extension-autoconfigure
  • opentelemetry-exporter-otlp

Version: v1.23.0
How did you reference these artifacts? From SBT:

    libraryDependencies ++= Seq(
      "io.opentelemetry" % "opentelemetry-exporter-otlp" % OpenTelemetryVersion,
      "io.opentelemetry" % "opentelemetry-sdk" % OpenTelemetryVersion,
      "io.opentelemetry" % "opentelemetry-sdk-extension-autoconfigure" % s"${OpenTelemetryVersion}-alpha"
    ),
    run / fork := true,
    javaOptions += "-Dotel.java.global-autoconfigure.enabled=true"

Environment
Compiler: Azul Systems, Inc. Java 19.0.1
OS: MacOS Ventura 13.1

Additional context

  • It works as expected on 1.22.0
  • I built opentelemetry-java locally, and can confirm OpenTelemetry.close() is called and that shutdown completes successfully.
  • The changes in 4df4a0a seem relevant, but I don't see a problem.
  • I originally hit this in Scala's otel4s, but I've minimized it to pure Java aside from the build. I can throw together a POM to completely eliminate Scala, but I don't think that's it.
@jack-berg
Copy link
Member

I can verify that this is a bug. Looks like I botched the ordering of the shutdown hook and its not operating on the OpenTelemetrySdk instance that ends up being used.

@jkwatson we should issue a patch for this. @trask can we hold off on the instrumentation release to incorporate the patch?

@trask
Copy link
Member

trask commented Feb 15, 2023

@trask can we hold off on the instrumentation release to incorporate the patch?

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants