diff --git a/.changesets/config_bryn_telemetry_config_fixes.md b/.changesets/config_bryn_telemetry_config_fixes.md index 383e18efc81..d72d9f2ece5 100644 --- a/.changesets/config_bryn_telemetry_config_fixes.md +++ b/.changesets/config_bryn_telemetry_config_fixes.md @@ -2,13 +2,33 @@ Configuration between tracing and metrics was inconsistent and did not align with otel spec terminology. The following changes have been made to router.yaml configuration: -`trace_config` has been renamed to `common` +`telemetry.tracing.trace_config` has been renamed to `common` - ```diff +```diff telemetry tracing: - trace_config: + common: - ``` +``` + +`telemetry.tracing.common.attributes` has been renamed to `resource` +```diff +telemetry + tracing: + common: +- attributes: ++ resource: +``` + +`telemetry.metrics.common.resources` has been renamed to `resource` +```diff +telemetry + metrics: + common: +- resources: ++ resource: +``` + +The Router will upgrade any existing configuration on startup. However, you should update your configuration to use the new format as soon as possible. By [@BrynCooke](https://github.com/BrynCooke) in https://github.com/apollographql/router/pull/4044 diff --git a/apollo-router/src/configuration/migrations/0015-telemetry_metrics_resource.yaml b/apollo-router/src/configuration/migrations/0015-telemetry_metrics_resource.yaml new file mode 100644 index 00000000000..c463fbb5e60 --- /dev/null +++ b/apollo-router/src/configuration/migrations/0015-telemetry_metrics_resource.yaml @@ -0,0 +1,5 @@ +description: telemetry.metrics.common.resources has been renamed to telemetry.metrics.common.resource +actions: + - type: move + from: telemetry.metrics.common.resources + to: telemetry.metrics.common.resource diff --git a/apollo-router/src/configuration/migrations/0016-telemetry_tracing_resource.yaml b/apollo-router/src/configuration/migrations/0016-telemetry_tracing_resource.yaml new file mode 100644 index 00000000000..286898b4ec3 --- /dev/null +++ b/apollo-router/src/configuration/migrations/0016-telemetry_tracing_resource.yaml @@ -0,0 +1,5 @@ +description: telemetry.tracing.common.attributes has been renamed to telemetry.tracing.common.resource +actions: + - type: move + from: telemetry.tracing.common.attributes + to: telemetry.tracing.common.resource diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap index c4ee9cc3a70..3097f16ae6c 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap @@ -4426,8 +4426,8 @@ expression: "&schema" }, "additionalProperties": false }, - "resources": { - "description": "Otel configuration via resource", + "resource": { + "description": "The Open Telemetry resource", "default": {}, "type": "object", "additionalProperties": { @@ -4697,8 +4697,48 @@ expression: "&schema" "description": "Common configuration", "type": "object", "properties": { - "attributes": { - "description": "The resources configured on the tracing pipeline", + "max_attributes_per_event": { + "description": "The maximum attributes per event before discarding", + "default": 128, + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "max_attributes_per_link": { + "description": "The maximum attributes per link before discarding", + "default": 128, + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "max_attributes_per_span": { + "description": "The maximum attributes per span before discarding", + "default": 128, + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "max_events_per_span": { + "description": "The maximum events per span before discarding", + "default": 128, + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "max_links_per_span": { + "description": "The maximum links per span before discarding", + "default": 128, + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "parent_based_sampler": { + "description": "Whether to use parent based sampling", + "default": true, + "type": "boolean" + }, + "resource": { + "description": "The Open Telemetry resource", "default": {}, "type": "object", "additionalProperties": { @@ -4759,46 +4799,6 @@ expression: "&schema" ] } }, - "max_attributes_per_event": { - "description": "The maximum attributes per event before discarding", - "default": 128, - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "max_attributes_per_link": { - "description": "The maximum attributes per link before discarding", - "default": 128, - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "max_attributes_per_span": { - "description": "The maximum attributes per span before discarding", - "default": 128, - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "max_events_per_span": { - "description": "The maximum events per span before discarding", - "default": 128, - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "max_links_per_span": { - "description": "The maximum links per span before discarding", - "default": 128, - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "parent_based_sampler": { - "description": "Whether to use parent based sampling", - "default": true, - "type": "boolean" - }, "sampler": { "description": "The sampler, always_on, always_off or a decimal between 0.0 and 1.0", "anyOf": [ diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__upgrade_old_configuration@telemetry_attributes.router.yaml.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__upgrade_old_configuration@telemetry_attributes.router.yaml.snap new file mode 100644 index 00000000000..9e35a834f9e --- /dev/null +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__upgrade_old_configuration@telemetry_attributes.router.yaml.snap @@ -0,0 +1,11 @@ +--- +source: apollo-router/src/configuration/tests.rs +expression: new_config +--- +--- +telemetry: + tracing: + common: + resource: + test: val + diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__upgrade_old_configuration@telemetry_resources.router.yaml.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__upgrade_old_configuration@telemetry_resources.router.yaml.snap new file mode 100644 index 00000000000..1eef0d0b60a --- /dev/null +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__upgrade_old_configuration@telemetry_resources.router.yaml.snap @@ -0,0 +1,11 @@ +--- +source: apollo-router/src/configuration/tests.rs +expression: new_config +--- +--- +telemetry: + metrics: + common: + resource: + test: val + diff --git a/apollo-router/src/configuration/testdata/migrations/telemetry_attributes.router.yaml b/apollo-router/src/configuration/testdata/migrations/telemetry_attributes.router.yaml new file mode 100644 index 00000000000..ec08ac32b7c --- /dev/null +++ b/apollo-router/src/configuration/testdata/migrations/telemetry_attributes.router.yaml @@ -0,0 +1,6 @@ +telemetry: + tracing: + common: + attributes: + test: val + diff --git a/apollo-router/src/configuration/testdata/migrations/telemetry_resources.router.yaml b/apollo-router/src/configuration/testdata/migrations/telemetry_resources.router.yaml new file mode 100644 index 00000000000..814d7408cae --- /dev/null +++ b/apollo-router/src/configuration/testdata/migrations/telemetry_resources.router.yaml @@ -0,0 +1,6 @@ +telemetry: + metrics: + common: + resources: + test: val + diff --git a/apollo-router/src/configuration/testdata/tracing_config.router.yaml b/apollo-router/src/configuration/testdata/tracing_config.router.yaml index fee8cc5469e..38e2bfab626 100644 --- a/apollo-router/src/configuration/testdata/tracing_config.router.yaml +++ b/apollo-router/src/configuration/testdata/tracing_config.router.yaml @@ -3,7 +3,7 @@ supergraph: telemetry: tracing: common: - attributes: + resource: foo: bar max_attributes_per_event: 2 max_attributes_per_link: 3 diff --git a/apollo-router/src/plugins/telemetry/config.rs b/apollo-router/src/plugins/telemetry/config.rs index 08c2574d36d..fdd8c2003ca 100644 --- a/apollo-router/src/plugins/telemetry/config.rs +++ b/apollo-router/src/plugins/telemetry/config.rs @@ -85,8 +85,8 @@ pub(crate) struct MetricsCommon { pub(crate) service_name: Option, /// Set a service.namespace attribute in your metrics pub(crate) service_namespace: Option, - /// Otel configuration via resource - pub(crate) resources: BTreeMap, + /// The Open Telemetry resource + pub(crate) resource: BTreeMap, /// Custom buckets for histograms pub(crate) buckets: Vec, /// Experimental metrics to know more about caching strategies @@ -119,7 +119,7 @@ impl Default for MetricsCommon { attributes: Default::default(), service_name: None, service_namespace: None, - resources: BTreeMap::new(), + resource: BTreeMap::new(), buckets: vec![ 0.001, 0.005, 0.015, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1.0, 5.0, 10.0, ], @@ -362,8 +362,8 @@ pub(crate) struct Trace { pub(crate) max_attributes_per_event: u32, /// The maximum attributes per link before discarding pub(crate) max_attributes_per_link: u32, - /// The resources configured on the tracing pipeline - pub(crate) attributes: BTreeMap, + /// The Open Telemetry resource + pub(crate) resource: BTreeMap, } impl ConfigResource for Trace { @@ -374,7 +374,7 @@ impl ConfigResource for Trace { self.service_namespace.clone() } fn resource(&self) -> &BTreeMap { - &self.attributes + &self.resource } } @@ -386,7 +386,7 @@ impl ConfigResource for MetricsCommon { self.service_namespace.clone() } fn resource(&self) -> &BTreeMap { - &self.resources + &self.resource } } @@ -410,7 +410,7 @@ impl Default for Trace { max_links_per_span: default_max_links_per_span(), max_attributes_per_event: default_max_attributes_per_event(), max_attributes_per_link: default_max_attributes_per_link(), - attributes: Default::default(), + resource: Default::default(), } } } diff --git a/apollo-router/src/plugins/telemetry/metrics/mod.rs b/apollo-router/src/plugins/telemetry/metrics/mod.rs index 767bada8820..deadbee02c9 100644 --- a/apollo-router/src/plugins/telemetry/metrics/mod.rs +++ b/apollo-router/src/plugins/telemetry/metrics/mod.rs @@ -463,7 +463,7 @@ impl ResourceDetector for ConfigResourceDetector { ); resource = resource.merge(&mut Resource::new( self.0 - .resources + .resource .clone() .into_iter() .map(|(k, v)| KeyValue::new(k, v)), diff --git a/apollo-router/src/plugins/telemetry/testdata/config.router.yaml b/apollo-router/src/plugins/telemetry/testdata/config.router.yaml index f7c0bc55668..5b7485b4db3 100644 --- a/apollo-router/src/plugins/telemetry/testdata/config.router.yaml +++ b/apollo-router/src/plugins/telemetry/testdata/config.router.yaml @@ -2,7 +2,7 @@ telemetry: tracing: common: service_name: router - attributes: + resource: str: a int: 1 float: 1 diff --git a/docs/source/configuration/metrics.mdx b/docs/source/configuration/metrics.mdx index 4eec93aeacd..f9d207d625f 100644 --- a/docs/source/configuration/metrics.mdx +++ b/docs/source/configuration/metrics.mdx @@ -20,7 +20,7 @@ Service name discovery is handled in the following order: 1. `OTEL_SERVICE_NAME` env 2. `OTEL_RESOURCE_ATTRIBUTES` env 3. `router.yaml` `service_name` -4. `router.yaml` `resources` (attributes) +4. `router.yaml` `resource` If none of the above are found then the service name will be set to `unknown_service:apollo_router` or `unknown_service` if the executable name cannot be determined. @@ -30,9 +30,9 @@ A Resource is a set of key-value pairs that provide additional information to an ```yaml title="router.yaml" telemetry: - tracing: + metrics: common: - attributes: + resource: "environment.name": "production" "environment.namespace": "{env.MY_K8_NAMESPACE_ENV_VARIABLE}" ``` diff --git a/docs/source/configuration/tracing.mdx b/docs/source/configuration/tracing.mdx index c7a51479a70..0d0f2fc7586 100644 --- a/docs/source/configuration/tracing.mdx +++ b/docs/source/configuration/tracing.mdx @@ -38,7 +38,7 @@ Service name discovery is handled in the following order: 1. `OTEL_SERVICE_NAME` env 2. `OTEL_RESOURCE_ATTRIBUTES` env 3. `router.yaml` `service_name` -4. `router.yaml` `resources` (attributes) +4. `router.yaml` `resource` If none of the above are found then the service name will be set to `unknown_service:apollo_router` or `unknown_service` if the executable name cannot be determined. @@ -50,7 +50,7 @@ A Resource is a set of key-value pairs that provide additional global informatio telemetry: tracing: common: - attributes: + resource: "environment.name": "production" "environment.namespace": "{env.MY_K8_NAMESPACE_ENV_VARIABLE}" ```