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

Expose active traces through telemetry server #87

Merged
merged 5 commits into from
Dec 9, 2024

Conversation

cbranch
Copy link
Collaborator

@cbranch cbranch commented Nov 6, 2024

Tracks currently-active spans in a low-overhead manner (relative to the general overhead of tracing, at least). This is particularly useful because even unsampled traces are available to be viewed here.

The model for this functionality is https://pkg.go.dev/golang.org/x/net/trace although there is no built-in viewer here, we expect you to use Chrome's about:tracing or anything that supports the same JSON log format.

This requires more functionality in our rustracing fork so we can get data set on the spans: cloudflare/rustracing#4

@cbranch cbranch force-pushed the cbranch/active-trace-server branch from 2b1290a to 2e03391 Compare November 6, 2024 12:13
Tracks currently-active spans in a low-overhead manner (relative to the
general overhead of tracing, at least). This is particularly useful because
even unsampled traces are available to be viewed here.

The model for this functionality is https://pkg.go.dev/golang.org/x/net/trace
although there is no built-in viewer here, we expect you to use Chrome's
about:tracing or anything that supports the same JSON log format.
@cbranch cbranch force-pushed the cbranch/active-trace-server branch from 2e03391 to 10fec1b Compare November 25, 2024 17:08
is_sampled,
}
}
}

impl SharedSpan {
pub(crate) fn into_span(self) -> Arc<parking_lot::RwLock<Span>> {
Arc::clone(&self.inner)
Copy link

Choose a reason for hiding this comment

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

  1. Since you consume self, you shouldn't need to clone
  2. Doesn't this return an Arc<LiveReferenceHandle<...>> if telemetry-server is enabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I attempted to reconcile this magical behaviour by defining a newtype struct in a new commit.

Copy link

Choose a reason for hiding this comment

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

Thanks, that definitely helps make clear what happens here.

foundations/src/telemetry/tracing/live/mod.rs Outdated Show resolved Hide resolved
foundations/src/telemetry/tracing/live/event_output.rs Outdated Show resolved Hide resolved
escape(name),
escape(category),
match event_type {
TraceEventType::Begin => "B",
Copy link

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Despite the name, async events don't have the right semantics for what we want to express here. Regular events are enough for the visualisation.

timestamp_us: u64,
) {
self.out.push_str(&format!(
"{{\"pid\":1,\"name\":\"{}\",\"cat\":\"{}\",\"ph\":\"{}\",\"ts\":{},\"id\":\"{}\"}},",
Copy link

Choose a reason for hiding this comment

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

It would be nice to also emit the trace tags as args, but I understand if you don't have time to implement this right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tags are typed, so we'd need to generate JSON objects with serde or something rather than this quick and dirty approach.

Copy link

Choose a reason for hiding this comment

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

Yeah, let's leave that for a future iteration

Using a different named type for SharedSpanInner depending on features
causes unclear behaviour due to auto-deref. Instead, define a newtype
with common methods in both feature variants.
@evanrittenhouse
Copy link
Contributor

Nice!

@cbranch cbranch force-pushed the cbranch/active-trace-server branch from 1e16b5a to 0a60af5 Compare December 9, 2024 11:16
@fisherdarling fisherdarling self-requested a review December 9, 2024 11:43
@dotjs dotjs merged commit befa6f6 into main Dec 9, 2024
18 checks passed
@dotjs dotjs deleted the cbranch/active-trace-server branch December 9, 2024 11:55
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.

5 participants