Skip to content

Commit

Permalink
[opentelemetry-integration] Fix issue with usage of `spanMetrics.tran…
Browse files Browse the repository at this point in the history
…sformStatements` when `spanMetrics.dbMetrics` is enabled (#514)

Fixes ES-442.

This fixes a bug that would cause the generated Collector configuration to be broken when `spanMetrics.transformStatements` were set while `spanMetrics.dbMetrics` is enabled. 

I also updated the README slightly to make it clear why semantic convention transforms for DB spans have to go into `spanMetrics.transformStatements` instead of `spanMetrics.dbMetrics.transformStatements` while still adding a small example of `dbMetrics.transformStatements`.
  • Loading branch information
douglascamata authored Feb 18, 2025
1 parent 12b36cf commit c412a6f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.DS_Store
.idea
.vscode
Chart.lock
5 changes: 5 additions & 0 deletions otel-integration/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## OpenTelemtry-Integration

### v0.0.144 / 2025-02-18

- [Fix] `spanMetrics.transformStatements` are correctly created even when
`spanMetrics.dbMetrics` is not enabled.

### v0.0.143 / 2025-02-05

- [Feat] Add support for custom autoscaling mode alongside hpa mode
Expand Down
12 changes: 6 additions & 6 deletions otel-integration/k8s-helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: otel-integration
description: OpenTelemetry Integration
version: 0.0.143
version: 0.0.144
keywords:
- OpenTelemetry Collector
- OpenTelemetry Agent
Expand All @@ -11,27 +11,27 @@ keywords:
dependencies:
- name: opentelemetry-collector
alias: opentelemetry-agent
version: "0.106.2"
version: "0.106.3"
repository: https://cgx.jfrog.io/artifactory/coralogix-charts-virtual
condition: opentelemetry-agent.enabled
- name: opentelemetry-collector
alias: opentelemetry-agent-windows
version: "0.106.2"
version: "0.106.3"
repository: https://cgx.jfrog.io/artifactory/coralogix-charts-virtual
condition: opentelemetry-agent-windows.enabled
- name: opentelemetry-collector
alias: opentelemetry-cluster-collector
version: "0.106.2"
version: "0.106.3"
repository: https://cgx.jfrog.io/artifactory/coralogix-charts-virtual
condition: opentelemetry-cluster-collector.enabled
- name: opentelemetry-collector
alias: opentelemetry-receiver
version: "0.106.2"
version: "0.106.3"
repository: https://cgx.jfrog.io/artifactory/coralogix-charts-virtual
condition: opentelemetry-receiver.enabled
- name: opentelemetry-collector
alias: opentelemetry-gateway
version: "0.106.2"
version: "0.106.3"
repository: https://cgx.jfrog.io/artifactory/coralogix-charts-virtual
condition: opentelemetry-gateway.enabled
- name: coralogix-ebpf-agent
Expand Down
58 changes: 38 additions & 20 deletions otel-integration/k8s-helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,19 +584,19 @@ To do that, you can add the following configuration:
presets:
spanMetrics:
enabled: true
transformStatements:
- set(attributes["http.response.status_code"], attributes["http.status_code"]) where attributes["http.response.status_code"] == nil
transformStatements:
- set(attributes["http.response.status_code"], attributes["http.status_code"]) where attributes["http.response.status_code"] == nil
errorTracking:
enabled: true
```

#### SpanMetrics Database Monitoring

Once you enable the Span Metrics preset, the dbMetrics configuration will automatically be enabled. The DbMetrics option generates RED (Request, Errors, Duration) metrics for database spans. For example, query `db_calls_total` to view generated request metrics.
Once you enable the Span Metrics preset, the `dbMetrics`` configuration will automatically be enabled. It generates RED (Request, Errors, Duration) metrics for database spans. For example, query `db_calls_total` to view generated request metrics.

This is needed to enable the [Database Monitoring](https://coralogix.com/docs/user-guides/apm/features/database-monitoring/) feature inside Coralogix APM.

This is how you can disable the dbMetrics option:
This is how you can disable the `dbMetrics` option:

```yaml
presets:
Expand All @@ -606,7 +606,22 @@ presets:
enabled: false
```

Note: DbMetrics only works with OpenTelemetry SDKs that support OpenTelemetry Semantic conventions v1.26.0. If you are using older versions, you might need to transform some attributes, such as:
The `dbMetrics` also support transform statements that will apply only to database traces. Here's how you can use it:

```yaml
presets:
spanMetrics:
enabled: true
dbMetrics:
enabled: true
transformStatements:
- replace_pattern(attributes["db.query.text"], "\\d+", "?") # removes potential IDs for the attribute
- set(attributes["span.duration_ns"], span.end_time_unix_nano - span.start_time_unix_nano) # stores the span duration in ns in an attribute
```

##### Note on Semantic Conventions for old OTEL SDKs

The `dbMetrics` preset only works with OpenTelemetry SDKs that support OpenTelemetry Semantic conventions v1.26.0. If you are using older versions, you might need to transform some attributes, such as:

```
db.sql.table => db.collection.name
Expand All @@ -615,27 +630,30 @@ db.cosmosdb.container => db.collection.name
db.cassandra.table => db.collection.name
```

To do that, you can add the following configuration:
To do that, you can add the configuration below for transform statements that will apply to the `traces/db` and `traces` pipelines, ensuring that all the spans going through both pipelines will be on the same semantic convention.

> [!IMPORTANT]
> Correlation might be broken if the transform statements below are applied only at the `dbMetrics` level.

```yaml
spanMetrics:
enabled: false
transformStatements:
- set(attributes["db.namespace"], attributes["db.name"]) where attributes["db.namespace"] == nil
- set(attributes["db.namespace"], attributes["server.address"]) where attributes["db.namespace"] == nil
- set(attributes["db.namespace"], attributes["network.peer.name"]) where attributes["db.namespace"] == nil
- set(attributes["db.namespace"], attributes["net.peer.name"]) where attributes["db.namespace"] == nil
- set(attributes["db.namespace"], attributes["db.system"]) where attributes["db.namespace"] == nil
- set(attributes["db.operation.name"], attributes["db.operation"]) where attributes["db.operation.name"] == nil
- set(attributes["db.collection.name"], attributes["db.sql.table"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.cassandra.table"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.mongodb.collection"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.redis.database_index"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.elasticsearch.path_parts.index"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.cosmosdb.container"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["aws_dynamodb.table_names"]) where attributes["db.collection.name"] == nil
dbMetrics:
enabled: true
transformStatements:
- set(attributes["db.namespace"], attributes["db.name"]) where attributes["db.namespace"] == nil
- set(attributes["db.namespace"], attributes["server.address"]) where attributes["db.namespace"] == nil
- set(attributes["db.namespace"], attributes["network.peer.name"]) where attributes["db.namespace"] == nil
- set(attributes["db.namespace"], attributes["net.peer.name"]) where attributes["db.namespace"] == nil
- set(attributes["db.namespace"], attributes["db.system"]) where attributes["db.namespace"] == nil
- set(attributes["db.operation.name"], attributes["db.operation"]) where attributes["db.operation.name"] == nil
- set(attributes["db.collection.name"], attributes["db.sql.table"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.cassandra.table"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.mongodb.collection"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.redis.database_index"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.elasticsearch.path_parts.index"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["db.cosmosdb.container"]) where attributes["db.collection.name"] == nil
- set(attributes["db.collection.name"], attributes["aws_dynamodb.table_names"]) where attributes["db.collection.name"] == nil
```

#### Span metrics with different buckets per application
Expand Down
2 changes: 1 addition & 1 deletion otel-integration/k8s-helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ global:
defaultSubsystemName: "integration"
logLevel: "warn"
collectionInterval: "30s"
version: "0.0.143"
version: "0.0.144"

extensions:
kubernetesDashboard:
Expand Down

0 comments on commit c412a6f

Please sign in to comment.