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

Remove the deployment ID from the trace. #65

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions rust-connector-sdk/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::error::Error;
use tracing_subscriber::EnvFilter;

use axum::body::{Body, BoxBody};
use http::{Request, Response, Uri};
use http::{Request, Response};
use opentelemetry_http::HeaderExtractor;
use std::time::Duration;
use tracing::{Level, Span};
use tracing::Span;
use tracing_opentelemetry::OpenTelemetrySpanExt;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
Expand Down Expand Up @@ -70,13 +70,11 @@ pub fn init_tracing(
// tracing crate requires all fields to be defined at creation time, so any fields that will be set
// later should be defined as Empty
pub fn make_span(request: &Request<Body>) -> Span {
let span = tracing::span!(
Level::INFO,
let span = tracing::info_span!(
"request",
method = %request.method(),
uri = %request.uri(),
version = ?request.version(),
deployment_id = extract_deployment_id(request.uri()),
status = tracing::field::Empty,
latency = tracing::field::Empty,
);
Expand All @@ -92,14 +90,6 @@ pub fn make_span(request: &Request<Body>) -> Span {
span
}

// Rough implementation of extracting deployment ID from URI. Regex might be better?
fn extract_deployment_id(uri: &Uri) -> &str {
let path = uri.path();
let mut parts = path.split('/').filter(|x| !x.is_empty());
let _ = parts.next().unwrap_or_default();
parts.next().unwrap_or("unknown")
}

// Custom function for adding information to request-level span that is only available at response time.
pub fn on_response(response: &Response<BoxBody>, latency: Duration, span: &Span) {
span.record("status", tracing::field::display(response.status()));
Expand Down