Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: operationName issue when label is not present
Browse files Browse the repository at this point in the history
darren-west committed Feb 1, 2024
1 parent 266488a commit 0bf3d5b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/plugins/prometheus/src/index.ts
Original file line number Diff line number Diff line change
@@ -37,7 +37,14 @@ export function usePrometheus(options: PrometheusTracingPluginConfig): Plugin {
}

if (options.http) {
const labelNames = ['url', 'method', 'statusCode', 'statusText'];
const labelNames = ['method', 'statusCode'];

if (labelExists('url')) {
labelNames.push('url');
}
if (labelExists('statusText')) {
labelNames.push('statusText');
}
if (labelExists('operationName')) {
labelNames.push('operationName');
}
@@ -62,12 +69,15 @@ export function usePrometheus(options: PrometheusTracingPluginConfig): Plugin {
}),
fillLabelsFn(params, { request, response }) {
const labels: Record<string, string> = {
operationName: params.operationName || 'Anonymous',
url: request.url,
method: request.method,
statusCode: response.status,
statusText: response.statusText,
};
if (labelExists('url')) {
labels.url = request.url;
}
if (labelExists('statusText')) {
labels.statusText = request.statusText;
}
if (labelExists('operationType') && params.operationType) {
labels.operationType = params.operationType;
}

0 comments on commit 0bf3d5b

Please sign in to comment.