Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
20 changes: 20 additions & 0 deletions .changesets/config_http_client_header_telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Telemetry instrumentation config for http_client headers ([PR #8349](https://github.com/apollographql/router/pull/8349))

Adds a new telemetry instrumentation configuration for the http_client spans. This setting allows request headers added by Rhai scripts to be attached to the http_client span. The `some_rhai_response_header` value is available on the subgraph span as before.

```yaml
telemetry:
instrumentation:
spans:
mode: spec_compliant
subgraph:
attributes:
http.response.header.some_rhai_response_header:
subgraph_response_header: "some_rhai_response_header"
http_client:
attributes:
http.request.header.some_rhai_request_header:
request_header: "some_rhai_request_header"
```

By [@bonnici](https://github.com/bonnici) in https://github.com/apollographql/router/pull/8349
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,133 @@ expression: "&schema"
}
]
},
"ConditionHttpClientSelector": {
"description": "Specify a condition for when an [instrument][] should be mutated or an [event][] should be triggered.\n\n[instrument]: https://www.apollographql.com/docs/graphos/routing/observability/telemetry/instrumentation/instruments\n[event]: https://www.apollographql.com/docs/graphos/routing/observability/telemetry/instrumentation/events",
"oneOf": [
{
"additionalProperties": false,
"description": "A condition to check a selection against a value.",
"properties": {
"eq": {
"items": {
"$ref": "#/definitions/HttpClientSelectorOrValue"
},
"maxItems": 2,
"minItems": 2,
"type": "array"
}
},
"required": [
"eq"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "The first selection must be greater than the second selection.",
"properties": {
"gt": {
"items": {
"$ref": "#/definitions/HttpClientSelectorOrValue"
},
"maxItems": 2,
"minItems": 2,
"type": "array"
}
},
"required": [
"gt"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "The first selection must be less than the second selection.",
"properties": {
"lt": {
"items": {
"$ref": "#/definitions/HttpClientSelectorOrValue"
},
"maxItems": 2,
"minItems": 2,
"type": "array"
}
},
"required": [
"lt"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "A condition to check a selection against a selector.",
"properties": {
"exists": {
"$ref": "#/definitions/HttpClientSelector"
}
},
"required": [
"exists"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "All sub-conditions must be true.",
"properties": {
"all": {
"items": {
"$ref": "#/definitions/ConditionHttpClientSelector"
},
"type": "array"
}
},
"required": [
"all"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "At least one sub-conditions must be true.",
"properties": {
"any": {
"items": {
"$ref": "#/definitions/ConditionHttpClientSelector"
},
"type": "array"
}
},
"required": [
"any"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "The sub-condition must not be true",
"properties": {
"not": {
"$ref": "#/definitions/ConditionHttpClientSelector"
}
},
"required": [
"not"
],
"type": "object"
},
{
"const": "true",
"description": "Static true condition",
"type": "string"
},
{
"const": "false",
"description": "Static false condition",
"type": "string"
}
]
},
"ConditionRouterSelector": {
"description": "Specify a condition for when an [instrument][] should be mutated or an [event][] should be triggered.\n\n[instrument]: https://www.apollographql.com/docs/graphos/routing/observability/telemetry/instrumentation/instruments\n[event]: https://www.apollographql.com/docs/graphos/routing/observability/telemetry/instrumentation/events",
"oneOf": [
Expand Down Expand Up @@ -1553,6 +1680,21 @@ expression: "&schema"
}
]
},
"ConditionalHttpClientSelector": {
"anyOf": [
{
"$ref": "#/definitions/HttpClientSelector"
},
{
"properties": {
"condition": {
"$ref": "#/definitions/ConditionHttpClientSelector"
}
},
"type": "object"
}
]
},
"ConditionalRouterSelector": {
"anyOf": [
{
Expand Down Expand Up @@ -3751,6 +3893,12 @@ expression: "&schema"
},
"type": "object"
},
"ExtendedHttpClientAttributesWithConditionalHttpClientSelector": {
"additionalProperties": {
"$ref": "#/definitions/ConditionalHttpClientSelector"
},
"type": "object"
},
"ExtendedRouterAttributesWithConditionalRouterSelector": {
"additionalProperties": {
"$ref": "#/definitions/ConditionalRouterSelector"
Expand Down Expand Up @@ -5280,6 +5428,86 @@ expression: "&schema"
}
]
},
"HttpClientSelector": {
"anyOf": [
{
"additionalProperties": false,
"description": "A header from the HTTP request",
"properties": {
"default": {
"description": "Optional default value.",
"type": [
"string",
"null"
]
},
"request_header": {
"description": "The name of the request header.",
"type": "string"
}
},
"required": [
"request_header"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "A header from the HTTP response",
"properties": {
"default": {
"description": "Optional default value.",
"type": [
"string",
"null"
]
},
"response_header": {
"description": "The name of the response header.",
"type": "string"
}
},
"required": [
"response_header"
],
"type": "object"
}
]
},
"HttpClientSelectorOrValue": {
"anyOf": [
{
"allOf": [
{
"$ref": "#/definitions/AttributeValue"
}
],
"description": "A constant value."
},
{
"allOf": [
{
"$ref": "#/definitions/HttpClientSelector"
}
],
"description": "Selector to extract a value from the pipeline."
}
]
},
"HttpClientSpans": {
"additionalProperties": false,
"properties": {
"attributes": {
"allOf": [
{
"$ref": "#/definitions/ExtendedHttpClientAttributesWithConditionalHttpClientSelector"
}
],
"description": "Custom attributes that are attached to the HTTP client span."
}
},
"type": "object"
},
"HttpExporter": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -8279,6 +8507,14 @@ expression: "&schema"
],
"description": "The attributes to include by default in spans based on their level as specified in the otel semantic conventions and Apollo documentation."
},
"http_client": {
"allOf": [
{
"$ref": "#/definitions/HttpClientSpans"
}
],
"description": "Attributes to include on the HTTP client span.\nHTTP client spans contain information about HTTP requests made to subgraphs, including any changes made by Rhai scripts."
},
"mode": {
"allOf": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::fmt::Debug;

use opentelemetry::KeyValue;
use schemars::JsonSchema;
use serde::Deserialize;
use tower::BoxError;

use crate::Context;
use crate::plugins::telemetry::config_new::DefaultForLevel;
use crate::plugins::telemetry::config_new::Selectors;
use crate::plugins::telemetry::config_new::attributes::DefaultAttributeRequirementLevel;
use crate::plugins::telemetry::otlp::TelemetryDataKind;
use crate::services::http;

#[derive(Deserialize, JsonSchema, Clone, Default, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[serde(deny_unknown_fields, default)]
pub(crate) struct HttpClientAttributes {}

impl DefaultForLevel for HttpClientAttributes {
fn defaults_for_level(
&mut self,
_requirement_level: DefaultAttributeRequirementLevel,
_kind: TelemetryDataKind,
) {
}
}

impl Selectors<http::HttpRequest, http::HttpResponse, ()> for HttpClientAttributes {
fn on_request(&self, _request: &http::HttpRequest) -> Vec<KeyValue> {
Vec::new()
}

fn on_response(&self, _response: &http::HttpResponse) -> Vec<KeyValue> {
Vec::new()
}

fn on_error(&self, _error: &BoxError, _ctx: &Context) -> Vec<KeyValue> {
Vec::new()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub(crate) mod attributes;
pub(crate) mod selectors;
pub(crate) mod spans;
Loading