From ee4ea21dfab9f7168cffe1a0c5ea523fe51c12aa Mon Sep 17 00:00:00 2001 From: Roger Coll Date: Fri, 23 Aug 2024 19:23:43 +0200 Subject: [PATCH 1/2] feat: decorate span names with url path --- .../otelcol-elastic-config-extras.yaml | 6 +++--- src/otelcollector/otelcol-elastic-config.yaml | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/otelcollector/otelcol-elastic-config-extras.yaml b/src/otelcollector/otelcol-elastic-config-extras.yaml index 530d47ad15..275146f136 100644 --- a/src/otelcollector/otelcol-elastic-config-extras.yaml +++ b/src/otelcollector/otelcol-elastic-config-extras.yaml @@ -10,13 +10,13 @@ service: pipelines: traces: receivers: [otlp] - processors: [batch] + processors: [batch,transform, resource] exporters: [spanmetrics, otlp/elastic] metrics: receivers: [otlp, spanmetrics] - processors: [batch] + processors: [batch, resource] exporters: [otlp/elastic] logs: receivers: [otlp] - processors: [batch] + processors: [batch, resource] exporters: [otlp/elastic] diff --git a/src/otelcollector/otelcol-elastic-config.yaml b/src/otelcollector/otelcol-elastic-config.yaml index 63ec2b97bd..2edc14bef0 100644 --- a/src/otelcollector/otelcol-elastic-config.yaml +++ b/src/otelcollector/otelcol-elastic-config.yaml @@ -2,7 +2,9 @@ receivers: otlp: protocols: grpc: + endpoint: ${env:OTEL_COLLECTOR_HOST}:${env:OTEL_COLLECTOR_PORT_GRPC} http: + endpoint: ${env:OTEL_COLLECTOR_HOST}:${env:OTEL_COLLECTOR_PORT_HTTP} cors: allowed_origins: - "http://*" @@ -13,6 +15,20 @@ exporters: processors: batch: + transform: + error_mode: ignore + trace_statements: + - context: span + conditions: + - IsString(attributes["http.url"]) + statements: + - merge_maps(attributes, URL(attributes["http.url"]), "upsert") + - set(name, attributes["url.path"]) + resource: + attributes: + - key: deployment.environment + value: "opentelemetry-demo" + action: upsert connectors: spanmetrics: From 6a62c0a200ec73b3840f6e38b89eeb2288f55819 Mon Sep 17 00:00:00 2001 From: Roger Coll Date: Fri, 23 Aug 2024 20:17:39 +0200 Subject: [PATCH 2/2] feat: set span name as shorten url path --- kubernetes/elastic-helm/configmap-deployment.yaml | 13 +++++++++++++ src/otelcollector/otelcol-elastic-config.yaml | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/kubernetes/elastic-helm/configmap-deployment.yaml b/kubernetes/elastic-helm/configmap-deployment.yaml index 742012f16c..5fff900ac6 100644 --- a/kubernetes/elastic-helm/configmap-deployment.yaml +++ b/kubernetes/elastic-helm/configmap-deployment.yaml @@ -21,6 +21,18 @@ data: extensions: processors: batch: {} + # Transforming span names for easier identification. See: https://github.com/open-telemetry/opentelemetry-demo/issues/1676 + transform: + error_mode: ignore + trace_statements: + - context: span + conditions: + - IsString(attributes["http.url"]) + statements: + - merge_maps(attributes, URL(attributes["http.url"]), "upsert") + # This pattern should correctly capture the first one or two segments of a URL and assign them to the short_url named group. + - merge_maps(attributes, ExtractPatterns(attributes["url.path"], "^(?P\\/[^\\/]+(\\/[^\\/]+)?)"), "upsert") + - set(name, attributes["short_url"]) resource: attributes: - key: deployment.environment @@ -70,6 +82,7 @@ data: - spanmetrics processors: - batch + - transform - resource receivers: - otlp diff --git a/src/otelcollector/otelcol-elastic-config.yaml b/src/otelcollector/otelcol-elastic-config.yaml index 2edc14bef0..2118a3cf9b 100644 --- a/src/otelcollector/otelcol-elastic-config.yaml +++ b/src/otelcollector/otelcol-elastic-config.yaml @@ -15,6 +15,7 @@ exporters: processors: batch: + # Transforming span names for easier identification. See: https://github.com/open-telemetry/opentelemetry-demo/issues/1676 transform: error_mode: ignore trace_statements: @@ -23,7 +24,9 @@ processors: - IsString(attributes["http.url"]) statements: - merge_maps(attributes, URL(attributes["http.url"]), "upsert") - - set(name, attributes["url.path"]) + # This pattern should correctly capture the first one or two segments of a URL and assign them to the short_url named group. + - merge_maps(attributes, ExtractPatterns(attributes["url.path"], "^(?P\\/[^\\/]+(\\/[^\\/]+)?)"), "upsert") + - set(name, attributes["short_url"]) resource: attributes: - key: deployment.environment