Skip to content
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
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