ref: Expose the sentry HTTP headers in the context, not tags
We used to have this functionality and somehow lost it when switching
to axum.  Also tags are indexed and these headers do not need to be
indexed.
Finally exporting `sentry.project_id` as a tag is very confusing together
`request.scope`.
+use std::collections::BTreeMap;
use std::task::{Context, Poll};
use axum::body::Body;
-use axum::http::{HeaderValue, Request};
+use axum::http::Request;
use tower_layer::Layer;
use tower_service::Service;
@@ -46,25 +47,17 @@ where
fn call(&mut self, request: Request<Body>) -> Self::Future {
sentry::configure_scope(|scope| {
- let headers = request.headers();
- fn get_str(val: &HeaderValue) -> Option<&str> {
- val.to_str().ok()
- }
- if let Some(worker_id) = headers.get("X-Sentry-Worker-Id").and_then(get_str) {
- scope.set_tag("sentry.worker_id", worker_id);
- }
- if let Some(project_id) = headers.get("X-Sentry-Project-Id").and_then(get_str) {
- scope.set_tag("sentry.project_id", project_id);
- }
- if let Some(event_id) = headers.get("X-Sentry-Event-Id").and_then(get_str) {
- scope.set_tag("sentry.event_id", event_id);
- }
-
- // TODO: We can use this in the future for distributed tracing once we make
- // properly support that in the SDK.
- if let Some(trace_id) = headers.get("Sentry-Trace").and_then(get_str) {
- scope.set_tag("sentry.trace", trace_id);
+ let mut headers = BTreeMap::new();
+ for (header, value) in request.headers() {
+ headers.insert(
+ header.to_string(),
+ value.to_str().unwrap_or("<Opaque header value>").into(),
+ );
}
+ scope.set_context(
+ "HTTP Request Headers",
+ sentry::protocol::Context::Other(headers),
+ );
});
self.service.call(request)
}
