From 0fcacff3f64e347e2b7076f74532683bea45169d Mon Sep 17 00:00:00 2001 From: Bram Schuur Date: Wed, 28 Oct 2026 15:01:10 +0100 Subject: [PATCH] fix(open-telemetry): build monitor URNs with a CEL urnTemplate instead of label_replace --- .../service-instance-span-duration/monitor.sty | 10 ++++------ .../service-instance-span-error-ratio/monitor.sty | 7 ++----- .../monitors/service-span-duration/monitor.sty | 10 ++++------ .../monitors/service-span-error-ratio/monitor.sty | 7 ++----- stackpacks/open-telemetry/stackpack.yaml | 2 +- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/stackpacks/open-telemetry/settings/monitors/service-instance-span-duration/monitor.sty b/stackpacks/open-telemetry/settings/monitors/service-instance-span-duration/monitor.sty index 4fe5686..bebda94 100644 --- a/stackpacks/open-telemetry/settings/monitors/service-instance-span-duration/monitor.sty +++ b/stackpacks/open-telemetry/settings/monitors/service-instance-span-duration/monitor.sty @@ -6,18 +6,16 @@ nodes: metric: # _seconds_ = telemetry gateway (target/new spanmetrics default); _milliseconds_ = standalone collector (current spanmetrics default, transitioning to s per OTel semantic conventions) query: |- - label_replace( - (histogram_quantile(0.95, sum by(service_namespace, service_name, service_instance_id, le)(rate(otel_span_duration_seconds_bucket{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m])))) - or - (histogram_quantile(0.95, sum by(service_namespace, service_name, service_instance_id, le)(rate(otel_span_duration_milliseconds_bucket{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]))) / 1000) - , "service_urn_prefix", "urn:opentelemetry:namespace/$1:service/", "service_namespace", "(.*)") + (histogram_quantile(0.95, sum by(service_namespace, service_name, service_instance_id, le)(rate(otel_span_duration_seconds_bucket{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m])))) + or + (histogram_quantile(0.95, sum by(service_namespace, service_name, service_instance_id, le)(rate(otel_span_duration_milliseconds_bucket{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]))) / 1000) aliasTemplate: Span duration 95th percentile unit: s threshold: 5 titleTemplate: Span duration # OTel: service.namespace is optional and an unset namespace is itself a valid namespace, encoded here as the empty string. # service.instance.id is unique only within its (service.namespace, service.name) pair: https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/ - urnTemplate: "${service_urn_prefix}${service_name}:serviceInstance/${service_instance_id}" + urnTemplate: "urn:opentelemetry:namespace/${'service_namespace' in labels ? labels.service_namespace : ''}:service/${service_name}:serviceInstance/${service_instance_id}" description: | Monitors the duration of the server and consumer spans. When the 95th percentile of the duration is greater than the threshold (default 5s) the monitor has a Deviating state. function: urn:stackpack:common:monitor-function:threshold diff --git a/stackpacks/open-telemetry/settings/monitors/service-instance-span-error-ratio/monitor.sty b/stackpacks/open-telemetry/settings/monitors/service-instance-span-error-ratio/monitor.sty index cf95ae6..c271e05 100644 --- a/stackpacks/open-telemetry/settings/monitors/service-instance-span-error-ratio/monitor.sty +++ b/stackpacks/open-telemetry/settings/monitors/service-instance-span-error-ratio/monitor.sty @@ -4,17 +4,14 @@ nodes: comparator: GT failureState: DEVIATING metric: - query: |- - label_replace( - sum by(service_namespace, service_name, service_instance_id)(rate(otel_span_calls_total{status_code="STATUS_CODE_ERROR", span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]) or (present_over_time(otel_span_calls_total{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]) -1)) / sum by(service_namespace, service_name, service_instance_id)(rate(otel_span_calls_total{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m])) * 100 - , "service_urn_prefix", "urn:opentelemetry:namespace/$1:service/", "service_namespace", "(.*)") + query: 'sum by(service_namespace, service_name, service_instance_id)(rate(otel_span_calls_total{status_code="STATUS_CODE_ERROR", span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]) or (present_over_time(otel_span_calls_total{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]) -1)) / sum by(service_namespace, service_name, service_instance_id)(rate(otel_span_calls_total{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m])) * 100' aliasTemplate: Error ratio (errors/total) unit: percent threshold: 5 titleTemplate: Span error ratio # OTel: service.namespace is optional and an unset namespace is itself a valid namespace, encoded here as the empty string. # service.instance.id is unique only within its (service.namespace, service.name) pair: https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/ - urnTemplate: "${service_urn_prefix}${service_name}:serviceInstance/${service_instance_id}" + urnTemplate: "urn:opentelemetry:namespace/${'service_namespace' in labels ? labels.service_namespace : ''}:service/${service_name}:serviceInstance/${service_instance_id}" description: | Percentage of server and consumer spans that are in an error state for the service instance. function: urn:stackpack:common:monitor-function:threshold diff --git a/stackpacks/open-telemetry/settings/monitors/service-span-duration/monitor.sty b/stackpacks/open-telemetry/settings/monitors/service-span-duration/monitor.sty index 0b5fd51..d3a2423 100644 --- a/stackpacks/open-telemetry/settings/monitors/service-span-duration/monitor.sty +++ b/stackpacks/open-telemetry/settings/monitors/service-span-duration/monitor.sty @@ -6,18 +6,16 @@ nodes: metric: # _seconds_ = telemetry gateway (target/new spanmetrics default); _milliseconds_ = standalone collector (current spanmetrics default, transitioning to s per OTel semantic conventions) query: |- - label_replace( - (histogram_quantile(0.95, sum by(service_namespace, service_name, le)(rate(otel_span_duration_seconds_bucket{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m])))) - or - (histogram_quantile(0.95, sum by(service_namespace, service_name, le)(rate(otel_span_duration_milliseconds_bucket{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]))) / 1000) - , "service_urn_prefix", "urn:opentelemetry:namespace/$1:service/", "service_namespace", "(.*)") + (histogram_quantile(0.95, sum by(service_namespace, service_name, le)(rate(otel_span_duration_seconds_bucket{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m])))) + or + (histogram_quantile(0.95, sum by(service_namespace, service_name, le)(rate(otel_span_duration_milliseconds_bucket{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]))) / 1000) aliasTemplate: Span duration 95th percentile unit: s threshold: 5 titleTemplate: Span duration # OTel: service.namespace is optional and an unset namespace is itself a valid namespace, encoded here as the empty string. # service.instance.id is unique only within its (service.namespace, service.name) pair: https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/ - urnTemplate: "${service_urn_prefix}${service_name}" + urnTemplate: "urn:opentelemetry:namespace/${'service_namespace' in labels ? labels.service_namespace : ''}:service/${service_name}" description: | Monitors the duration of the server and consumer spans. When the 95th percentile of the duration is greater than the threshold (default 5s) the monitor has a Deviating state. function: urn:stackpack:common:monitor-function:threshold diff --git a/stackpacks/open-telemetry/settings/monitors/service-span-error-ratio/monitor.sty b/stackpacks/open-telemetry/settings/monitors/service-span-error-ratio/monitor.sty index 1b42c31..30f6ec4 100644 --- a/stackpacks/open-telemetry/settings/monitors/service-span-error-ratio/monitor.sty +++ b/stackpacks/open-telemetry/settings/monitors/service-span-error-ratio/monitor.sty @@ -4,17 +4,14 @@ nodes: comparator: GT failureState: DEVIATING metric: - query: |- - label_replace( - sum by(service_namespace, service_name)(rate(otel_span_calls_total{status_code="STATUS_CODE_ERROR", span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]) or (present_over_time(otel_span_calls_total{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]) -1)) / sum by(service_namespace, service_name)(rate(otel_span_calls_total{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m])) * 100 - , "service_urn_prefix", "urn:opentelemetry:namespace/$1:service/", "service_namespace", "(.*)") + query: 'sum by(service_namespace, service_name)(rate(otel_span_calls_total{status_code="STATUS_CODE_ERROR", span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]) or (present_over_time(otel_span_calls_total{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m]) -1)) / sum by(service_namespace, service_name)(rate(otel_span_calls_total{span_kind=~"SPAN_KIND_SERVER|SPAN_KIND_CONSUMER"}[5m])) * 100' aliasTemplate: Error ratio (errors/total) unit: percent threshold: 5 titleTemplate: Span error ratio # OTel: service.namespace is optional and an unset namespace is itself a valid namespace, encoded here as the empty string. # service.instance.id is unique only within its (service.namespace, service.name) pair: https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/ - urnTemplate: "${service_urn_prefix}${service_name}" + urnTemplate: "urn:opentelemetry:namespace/${'service_namespace' in labels ? labels.service_namespace : ''}:service/${service_name}" description: | Percentage of server and consumer spans that are in an error state for the service. function: urn:stackpack:common:monitor-function:threshold diff --git a/stackpacks/open-telemetry/stackpack.yaml b/stackpacks/open-telemetry/stackpack.yaml index fde883a..b34b7b9 100644 --- a/stackpacks/open-telemetry/stackpack.yaml +++ b/stackpacks/open-telemetry/stackpack.yaml @@ -1,5 +1,5 @@ name: "open-telemetry" -version: "0.1.6" +version: "0.1.7" schemaVersion: "2.0" displayName: "Open Telemetry" categories: [ "Open Telemetry" ]