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

feat(telemetry): add description and units to standard instruments #5407

Merged
merged 5 commits into from
Jun 12, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Add description and units to standard instruments ([PR #5407](https://github.com/apollographql/router/pull/5407))

This PR adds description and units to standard instruments available in the router. These descriptions and units have been copy pasted directly from the [OpenTelemetry semantic conventions](https://opentelemetry.io/docs/specs/semconv/http/http-metrics/) and are needed for better integrations with APMs.

By [@bnjjj](https://github.com/bnjjj) in https://github.com/apollographql/router/pull/5407
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: apollo-router/src/plugins/telemetry/config_new/instruments.rs
description: Custom counter
description: error.type attribute
expression: "&metrics.all()"
info:
telemetry:
Expand All @@ -13,6 +13,8 @@ info:
error.type: true
---
- name: http.server.request.duration
description: Duration of HTTP server requests.
unit: s
data:
datapoints:
- sum: 0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ info:
on_graphql_error: true
---
- name: http.server.request.duration
description: Duration of HTTP server requests.
unit: s
data:
datapoints:
- sum: 0.1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: apollo-router/src/plugins/telemetry/config_new/instruments.rs
description: Test standard router metrics
description: Active requests metrics
expression: "&metrics.all()"
info:
telemetry:
Expand All @@ -9,8 +9,12 @@ info:
router:
http.server.active_requests: true
http.server.request.duration: false
subgraph:
http.client.request.duration: false
---
- name: http.server.active_requests
description: Number of active HTTP server requests.
unit: request
data:
datapoints:
- value: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: apollo-router/src/plugins/telemetry/config_new/instruments.rs
description: Test server request body size metrics
description: Server request body size metrics
expression: "&metrics.all()"
info:
telemetry:
Expand All @@ -12,6 +12,8 @@ info:
http.server.request.body.size: true
---
- name: http.server.request.body.size
description: Size of HTTP server request bodies.
unit: By
data:
datapoints:
- sum: 35
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: apollo-router/src/plugins/telemetry/config_new/instruments.rs
description: Test server request body size metrics
description: Server request body size metrics
expression: "&metrics.all()"
info:
telemetry:
Expand All @@ -12,6 +12,8 @@ info:
http.server.request.body.size: true
---
- name: http.server.request.body.size
description: Size of HTTP server request bodies.
unit: By
data:
datapoints:
- sum: 35
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ info:
http.server.request.duration: true
---
- name: http.server.request.duration
description: Duration of HTTP server requests.
unit: s
data:
datapoints:
- sum: 0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ info:
request_method: true
---
- name: http.server.request.duration
description: Duration of HTTP server requests.
unit: s
data:
datapoints:
- sum: 0.1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: apollo-router/src/plugins/telemetry/config_new/instruments.rs
description: Test server request body size metrics
description: Server request body size metrics
expression: "&metrics.all()"
info:
telemetry:
Expand All @@ -12,6 +12,8 @@ info:
http.server.response.body.size: true
---
- name: http.server.response.body.size
description: Size of HTTP server response bodies.
unit: By
data:
datapoints:
- sum: 35
Expand Down
93 changes: 61 additions & 32 deletions apollo-router/src/plugins/telemetry/config_new/instruments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ impl InstrumentsConfig {
inner: Mutex::new(CustomHistogramInner {
increment: Increment::Duration(Instant::now()),
condition: Condition::True,
histogram: Some(meter.f64_histogram("http.server.request.duration").init()),
histogram: Some(
meter
.f64_histogram("http.server.request.duration")
.with_unit(Unit::new("s"))
.with_description("Duration of HTTP server requests.")
.init(),
),
attributes: Vec::new(),
selector: None,
selectors: match &self.router.attributes.http_server_request_duration {
Expand Down Expand Up @@ -126,7 +132,11 @@ impl InstrumentsConfig {
increment: Increment::Custom(None),
condition: Condition::True,
histogram: Some(
meter.f64_histogram("http.server.request.body.size").init(),
meter
.f64_histogram("http.server.request.body.size")
.with_unit(Unit::new("By"))
.with_description("Size of HTTP server request bodies.")
.init(),
),
attributes: Vec::with_capacity(nb_attributes),
selector: Some(Arc::new(RouterSelector::RequestHeader {
Expand Down Expand Up @@ -160,7 +170,11 @@ impl InstrumentsConfig {
increment: Increment::Custom(None),
condition: Condition::True,
histogram: Some(
meter.f64_histogram("http.server.response.body.size").init(),
meter
.f64_histogram("http.server.response.body.size")
.with_unit(Unit::new("By"))
.with_description("Size of HTTP server response bodies.")
.init(),
),
attributes: Vec::with_capacity(nb_attributes),
selector: Some(Arc::new(RouterSelector::ResponseHeader {
Expand All @@ -183,6 +197,8 @@ impl InstrumentsConfig {
counter: Some(
meter
.i64_up_down_counter("http.server.active_requests")
.with_unit(Unit::new("request"))
.with_description("Number of active HTTP server requests.")
.init(),
),
attrs_config: match &self.router.attributes.http_server_active_requests {
Expand Down Expand Up @@ -213,34 +229,39 @@ impl InstrumentsConfig {

pub(crate) fn new_subgraph_instruments(&self) -> SubgraphInstruments {
let meter = metrics::meter_provider().meter(METER_NAME);
let http_client_request_duration = self
.subgraph
.attributes
.http_client_request_duration
.is_enabled()
.then(|| {
let mut nb_attributes = 0;
let selectors = match &self.subgraph.attributes.http_client_request_duration {
DefaultedStandardInstrument::Bool(_) | DefaultedStandardInstrument::Unset => {
None
}
DefaultedStandardInstrument::Extendable { attributes } => {
nb_attributes = attributes.custom.len();
Some(attributes.clone())
let http_client_request_duration =
self.subgraph
.attributes
.http_client_request_duration
.is_enabled()
.then(|| {
let mut nb_attributes = 0;
let selectors = match &self.subgraph.attributes.http_client_request_duration {
DefaultedStandardInstrument::Bool(_)
| DefaultedStandardInstrument::Unset => None,
DefaultedStandardInstrument::Extendable { attributes } => {
nb_attributes = attributes.custom.len();
Some(attributes.clone())
}
};
CustomHistogram {
inner: Mutex::new(CustomHistogramInner {
increment: Increment::Duration(Instant::now()),
condition: Condition::True,
histogram: Some(
meter
.f64_histogram("http.client.request.duration")
.with_unit(Unit::new("s"))
.with_description("Duration of HTTP client requests.")
.init(),
),
attributes: Vec::with_capacity(nb_attributes),
selector: None,
selectors,
updated: false,
}),
}
};
CustomHistogram {
inner: Mutex::new(CustomHistogramInner {
increment: Increment::Duration(Instant::now()),
condition: Condition::True,
histogram: Some(meter.f64_histogram("http.client.request.duration").init()),
attributes: Vec::with_capacity(nb_attributes),
selector: None,
selectors,
updated: false,
}),
}
});
});
let http_client_request_body_size =
self.subgraph
.attributes
Expand All @@ -261,7 +282,11 @@ impl InstrumentsConfig {
increment: Increment::Custom(None),
condition: Condition::True,
histogram: Some(
meter.f64_histogram("http.client.request.body.size").init(),
meter
.f64_histogram("http.client.request.body.size")
.with_unit(Unit::new("By"))
.with_description("Size of HTTP client request bodies.")
.init(),
),
attributes: Vec::with_capacity(nb_attributes),
selector: Some(Arc::new(SubgraphSelector::SubgraphRequestHeader {
Expand Down Expand Up @@ -294,7 +319,11 @@ impl InstrumentsConfig {
increment: Increment::Custom(None),
condition: Condition::True,
histogram: Some(
meter.f64_histogram("http.client.response.body.size").init(),
meter
.f64_histogram("http.client.response.body.size")
.with_unit(Unit::new("By"))
.with_description("Size of HTTP client response bodies.")
.init(),
),
attributes: Vec::with_capacity(nb_attributes),
selector: Some(Arc::new(SubgraphSelector::SubgraphResponseHeader {
Expand Down
Loading