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

Define default for service.name #384

Closed
jtescher opened this issue Dec 14, 2020 · 4 comments
Closed

Define default for service.name #384

jtescher opened this issue Dec 14, 2020 · 4 comments
Labels
good first issue Good for newcomers

Comments

@jtescher
Copy link
Member

See the spec change for details open-telemetry/opentelemetry-specification#1269

@denismaxim0v
Copy link

Should be closed?

@ymtdzzz
Copy link
Contributor

ymtdzzz commented Mar 28, 2023

seems to be already defined?

fn detect(&self, _timeout: Duration) -> Resource {
Resource::new(vec![KeyValue::new(
"service.name",
env::var(OTEL_SERVICE_NAME)
.ok()
.filter(|s| !s.is_empty())
.unwrap_or_else(|| {
EnvResourceDetector::new()
.detect(Duration::from_secs(0))
.get(Key::new("service.name"))
.map(|v| v.to_string())
.filter(|s| !s.is_empty())
.unwrap_or_else(|| match option_env!("CARGO_BIN_NAME") {
Some(s) => s.to_string(),
None => "unknown_service".to_string(),
})
}),
)])
}

@TommyCpp TommyCpp closed this as completed Apr 7, 2023
@ivanitskiy
Copy link

I just tried a few things with mini-redis. It seems to me it doesn't use CARGO_BIN_NAME.

steps:

  1. using this docker docker run -d --rm --name jaeger -e COLLECTOR_OTLP_ENABLED=true -p 16686:16686 -p 4317:4317 -p 4318:4318 jaegertracing/all-in-one:latest
  2. start mini-redis server RUST_LOG=debug cargo run --bin mini-redis-server --features otel
  3. set a value RUST_LOG=debug cargo run --bin mini-redis-cli --features otel -- set foo bar
  4. then validate in Jaeger traces:
image 5. it does use env variable **OTEL_SERVICE_NAME** `OTEL_SERVICE_NAME=whatever RUST_LOG=debug cargo run --bin mini-redis-server --features otel` image

however when i change mini-redis code to use CARGO_BIN_NAME via with_resource():

diff --git a/src/bin/server.rs b/src/bin/server.rs
index 701a1f1..ad4df39 100644
--- a/src/bin/server.rs
+++ b/src/bin/server.rs
@@ -12,12 +12,12 @@ use clap::Parser;
 use tokio::net::TcpListener;
 use tokio::signal;
 
-#[cfg(feature = "otel")]
-// To be able to set the XrayPropagator
-use opentelemetry::global;
 #[cfg(feature = "otel")]
 // To configure certain options such as sampling rate
-use opentelemetry::sdk::trace as sdktrace;
+use opentelemetry::sdk::{trace as sdktrace, Resource};
+#[cfg(feature = "otel")]
+// To be able to set the XrayPropagator
+use opentelemetry::{global, KeyValue};
 #[cfg(feature = "otel")]
 // For passing along the same XrayId across services
 use opentelemetry_aws::trace::XrayPropagator;
@@ -71,6 +71,10 @@ fn set_up_logging() -> Result<(), TryInitError> {
         .with_trace_config(
             sdktrace::config()
                 .with_sampler(sdktrace::Sampler::AlwaysOn)
+                .with_resource(Resource::new(vec![
+                    KeyValue::new("service.name", env!("CARGO_BIN_NAME")),
+                    KeyValue::new("service.version", env!("CARGO_PKG_VERSION")),
+                ]))
                 // Needed in order to convert the trace IDs into an Xray-compatible format
                 .with_id_generator(sdktrace::XrayIdGenerator::default()),
         )
image

@djc
Copy link
Contributor

djc commented Jun 29, 2023

Maybe open a new issue and refer to the relevant PR to make sure this doesn't get lost?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants