Skip to content

Commit 0bf4661

Browse files
committed
Update Envelop Prom plugin
1 parent 8672442 commit 0bf4661

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

.changeset/shiny-coats-smile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-yoga/plugin-prometheus': patch
3+
---
4+
5+
Update Envelop plugin

packages/plugins/prometheus/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"prom-client": "^15.0.0"
4343
},
4444
"dependencies": {
45-
"@envelop/prometheus": "9.0.0"
45+
"@envelop/prometheus": "^9.2.0"
4646
},
4747
"devDependencies": {
4848
"prom-client": "15.0.0"

packages/plugins/prometheus/src/index.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ export function usePrometheus(options: PrometheusTracingPluginConfig): Plugin {
2929

3030
let httpHistogram: ReturnType<typeof createHistogram> | undefined;
3131

32+
function labelExists(label: string) {
33+
if ((options.labels as Record<string, boolean>)?.[label] == null) {
34+
return true;
35+
}
36+
return (options.labels as Record<string, boolean>)[label];
37+
}
38+
3239
if (options.http) {
33-
const labelNames = [
34-
'url',
35-
'method',
36-
'statusCode',
37-
'statusText',
38-
'operationName',
39-
'operationType',
40-
];
40+
const labelNames = ['url', 'method', 'statusCode', 'statusText'];
41+
if (labelExists('operationName')) {
42+
labelNames.push('operationName');
43+
}
44+
if (labelExists('operationType')) {
45+
labelNames.push('operationType');
46+
}
4147
if (options.httpRequestHeaders) {
4248
labelNames.push('requestHeaders');
4349
}
@@ -62,9 +68,12 @@ export function usePrometheus(options: PrometheusTracingPluginConfig): Plugin {
6268
statusCode: response.status,
6369
statusText: response.statusText,
6470
};
65-
if (params?.operationType) {
71+
if (labelExists('operationType') && params.operationType) {
6672
labels.operationType = params.operationType;
6773
}
74+
if (labelExists('operationName')) {
75+
labels.operationName = params.operationName || 'Anonymous';
76+
}
6877
if (options.httpRequestHeaders) {
6978
labels.requestHeaders = JSON.stringify(
7079
Object.fromEntries(request.headers.entries()),

pnpm-lock.yaml

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)