Skip to content

Commit

Permalink
Clarify usage of resource_to_telemetry_conversion (#6076)
Browse files Browse the repository at this point in the history
* Clarify usage of resource_to_telemetry_conversion

* Apply suggestions from code review

Co-authored-by: Clayton Cornell <[email protected]>

---------

Co-authored-by: Clayton Cornell <[email protected]>
  • Loading branch information
ptodev and clayton-cornell authored Jan 10, 2024
1 parent 38c8468 commit 7d987df
Showing 1 changed file with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ When `include_scope_labels` is `true` the `otel_scope_name` and

When `include_target_info` is true, OpenTelemetry Collector resources are converted into `target_info` metrics.

{{% admonition type="note" %}}

OTLP metrics can have a lot of resource attributes.
Setting `resource_to_telemetry_conversion` to `true` would convert all of them to Prometheus labels, which may not be what you want.
Instead of using `resource_to_telemetry_conversion`, most users need to use `otelcol.processor.transform`
to convert OTLP resource attributes to OTLP metric datapoint attributes before using `otelcol.exporter.prometheus`.
See [Creating Prometheus labels from OTLP resource attributes][] for an example.

[Creating Prometheus labels from OTLP resource attributes]: #creating-prometheus-labels-from-otlp-resource-attributes

{{% /admonition %}}

## Exported fields

The following fields are exported and can be referenced by other components:
Expand Down Expand Up @@ -87,6 +99,8 @@ information.

## Example

## Basic usage

This example accepts metrics over OTLP and forwards it using
`prometheus.remote_write`:

Expand All @@ -109,6 +123,54 @@ prometheus.remote_write "mimir" {
}
}
```

## Create Prometheus labels from OTLP resource attributes

This example uses `otelcol.processor.transform` to add extra `key1` and `key2` OTLP metric datapoint attributes from the
`key1` and `key2` OTLP resource attributes.

`otelcol.exporter.prometheus` then converts `key1` and `key2` to Prometheus labels along with any other OTLP metric datapoint attributes.

This avoids the need to set `resource_to_telemetry_conversion` to `true`,
which could have created too many unnecessary metric labels.

```river
otelcol.receiver.otlp "default" {
grpc {}
output {
metrics = [otelcol.processor.transform.default.input]
}
}
otelcol.processor.transform "default" {
error_mode = "ignore"
metric_statements {
context = "datapoint"
statements = [
`set(attributes["key1"], resource.attributes["key1"])`,
`set(attributes["key2"], resource.attributes["key2"])`,
]
}
output {
metrics = [otelcol.exporter.prometheus.default.input]
}
}
otelcol.exporter.prometheus "default" {
forward_to = [prometheus.remote_write.mimir.receiver]
}
prometheus.remote_write "mimir" {
endpoint {
url = "http://mimir:9009/api/v1/push"
}
}
```

<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components
Expand Down

0 comments on commit 7d987df

Please sign in to comment.