Skip to content

Commit

Permalink
(Fix) telemetry: allow overriding of service.version (#5689)
Browse files Browse the repository at this point in the history
Co-authored-by: bryn <bryn@apollographql.com>
  • Loading branch information
BrynCooke and bryn authored Jul 22, 2024
1 parent 8524c42 commit 4a0c250
Show file tree
Hide file tree
Showing 4 changed files with 388 additions and 368 deletions.
17 changes: 17 additions & 0 deletions .changesets/fix_bryn_service_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Allow overriding of service version ([PR #5689](https://github.com/apollographql/router/pull/5689))

Previously `service.version` was not overridable via yaml and was ignored. It is now possible to set this explicitly which can be useful for users producing custom builds of the Router.

For example:
```yaml
telemetry:
exporters:
tracing:
common:
resource:
service.version: 1.0
```
Overrides the version to `1.0`.

By [@BrynCooke](https://github.com/BrynCooke) in https://github.com/apollographql/router/pull/5689
37 changes: 23 additions & 14 deletions apollo-router/src/plugins/telemetry/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ use crate::plugins::telemetry::config::AttributeValue;
const UNKNOWN_SERVICE: &str = "unknown_service";
const OTEL_SERVICE_NAME: &str = "OTEL_SERVICE_NAME";

/// This resource detector fills out things like the default service version and executable name.
/// Users can always override them via config.
struct StaticResourceDetector;
impl ResourceDetector for StaticResourceDetector {
fn detect(&self, _timeout: Duration) -> Resource {
let mut config_resources = vec![];
config_resources.push(KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_VERSION,
std::env!("CARGO_PKG_VERSION"),
));

// Some other basic resources
if let Some(executable_name) = executable_name() {
config_resources.push(KeyValue::new(
opentelemetry_semantic_conventions::resource::PROCESS_EXECUTABLE_NAME,
executable_name,
));
}
Resource::new(config_resources)
}
}

struct EnvServiceNameDetector;
// Used instead of SdkProvidedResourceDetector
impl ResourceDetector for EnvServiceNameDetector {
Expand Down Expand Up @@ -42,6 +64,7 @@ pub(crate) trait ConfigResource {
let resource = Resource::from_detectors(
Duration::from_secs(0),
vec![
Box::new(StaticResourceDetector),
Box::new(config_resource_detector),
Box::new(EnvResourceDetector::new()),
Box::new(EnvServiceNameDetector),
Expand Down Expand Up @@ -84,24 +107,10 @@ impl ResourceDetector for ConfigResourceDetector {
let mut config_resources = vec![];

// For config resources last entry wins

// Add any other resources from config
for (key, value) in self.resources.iter() {
config_resources.push(KeyValue::new(key.clone(), value.clone()));
}

// Some other basic resources
config_resources.push(KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_VERSION,
std::env!("CARGO_PKG_VERSION"),
));
if let Some(executable_name) = executable_name() {
config_resources.push(KeyValue::new(
opentelemetry_semantic_conventions::resource::PROCESS_EXECUTABLE_NAME,
executable_name,
));
}

// Service namespace
if let Some(service_namespace) = self.service_namespace.clone() {
config_resources.push(KeyValue::new(
Expand Down
Loading

0 comments on commit 4a0c250

Please sign in to comment.