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

adding support for setting the status of the span through SpanExt #176

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

webfinesse
Copy link
Contributor

Motivation

I have found that when working with tracing spans created by 3rd party libraries, it is incredibly difficult to set the OpenTelemetry Status of the span, which results in always having an unset span in my visualization tool.

image

In this case, I am working with the span created by the aws_lambda_runtime crate.

Unfortunately, since the span in the aws_lambda_runtime crate does not include the otel.status_code attribute upfront the OpenTelemetryLayer::SpanAttributeVisitor::record_str and OpenTelemetryLayer::SpanAttributeVisitor::record_debug never gets triggered when calling tracing::Span::current().record("otel.status_code", "ok"); This behavior of the record function ignoring new fields is documented here

Solution

My solution to this is add a new member OpenTelemetrySpanExt::set_status that takes an opentelemetry::trace::Status enum that gets written to the underlying SpanBuilder.

@webfinesse webfinesse changed the title adding support for setting the status of the span through through SpanExt adding support for setting the status of the span through SpanExt Oct 17, 2024
Copy link
Collaborator

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, thanks!

(In addition to my remarks below, need to fix up the formatting to appease CI.)

src/span_ext.rs Show resolved Hide resolved
src/span_ext.rs Show resolved Hide resolved
tests/span_ext.rs Outdated Show resolved Hide resolved
@djc djc merged commit ab629c3 into tokio-rs:v0.1.x Oct 18, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants