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

[WIP] opentelemetry-aware event formatter #1304

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Mar 15, 2021

this doesn't quite work yet, but i thought it could be nice to have --- possibly @jtescher has some advice on how to handle remote parents nicely (and, if i'm missing anything that we should be logging?)

@hawkw hawkw requested review from davidbarsky, jtescher and a team as code owners March 15, 2021 20:50
Copy link
Collaborator

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Exciting! Couple of quick ideas for getting things closer to what you may have wanted

.and_then(|span| {
let ext = span.extensions();
let builder = ext.get::<otel::SpanBuilder>()?;
let tid = builder.trace_id.unwrap_or_else(otel::TraceId::invalid);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic is a little complex currently unfortunately. Basically 3 cases here:

  1. parent context with active span
  2. parent context with remote span
  3. set trace id in builder

So you should see the correct trace ids with something along the lines of:

span.as_ref()
    .and_then(|span| {
        let ext = span.extensions();
        let builder = ext.get::<otel::SpanBuilder>()?;

        if let Some(ref parent) = builder.parent_context {
            if parent.has_active_span() {
                return Some(parent.span().span_context().trace_id());
            }
            if let Some(remote) = parent.remote_span_context() {
                return Some(remote.trace_id());
            }
        }

        builder.trace_id
    })
    .unwrap_or_else(otel::TraceId::invalid)

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks! i was having a really hard time figuring out what the right logic here was, that's really helpful.

write!(
writer,
"{{{:?}}}{}:",
remote_parent.trace_state(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

remote_parent.trace_flags() may actually be more interesting here as it contains sampling information and is present in all spans, values from the tracestate-header are less common and often opaque to the application anyway

Copy link
Member Author

Choose a reason for hiding this comment

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

okay, thanks! i wasn't sure which data was more likely to be useful — perhaps we would want an option to show trace flags for local spans as well, for debugging sampling?

i was hoping there was a way to get key-value data, names, etc for remote spans to display in the logs, but it seems like that's not available to us...(which does make sense; we wouldn't want to pass that data around everywhere). is there any way we can hydrate that data from span IDs, or is that not supported?

Copy link
Collaborator

Choose a reason for hiding this comment

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

okay, thanks! i wasn't sure which data was more likely to be useful — perhaps we would want an option to show trace flags for local spans as well, for debugging sampling?

Yeah I think that would make sense as an option 👍

i was hoping there was a way to get key-value data, names, etc for remote spans to display in the logs, but it seems like that's not available to us...(which does make sense; we wouldn't want to pass that data around everywhere). is there any way we can hydrate that data from span IDs, or is that not supported?

That would be interesting but I don't think that it's possible to get information about remote spans currently, you basically just work with a serialized SpanContext when injecting/extracting.

@hawkw hawkw marked this pull request as draft October 12, 2021 17:33
@bryangarza
Copy link
Member

This seems useful, would love to see it get merged in the future.

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.

3 participants