Skip to content

opentelemetry-sdk-trace: BatchSpanExporter gets stuck when non-runtime exceptions are thrown (kotlin) #4348

Description

@gfelbing

Describe the bug

We are using opentelemtry-java with kotlin and a custom exporter.
We faced an issue that our exporter threw a java.net.ConnectException which wasn't catched in the exporter.
This caused the wrapping BatchSpanExporter's export thread being killed:

Exception in thread "BatchSpanProcessor_WorkerThread-1" java.net.ConnectException: Connection refused (Connection refused)
  at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
    at java.base/java.net.Socket.connect(Socket.java:609)
    at java.base/java.net.Socket.connect(Socket.java:558)
    at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
    at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
    at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:341)
    at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:362)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1253)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1187)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1015)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1367)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1342)
    [custom exporter stack]
    at io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.exportCurrentBatch(BatchSpanProcessor.java:320)
    at io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.run(BatchSpanProcessor.java:238)
    at java.base/java.lang.Thread.run(Thread.java:829)

Steps to reproduce

  • Implement a io.opentelemetry.sdk.trace.export.SpanExporter in kotlin and throw and uncatched java.net.ConnectException in export()
  • Try export any span using this exporter

What did you expect to see?

should catch and handle Throwable

What did you see instead?

Only RuntimeExceptions are catched. This is sufficient for java, as non-runtime exceptions are ensured to be catched by compiler.

What version and what artifacts are you using?

Artifacts:
- "io.opentelemetry:opentelemetry-api:${groupedVersions.io_opentelemetry}"
- "io.opentelemetry:opentelemetry-sdk:${groupedVersions.io_opentelemetry}"
- "io.opentelemetry:opentelemetry-exporter-zipkin:${groupedVersions.io_opentelemetry}"
- "io.opentelemetry:opentelemetry-semconv:${groupedVersions.io_opentelemetry}-alpha"
- "io.opentelemetry:opentelemetry-opencensus-shim:${groupedVersions.io_opentelemetry}-alpha"

Version: groupedVersions.io_opentelemetry = 1.10.1
How did you reference these artifacts? gradle java-platform plugin

Environment

Runtime: gcr.io/distroless/java

Additional context

We also handle errors now decently in our exporter, which is IMHO also the right place to do so.
Still, it would be great that if such an error happens, it only results in a warning log than in a stuck exporter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions