Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

feat: add an optional trace header to metrics/logging #146

Merged
merged 6 commits into from
Jun 10, 2021
Merged

Conversation

jrconlin
Copy link
Member

@jrconlin jrconlin commented Jun 8, 2021

Description

This adds a trace_header setting. This will add the value (if found in
the Headers) to the tags as header.trace.

(e.g. if a request has X-Cloud-Trace-Context: abc123 this will add a
tag with header.trace: abc123 to the outboud tags for logging and
metrics.)

Testing

Ensure the content of the tracing header is sent to metric and logging.

Issue(s)

Closes #145

jrconlin added 2 commits June 8, 2021 15:12
This adds a `trace_header` setting. This will add the value (if found in
the Headers) to the tags as `header.trace`.

(e.g. if a request has `X-Cloud-Trace-Context: abc123` this will add a
tag with `header.trace: abc123` to the outboud tags for logging and
metrics.)

Closes #145
@jrconlin jrconlin requested review from jbuck and a team June 8, 2021 22:21
src/settings.rs Outdated
// TODO: someone better at lifetimes could fix these.
// The returned settings need only last as long as the request.
// we clone to break out of the Arc
impl From<&HttpRequest> for Settings {
Copy link
Member

Choose a reason for hiding this comment

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

This was trickier than I thought it was gonna be 😅 but I think this works:

feat/145-trace...feat/145-trace-lifetimes

Wanna apply the same to impl From<&ServiceRequest> for Settings below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, cool! Thanks!
Yep, I'll modify the other ones along the same lines.

@jbuck
Copy link
Collaborator

jbuck commented Jun 9, 2021

@jrconlin sorry, I don't understand this code so I'm not sure where to add my comment... but it's critical that the trace tag isn't added to statsd, and only added to sentry/log output. The trace id is a random string which will blow up influxdb cardinality

@jrconlin
Copy link
Member Author

jrconlin commented Jun 9, 2021

@jbuck yeah, that's exactly the sort of comment I need. thanks!

@jrconlin jrconlin changed the title Feat/145 trace feat: add an optional trace header to metrics/logging Jun 10, 2021
pjenvey
pjenvey previously approved these changes Jun 10, 2021
@@ -127,6 +129,15 @@ impl From<&RequestHead> for Tags {
extra.insert("ua".to_owned(), uas.to_string());
}
}
if let Some(tracer) = settings.trace_header.clone() {
Copy link
Member

Choose a reason for hiding this comment

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

nit

Suggested change
if let Some(tracer) = settings.trace_header.clone() {
if let Some(ref tracer) = settings.trace_header {

@jrconlin jrconlin merged commit 762bc39 into main Jun 10, 2021
@jrconlin jrconlin deleted the feat/145-trace branch June 10, 2021 23:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add trace context to metric and logging calls
3 participants