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

fix(telemetry): rename the selector to get studio operation id #5337

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions .changesets/config_bnjjj_fix_studio_selector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### Rename the telemetry selector to get studio operation id ([PR #5337](https://github.com/apollographql/router/pull/5337))

We introduced a new `trace_id` selector format in `1.48.0` which has been misnamed because it's not a trace id but the Apollo Studio Operation ID. If you want to access to this selector, here is an example:

```yaml
telemetry:
instrumentation:
spans:
router:
"studio.operation.id":
studio_operation_id: true
```

By [@bnjjj](https://github.com/bnjjj) in https://github.com/apollographql/router/pull/5337
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: apollo-router/src/configuration/tests.rs
assertion_line: 26
expression: "&schema"
---
{
Expand Down Expand Up @@ -5028,6 +5029,20 @@ expression: "&schema"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "Apollo Studio operation id",
"properties": {
"studio_operation_id": {
"description": "Apollo Studio operation id",
"type": "boolean"
}
},
"required": [
"studio_operation_id"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "A value from context.",
Expand Down Expand Up @@ -6882,13 +6897,6 @@ expression: "&schema"
"datadog"
],
"type": "string"
},
{
"description": "Apollo Studio trace id",
"enum": [
"apollo"
],
"type": "string"
}
]
},
Expand Down
52 changes: 21 additions & 31 deletions apollo-router/src/plugins/telemetry/config_new/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ pub(crate) enum TraceIdFormat {
OpenTelemetry,
/// Datadog trace ID, a u64.
Datadog,
/// Apollo Studio trace id
Apollo,
}

#[derive(Deserialize, JsonSchema, Clone, Debug)]
Expand Down Expand Up @@ -127,6 +125,11 @@ pub(crate) enum RouterSelector {
/// The format of the trace ID.
trace_id: TraceIdFormat,
},
/// Apollo Studio operation id
StudioOperationId {
/// Apollo Studio operation id
studio_operation_id: bool,
},
/// A value from context.
ResponseContext {
/// The response context key.
Expand Down Expand Up @@ -566,20 +569,13 @@ impl Selector for RouterSelector {
.map(opentelemetry::Value::from),
RouterSelector::TraceId {
trace_id: trace_id_format,
} => {
if let TraceIdFormat::Apollo = &trace_id_format {
return None;
} => trace_id().map(|id| {
match trace_id_format {
TraceIdFormat::OpenTelemetry => id.to_string(),
TraceIdFormat::Datadog => id.to_datadog(),
}
trace_id().map(|id| {
match trace_id_format {
TraceIdFormat::OpenTelemetry => id.to_string(),
TraceIdFormat::Datadog => id.to_datadog(),
// It happens in the response
TraceIdFormat::Apollo => String::new(),
}
.into()
})
}
.into()
}),
RouterSelector::Baggage {
baggage, default, ..
} => get_baggage(baggage).or_else(|| default.maybe_to_otel_value()),
Expand Down Expand Up @@ -636,20 +632,14 @@ impl Selector for RouterSelector {
}
RouterSelector::Static(val) => Some(val.clone().into()),
RouterSelector::StaticField { r#static } => Some(r#static.clone().into()),
RouterSelector::TraceId {
trace_id: trace_id_format,
} => {
if let TraceIdFormat::Apollo = &trace_id_format {
response
.context
.get::<_, String>(APOLLO_OPERATION_ID)
.ok()
.flatten()
.map(opentelemetry::Value::from)
} else {
None
}
}
RouterSelector::StudioOperationId {
studio_operation_id,
} if *studio_operation_id => response
.context
.get::<_, String>(APOLLO_OPERATION_ID)
.ok()
.flatten()
.map(opentelemetry::Value::from),
_ => None,
}
}
Expand Down Expand Up @@ -2016,8 +2006,8 @@ mod test {

#[test]
fn test_router_studio_trace_id() {
let selector = RouterSelector::TraceId {
trace_id: TraceIdFormat::Apollo,
let selector = RouterSelector::StudioOperationId {
studio_operation_id: true,
};
let ctx = crate::Context::new();
let _ = ctx.insert(APOLLO_OPERATION_ID, "42".to_string()).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ The router service is the initial entrypoint for all requests. It is HTTP centri

| Selector | Defaultable | Values | Description |
|--------------------|-------------|-------------------------------------------|--------------------------------------|
| `trace_id` | Yes | `open_telemetry`\|`datadog`\|`apollo` | The trace ID |
| `trace_id` | Yes | `open_telemetry`\|`datadog`\ | The trace ID |
bnjjj marked this conversation as resolved.
Show resolved Hide resolved
| `studio_operation_id` | Yes | `true`|`false` | The Apollo Studio operation id |
| `request_header` | Yes | | The name of the request header |
| `response_header` | Yes | | The name of a response header |
| `response_status` | Yes | `code`\|`reason` | The response status |
Expand Down
Loading