From 1d17cac46a1dcc2fad7a4f4210b77ecfd6b9fb09 Mon Sep 17 00:00:00 2001 From: scottmace Date: Wed, 13 Sep 2023 01:44:31 -0700 Subject: [PATCH] Add Support for AWS X-Ray Tracing Propagator (#3580) Adds support for the OpenTelemetry AWS X-Ray tracing [propagator](https://docs.rs/opentelemetry-aws/latest/opentelemetry_aws/). This propagator helps propagate tracing information from upstream services (such as AWS load balancers) to downstream services and handles conversion between the X-Ray trace id format and OpenTelemetry span contexts. --- .changesets/feat_sm_add_awsxray_propagator.md | 5 +++++ Cargo.lock | 11 +++++++++++ apollo-router/Cargo.toml | 1 + ...uter__configuration__tests__schema_generation.snap | 5 +++++ apollo-router/src/plugins/telemetry/config.rs | 2 ++ apollo-router/src/plugins/telemetry/mod.rs | 3 +++ docs/source/configuration/tracing.mdx | 3 +++ 7 files changed, 30 insertions(+) create mode 100644 .changesets/feat_sm_add_awsxray_propagator.md diff --git a/.changesets/feat_sm_add_awsxray_propagator.md b/.changesets/feat_sm_add_awsxray_propagator.md new file mode 100644 index 0000000000..9b1ff8b2e7 --- /dev/null +++ b/.changesets/feat_sm_add_awsxray_propagator.md @@ -0,0 +1,5 @@ +Adds support for the OpenTelemetry AWS X-Ray tracing propagator. + +This propagator helps propagate tracing information from upstream services (such as AWS load balancers) to downstream services and handles conversion between the X-Ray trace id format and OpenTelemetry span contexts. + +By [@scottmace](https://github.com/scottmace) in https://github.com/apollographql/router/pull/3580 diff --git a/Cargo.lock b/Cargo.lock index 9534fb8c42..ea6ea9f79a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,6 +332,7 @@ dependencies = [ "nu-ansi-term 0.49.0", "once_cell", "opentelemetry", + "opentelemetry-aws", "opentelemetry-datadog", "opentelemetry-http", "opentelemetry-jaeger", @@ -4080,6 +4081,16 @@ dependencies = [ "opentelemetry_sdk", ] +[[package]] +name = "opentelemetry-aws" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a394d24777936802edd6c03a68daab4db39630418c7e431a5648e9befa80b8" +dependencies = [ + "once_cell", + "opentelemetry", +] + [[package]] name = "opentelemetry-datadog" version = "0.7.0" diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 9635c4b9ed..5b40f382df 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -135,6 +135,7 @@ once_cell = "1.18.0" # there (and on `tracing` packages below) should be updated should this change. opentelemetry = { version = "0.19.0", features = ["rt-tokio", "metrics"] } opentelemetry_api = "0.19.0" +opentelemetry-aws = "0.7.0" opentelemetry-datadog = { version = "0.7.0", features = ["reqwest-client"] } opentelemetry-http = "0.8.0" opentelemetry-jaeger = { version = "0.18.0", features = [ 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 14ab198d54..f666bd1baf 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 @@ -4993,6 +4993,11 @@ expression: "&schema" "description": "Propagation configuration", "type": "object", "properties": { + "awsxray": { + "description": "Propagate AWS X-Ray", + "default": false, + "type": "boolean" + }, "baggage": { "description": "Propagate baggage https://www.w3.org/TR/baggage/", "default": false, diff --git a/apollo-router/src/plugins/telemetry/config.rs b/apollo-router/src/plugins/telemetry/config.rs index 7d9418dee6..fca3b8c9cf 100644 --- a/apollo-router/src/plugins/telemetry/config.rs +++ b/apollo-router/src/plugins/telemetry/config.rs @@ -337,6 +337,8 @@ pub(crate) struct Propagation { pub(crate) datadog: bool, /// Propagate Zipkin pub(crate) zipkin: bool, + /// Propagate AWS X-Ray + pub(crate) awsxray: bool, } #[derive(Clone, Debug, Deserialize, JsonSchema, Default)] diff --git a/apollo-router/src/plugins/telemetry/mod.rs b/apollo-router/src/plugins/telemetry/mod.rs index 67450787e9..1c792e3159 100644 --- a/apollo-router/src/plugins/telemetry/mod.rs +++ b/apollo-router/src/plugins/telemetry/mod.rs @@ -647,6 +647,9 @@ impl Telemetry { if propagation.datadog || tracing.datadog.is_some() { propagators.push(Box::::default()); } + if propagation.awsxray { + propagators.push(Box::::default()); + } if let Some(from_request_header) = &propagation.request.header_name { propagators.push(Box::new(CustomTraceIdPropagator::new( from_request_header.to_string(), diff --git a/docs/source/configuration/tracing.mdx b/docs/source/configuration/tracing.mdx index 26b294def7..b433e138b2 100644 --- a/docs/source/configuration/tracing.mdx +++ b/docs/source/configuration/tracing.mdx @@ -81,6 +81,9 @@ telemetry: # https://zipkin.io/ (compliant with opentracing) zipkin: false + # https://aws.amazon.com/xray/ (compliant with opentracing) + awsxray: false + # If you have your own way to generate a trace id and you want to pass it via a custom request header request: header_name: my-trace-id