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

fix: append service.name to prevent it being overidden #22

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion examples/layers/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ fn setup_tracing(otel_is_configured: bool, tags: &[(&str, &str)]) -> Result<(),
.with_target(false);

// Setup an Axiom OpenTelemetry compatible tracing layer
let axiom_layer = tracing_axiom::builder().with_tags(tags).layer()?;
let axiom_layer = tracing_axiom::builder()
.with_service_name("layers")
.with_tags(tags)
.layer()?;

// Setup our multi-layered tracing subscriber
Registry::default()
Expand Down
1 change: 1 addition & 0 deletions examples/noenv/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn say_hi(id: Uuid, name: impl Into<String> + std::fmt::Debug) {
#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_axiom::builder()
.with_service_name("noenv")
.with_tags(&[("aws_region", "us-east-1")]) // Set otel tags
.with_dataset("tracing-axiom-examples") // Set dataset
.with_token("xaat-some-valid-token") // Set API token
Expand Down
18 changes: 9 additions & 9 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,22 @@ impl Builder {
format!("tracing-axiom/{}", env!("CARGO_PKG_VERSION")),
);

let mut trace_config = self.trace_config.unwrap_or_default();
if let Some(service_name) = self.service_name {
trace_config = trace_config.with_resource(Resource::new(vec![KeyValue::new(
SERVICE_NAME,
service_name, // TODO: Is there a way to get the name of the bin crate using this?
)]));
}

let mut tags = self.tags.clone();
tags.extend(vec![
KeyValue::new(TELEMETRY_SDK_NAME, env!("CARGO_PKG_NAME").to_string()),
KeyValue::new(TELEMETRY_SDK_VERSION, env!("CARGO_PKG_VERSION").to_string()),
KeyValue::new(TELEMETRY_SDK_LANGUAGE, "rust".to_string()),
]);

trace_config = trace_config.with_resource(Resource::new(tags));
if let Some(service_name) = self.service_name {
// TODO: Is there a way to get the name of the bin crate using this?
tags.push(KeyValue::new(SERVICE_NAME, service_name));
}

let trace_config = self
.trace_config
.unwrap_or_default()
.with_resource(Resource::new(tags));

let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
Expand Down
Loading