Skip to content

Commit

Permalink
Update Envelop Prom plugin
Browse files Browse the repository at this point in the history
ardatan committed Jan 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8672442 commit 0bf4661
Showing 4 changed files with 40 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-coats-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-yoga/plugin-prometheus': patch
---

Update Envelop plugin
2 changes: 1 addition & 1 deletion packages/plugins/prometheus/package.json
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@
"prom-client": "^15.0.0"
},
"dependencies": {
"@envelop/prometheus": "9.0.0"
"@envelop/prometheus": "^9.2.0"
},
"devDependencies": {
"prom-client": "15.0.0"
27 changes: 18 additions & 9 deletions packages/plugins/prometheus/src/index.ts
Original file line number Diff line number Diff line change
@@ -29,15 +29,21 @@ export function usePrometheus(options: PrometheusTracingPluginConfig): Plugin {

let httpHistogram: ReturnType<typeof createHistogram> | undefined;

function labelExists(label: string) {
if ((options.labels as Record<string, boolean>)?.[label] == null) {
return true;
}
return (options.labels as Record<string, boolean>)[label];
}

if (options.http) {
const labelNames = [
'url',
'method',
'statusCode',
'statusText',
'operationName',
'operationType',
];
const labelNames = ['url', 'method', 'statusCode', 'statusText'];
if (labelExists('operationName')) {
labelNames.push('operationName');
}
if (labelExists('operationType')) {
labelNames.push('operationType');
}
if (options.httpRequestHeaders) {
labelNames.push('requestHeaders');
}
@@ -62,9 +68,12 @@ export function usePrometheus(options: PrometheusTracingPluginConfig): Plugin {
statusCode: response.status,
statusText: response.statusText,
};
if (params?.operationType) {
if (labelExists('operationType') && params.operationType) {
labels.operationType = params.operationType;
}
if (labelExists('operationName')) {
labels.operationName = params.operationName || 'Anonymous';
}
if (options.httpRequestHeaders) {
labels.requestHeaders = JSON.stringify(
Object.fromEntries(request.headers.entries()),
21 changes: 16 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0bf4661

Please sign in to comment.