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

Per-operation and client error metric #6443

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion apollo-router/src/plugins/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub(crate) mod utils;

// Tracing consts
pub(crate) const CLIENT_NAME: &str = "apollo_telemetry::client_name";
const CLIENT_VERSION: &str = "apollo_telemetry::client_version";
pub(crate) const CLIENT_VERSION: &str = "apollo_telemetry::client_version";
const SUBGRAPH_FTV1: &str = "apollo_telemetry::subgraph_ftv1";
pub(crate) const STUDIO_EXCLUDE: &str = "apollo_telemetry::studio::exclude";
pub(crate) const SUPERGRAPH_SCHEMA_ID_CONTEXT_KEY: &str = "apollo::supergraph_schema_id";
Expand Down
45 changes: 45 additions & 0 deletions apollo-router/src/services/router/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ use crate::cache::DeduplicatingCache;
use crate::configuration::Batching;
use crate::configuration::BatchingMode;
use crate::context::CONTAINS_GRAPHQL_ERROR;
use crate::context::OPERATION_KIND;
use crate::context::OPERATION_NAME;
use crate::plugins::telemetry::CLIENT_NAME;
use crate::plugins::telemetry::CLIENT_VERSION;
use crate::query_planner::APOLLO_OPERATION_ID;
use crate::graphql;
use crate::http_ext;
#[cfg(test)]
Expand Down Expand Up @@ -304,6 +309,21 @@ impl RouterService {
Self::count_errors(&response.errors);
}

if let Some(path) = response.path.clone() {
println!("response path: {}", path);
}

let operation_id: String = context.get::<_, String>(APOLLO_OPERATION_ID).unwrap_or_default().unwrap_or_default();
let operation_kind = context.get::<_, String>(OPERATION_KIND).unwrap_or_default().unwrap_or_default();
let operation_name = context.get::<_, String>(OPERATION_NAME).unwrap_or_default().unwrap_or_default();
let client_name = context.get::<_, String>(CLIENT_NAME).unwrap_or_default().unwrap_or_default();
let client_version = context.get::<_, String>(CLIENT_VERSION).unwrap_or_default().unwrap_or_default();
println!("operation_id: {}", operation_id);
println!("operation_kind: {}", operation_kind);
println!("operation_name: {}", operation_name);
println!("client_name: {}", client_name);
println!("client_version: {}", client_version);

parts
.headers
.insert(CONTENT_TYPE, APPLICATION_JSON_HEADER_VALUE.clone());
Expand Down Expand Up @@ -778,6 +798,31 @@ impl RouterService {
let code = error.extensions.get("code").and_then(|c| c.as_str());
let entry = map.entry(code).or_insert(0u64);
*entry += 1;

let temp_code = code.unwrap_or_default().to_string();
let temp_service = error.extensions.get("service").and_then(|s| s.as_str())
.unwrap_or_default().to_string();
let temp_path = match &error.path {
None => "".into(),
Some(path) => path.to_string()
};
println!("temp_code: {temp_code}");
println!("temp_path: {temp_path}");
println!("temp_service: {temp_service}");

u64_counter!(
"temp.nick.apollo.router.operations.error",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 Cool to see a PoC in under 50 lines.

"Temp metric",
1,
"apollo.operation.id" = "todo",
"apollo.operation.name" = "todo",
"apollo.client.name" = "todo",
"apollo.client.version" = "todo",
"graphql.error.extensions.code" = temp_code,
"graphql.error.path" = temp_path,
"apollo.router.error.source" = temp_service,
"apollo.router.error.coordinate" = "todo"
);
}

for (code, count) in map {
Expand Down