Skip to content

Commit 407437a

Browse files
committed
feat: add key level metrics and metric prefix
1 parent 6cbc64e commit 407437a

File tree

3 files changed

+465
-392
lines changed

3 files changed

+465
-392
lines changed

src/metrics.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@ const DEFAULT_BUCKETS: [f64; 11] = [
1414
pub struct ToolCallLabels {
1515
pub tool_name: String,
1616
pub status: String,
17+
pub api_key: String,
1718
}
1819

1920
#[derive(Clone, Hash, PartialEq, Eq, Debug, EncodeLabelSet)]
2021
pub struct ToolCallDurationLabels {
2122
pub tool_name: String,
23+
pub api_key: String,
2224
}
2325

2426
#[derive(Clone, Hash, PartialEq, Eq, Debug, EncodeLabelSet)]
2527
pub struct GatewayRequestLabels {
2628
pub endpoint_type: String,
2729
pub status: String,
30+
pub api_key: String,
2831
}
2932

3033
#[derive(Clone, Hash, PartialEq, Eq, Debug, EncodeLabelSet)]
3134
pub struct GatewayRequestDurationLabels {
3235
pub endpoint_type: String,
36+
pub api_key: String,
3337
}
3438

3539
#[derive(Clone)]
@@ -58,31 +62,31 @@ impl Metrics {
5862

5963
pub fn register(&self, registry: &mut Registry) {
6064
registry.register(
61-
"mcp_tool_calls",
65+
"subgraph_mcp_tool_calls",
6266
"Total number of MCP tool calls",
6367
self.mcp_tool_calls_total.clone(),
6468
);
6569

6670
registry.register(
67-
"mcp_tool_call_duration_seconds",
71+
"subgraph_mcp_tool_call_duration_seconds",
6872
"Duration of MCP tool calls in seconds",
6973
self.mcp_tool_call_duration_seconds.clone(),
7074
);
7175

7276
registry.register(
73-
"gateway_requests",
77+
"subgraph_mcp_gateway_requests",
7478
"Total number of requests to the Graph Gateway",
7579
self.gateway_requests_total.clone(),
7680
);
7781

7882
registry.register(
79-
"gateway_request_duration_seconds",
83+
"subgraph_mcp_gateway_request_duration_seconds",
8084
"Duration of Graph Gateway requests in seconds",
8185
self.gateway_request_duration_seconds.clone(),
8286
);
8387
}
8488

85-
pub async fn observe_tool_call<F, Fut, T>(&self, tool_name: &str, f: F) -> T
89+
pub async fn observe_tool_call<F, Fut, T>(&self, tool_name: &str, api_key: &str, f: F) -> T
8690
where
8791
F: FnOnce() -> Fut,
8892
Fut: std::future::Future<Output = T>,
@@ -102,19 +106,26 @@ impl Metrics {
102106
.get_or_create(&ToolCallLabels {
103107
tool_name: tool_name.to_string(),
104108
status: status.to_string(),
109+
api_key: api_key.to_string(),
105110
})
106111
.inc();
107112

108113
self.mcp_tool_call_duration_seconds
109114
.get_or_create(&ToolCallDurationLabels {
110115
tool_name: tool_name.to_string(),
116+
api_key: api_key.to_string(),
111117
})
112118
.observe(duration.as_secs_f64());
113119

114120
result
115121
}
116122

117-
pub async fn observe_gateway_request<F, Fut, T>(&self, endpoint_type: &str, f: F) -> T
123+
pub async fn observe_gateway_request<F, Fut, T>(
124+
&self,
125+
endpoint_type: &str,
126+
api_key: &str,
127+
f: F,
128+
) -> T
118129
where
119130
F: FnOnce() -> Fut,
120131
Fut: std::future::Future<Output = T>,
@@ -134,12 +145,14 @@ impl Metrics {
134145
.get_or_create(&GatewayRequestLabels {
135146
endpoint_type: endpoint_type.to_string(),
136147
status: status.to_string(),
148+
api_key: api_key.to_string(),
137149
})
138150
.inc();
139151

140152
self.gateway_request_duration_seconds
141153
.get_or_create(&GatewayRequestDurationLabels {
142154
endpoint_type: endpoint_type.to_string(),
155+
api_key: api_key.to_string(),
143156
})
144157
.observe(duration.as_secs_f64());
145158

0 commit comments

Comments
 (0)