-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use guard pattern to allow consumers to ensure final trace is se…
…nt (#185) * Use guard pattern to allow consumers to ensure final trace is sent * Add must_use to struct * Switch examples to use guard pattern In discussion with the Rust OpenTelemetry crate maintainers, the `shutdown_tracer_provider` function intentionally no longer ensures that the final traces are sent to the OpenTelemetry server before the application exits. To perform this functionality, we now need to call `force_flush` on the TracerProvider instance. Since the public API functions for the TracerProvider only return a trait object which does not have this function exposed, we need to keep an instance of the actual TracerProvider around. In order to make this simple for consumers of this crate, I have used the guard pattern here so that they do not need to worry about those details or pull in the crates that provide those types. An instance of the TracerProvider is kept in a private field of the TracingGuard struct, which is returned by the init functions. That struct impls `Drop` to call `force_flush` when the struct is dropped. As such, crate consumers only need to use the `let _guard =` syntax to ensure the guard is only dropped when the function actually exits. This also allows us to, in the future, include other provider flushes in the same pattern, such as for OpenTelemetry logs and metrics. In addition, as the `Drop` impl only performs a `force_flush`, if any consumers of this crate update to a version with this and do not make any code changes, their code will continue to behave exactly the same - the guard struct will be dropped immediately, triggering the `force_flush`, but the provider will continue to operate. Their application will behave exactly as it did before with regard to sending traces. It only loses the behavior of ensuring the final traces are sent before application exit, but that wasn't working before this anyways. FIX #184
- Loading branch information
1 parent
9433355
commit 4a321b0
Showing
7 changed files
with
31 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters