-
Notifications
You must be signed in to change notification settings - Fork 848
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
Make sure the 2nd call to shutdown() on the GRPC exporters succeeds. #3307
Conversation
@@ -179,6 +179,9 @@ public static OtlpGrpcSpanExporter getDefault() { | |||
*/ | |||
@Override | |||
public CompletableResultCode shutdown() { | |||
if (managedChannel.isShutdown()) { | |||
return CompletableResultCode.ofSuccess(); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's definitely still a race condition in here, where the shutdown can complete in between this check and the addition of the 2nd notification listener. I'm not sure if there's a solution to that or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add the listener first and do it like this?
final CompletableResultCode result = new CompletableResultCode();
managedChannel.notifyWhenStateChanged(ConnectivityState.SHUTDOWN, result::succeed);
if (managedChannel.isShutdown()) {
return result.succeed();
}
managedChannel.shutdown();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does seem tighter. Depending on the grpc internals, there might still be a race, but this change will definitely make it less likely. Thanks for the suggestion!
This adds a `natchez-opentelemetry` module which allows span reporting via the `opentelemetry-java` project. The `Utils` object contains a helper to turn the `OpenTelemetry` `CompletableResultCode` class into an `F[Unit]` given `Async[F]`, this is useful for implementing `Resource`s for clean shutdown logic. `Shutdownable` is a little abstraction to unify all the interfaces that have a `shutdown(): CompletableResultCode` method in `OpenTelemetry`, since they have no common interface. `OpenTelemetrySpan` and `OpenTelemetryEntryPoint` are heavily based on the `natchez-jaeger` versions, with tweaks to make them with with `OpenTelemetry. The `OpenTelemetry` object which end users should interact with has these methods: * `lift` can be used to lift any `F[T]` where `T` is an `OpenTelemetry` class with a `shutdown` method into a `Resource[F, T], it asks for a name to provide a nice error message * `entryPoint` is the main way to make an `EntryPoint` and has a boolean flag to allow the user to globally register the `OpenTelemetry` if that's helpful, this defaults to false. * `globalEntryPoint` will use the globally registered `OpenTelemetry` to create an `EntryPoint` Note that this is currently using `OpenTelemetry` libraries at `1.4.0-SNAPSHOT` because I found a bug while developing this this broke the shutdown logic. The issue is here open-telemetry/opentelemetry-java#3306 and it was closed by this PR open-telemetry/opentelemetry-java#3307 so it should make it into the next release.
Resolves #3306