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

Add custom OpenTelemetrySpanExt trait #700

Merged

Conversation

sergerad
Copy link

@sergerad sergerad commented Feb 17, 2025

Closes #678

  • Replaces re-export of tracing_opentelemetry::OpenTelemetrySpanExt with a custom trait of the same name
  • Removes re-export of opentelemetry::trace::Status in favour of a trait API that takes &dyn Error instead
  • Adds ToValue trait and impls for various Miden and core types

pub use opentelemetry::trace::Status as OtelStatus;
pub use tracing_opentelemetry::OpenTelemetrySpanExt;
use opentelemetry::trace::Status as OtelStatus;
use opentelemetry::{Key, Value};
Copy link
Author

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:

We can make set_attribute more ergonomic by adding a secondary trait ToValue which we can then implement for foreign types. i.e. instead of set_attribute("hash", digest.to_hex()), we can just do set_attribute("hash", &digest).

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?

Copy link
Contributor

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 introducing open-telemetry there is a reasonable expectation. Though it could make sense if we really want to standardize on it everywhere.

Copy link
Contributor

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 :)

Copy link
Author

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 implements trace::Span so I would have to change our Ext trait to be over impl<S: trace::Span + tracing_opentelemetry::OpenTelemetrySpanExt> and then make sure the tracing_opentelemetry::OpenTelemetrySpanExt applies to TestSpan. Unless I am missing something about how to using those testing utilities.

Copy link
Contributor

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.

Copy link
Contributor

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 for T: tracing::Span. So we just piggy back on theirs? Alternatively we keep as is and add another impl for the TestSpan specifically.

I'd do the former, and then see how it works out in the other PR?

@sergerad sergerad marked this pull request as ready for review February 18, 2025 05:09
sergerad and others added 4 commits February 18, 2025 19:57
Co-authored-by: Mirko <48352201+Mirko-von-Leipzig@users.noreply.github.com>
@Mirko-von-Leipzig Mirko-von-Leipzig merged commit 22f53bd into 0xPolygonMiden:next Feb 19, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants