-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add custom OpenTelemetrySpanExt trait #700
Merged
Mirko-von-Leipzig
merged 9 commits into
0xPolygonMiden:next
from
sergerad:sergerad/span-ext-trait
Feb 19, 2025
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5410859
Replace ext trait with basic impl
sergerad 8e21534
Add sealed and set_error impl
sergerad 6d9c4e7
Add ToValue trait
sergerad e30f0a6
Fmt and changelog
sergerad a7fd42e
RM as_u32() call
sergerad f81051d
RM changelog line and replace sealed dep
sergerad 974f44a
Coalesce err sources
sergerad 301982a
span_ext mod
sergerad 5c81741
Replace ext impl for generic Span
sergerad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
pub mod grpc; | ||
|
||
// Re-export useful traits for open-telemetry traces. This avoids requiring other crates from | ||
// importing that family of crates directly. | ||
pub use opentelemetry::trace::Status as OtelStatus; | ||
pub use tracing_opentelemetry::OpenTelemetrySpanExt; | ||
use opentelemetry::trace::Status as OtelStatus; | ||
use opentelemetry::{Key, Value}; | ||
use sealed::sealed; | ||
|
||
/// Utility functions based on [`tracing_opentelemetry::OpenTelemetrySpanExt`]. | ||
#[sealed] | ||
pub trait OpenTelemetrySpanExt { | ||
fn set_attribute(&self, key: impl Into<Key>, value: impl Into<Value>); | ||
fn set_error(&self, err: &dyn std::error::Error); | ||
} | ||
|
||
#[sealed] | ||
impl OpenTelemetrySpanExt for tracing::Span { | ||
/// Sets an attribute on `Span`. | ||
fn set_attribute(&self, key: impl Into<Key>, value: impl Into<Value>) { | ||
tracing_opentelemetry::OpenTelemetrySpanExt::set_attribute(self, key, value); | ||
} | ||
/// Sets a status on `Span` based on an error. | ||
fn set_error(&self, err: &dyn std::error::Error) { | ||
tracing_opentelemetry::OpenTelemetrySpanExt::set_status( | ||
self, | ||
OtelStatus::Error { description: format!("{err:?}").into() }, | ||
Mirko-von-Leipzig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@Mirko-von-Leipzig in the issue you mentioned:
I was wondering if this is worthwhile considering that crates can already
impl From<...> for opentelemetry::Value
for their types and rely on the trait as is, value: impl Into<Value>);
.WDYT?
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.
Most of our core types come from the crates from
miden-base
- and I don't think introducingopen-telemetry
there is a reasonable expectation. Though it could make sense if we really want to standardize on it everywhere.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.
Actually here we go: https://docs.rs/opentelemetry_sdk/latest/opentelemetry_sdk/testing/trace/index.html
They do actually have test infra :)
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.
Just checking you meant that this is relevant for this PR and not the other trace-related PR #698.
TestSpan
implementstrace::Span
so I would have to change our Ext trait to be overimpl<S: trace::Span + tracing_opentelemetry::OpenTelemetrySpanExt>
and then make sure thetracing_opentelemetry::OpenTelemetrySpanExt
applies toTestSpan
. Unless I am missing something about how to using those testing utilities.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.
Ah right; yeah this was intended for their 😅 Will cross-post just for traceability.
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.
Hmm. Yes good point - we can
impl<S: OpenTelemetrySpanExt>
because it in turn is implemented forT: tracing::Span
. So we just piggy back on theirs? Alternatively we keep as is and add another impl for theTestSpan
specifically.I'd do the former, and then see how it works out in the other PR?