-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add an optional trace header to metrics/logging #146
Conversation
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
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@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 |
@jbuck yeah, that's exactly the sort of comment I need. thanks! |
@@ -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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
if let Some(tracer) = settings.trace_header.clone() { | |
if let Some(ref tracer) = settings.trace_header { |
Description
This adds a
trace_header
setting. This will add the value (if found inthe Headers) to the tags as
header.trace
.(e.g. if a request has
X-Cloud-Trace-Context: abc123
this will add atag with
header.trace: abc123
to the outboud tags for logging andmetrics.)
Testing
Ensure the content of the tracing header is sent to metric and logging.
Issue(s)
Closes #145