Skip to content

Commit

Permalink
Bring otel resource into alignment
Browse files Browse the repository at this point in the history
Currently, we have telemetry.tracing.common.resources and telemetry.tracing.common.attributes.

These should be 'resource' to align with otel terminology.

Part of #4043
  • Loading branch information
bryn committed Oct 17, 2023
1 parent 4c76a1e commit 408982e
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 63 deletions.
26 changes: 23 additions & 3 deletions .changesets/config_bryn_telemetry_config_fixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -4426,8 +4426,8 @@ expression: "&schema"
},
"additionalProperties": false
},
"resources": {
"description": "Otel configuration via resource",
"resource": {
"description": "The Open Telemetry resource",
"default": {},
"type": "object",
"additionalProperties": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: apollo-router/src/configuration/tests.rs
expression: new_config
---
---
telemetry:
tracing:
common:
resource:
test: val

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: apollo-router/src/configuration/tests.rs
expression: new_config
---
---
telemetry:
metrics:
common:
resource:
test: val

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telemetry:
tracing:
common:
attributes:
test: val

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telemetry:
metrics:
common:
resources:
test: val

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ supergraph:
telemetry:
tracing:
common:
attributes:
resource:
foo: bar
max_attributes_per_event: 2
max_attributes_per_link: 3
Expand Down
16 changes: 8 additions & 8 deletions apollo-router/src/plugins/telemetry/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ pub(crate) struct MetricsCommon {
pub(crate) service_name: Option<String>,
/// Set a service.namespace attribute in your metrics
pub(crate) service_namespace: Option<String>,
/// Otel configuration via resource
pub(crate) resources: BTreeMap<String, AttributeValue>,
/// The Open Telemetry resource
pub(crate) resource: BTreeMap<String, AttributeValue>,
/// Custom buckets for histograms
pub(crate) buckets: Vec<f64>,
/// Experimental metrics to know more about caching strategies
Expand Down Expand Up @@ -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,
],
Expand Down Expand Up @@ -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<String, AttributeValue>,
/// The Open Telemetry resource
pub(crate) resource: BTreeMap<String, AttributeValue>,
}

impl ConfigResource for Trace {
Expand All @@ -374,7 +374,7 @@ impl ConfigResource for Trace {
self.service_namespace.clone()
}
fn resource(&self) -> &BTreeMap<String, AttributeValue> {
&self.attributes
&self.resource
}
}

Expand All @@ -386,7 +386,7 @@ impl ConfigResource for MetricsCommon {
self.service_namespace.clone()
}
fn resource(&self) -> &BTreeMap<String, AttributeValue> {
&self.resources
&self.resource
}
}

Expand All @@ -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(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/src/plugins/telemetry/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ telemetry:
tracing:
common:
service_name: router
attributes:
resource:
str: a
int: 1
float: 1
Expand Down
6 changes: 3 additions & 3 deletions docs/source/configuration/metrics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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}"
```
Expand Down
4 changes: 2 additions & 2 deletions docs/source/configuration/tracing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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}"
```
Expand Down

0 comments on commit 408982e

Please sign in to comment.