open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.73k stars 2.16k forks source link

[exporter/loki] Auto convert OpenTelemetry ResourceAttributes to log labels #19215

Open fkalinowski opened 1 year ago

fkalinowski commented 1 year ago

Component(s)

exporter/loki

Is your feature request related to a problem? Please describe.

The Resource Attributes are very interesting to use as labels in the log events.

With the current implementation, I need to declare an explicit mapping in my collector's configuration for each Resource Attribute. This approach requires to reconfigure my opentelemetry-collector each time an application introduces a new Resource Attribute (available in SemConv or not).

Moreover due to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/14113 I need to declare each ResourceAttribute twice - which can be tedious.

Describe the solution you'd like

Since Loki's backend is largely inspired by the Prometheus backend (Loki uses Mimir implementation of Prometheus compliant backend), that seems natural to apply the same constraint and have the same feature sets than exporter/prometheusremotewriteexporter.

That would be great if the feature resource_to_telemetry_conversion could be ported into the lokiexporter.

Describe alternatives you've considered

No response

Additional context

@gouthamve https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/14113#issuecomment-1456263808

github-actions[bot] commented 1 year ago

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

jpkrohling commented 1 year ago

cc @mar4uk

mar4uk commented 1 year ago

I think we can go for it. Adding resource_to_telemetry_conversion will also solve another issue https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/2290

So basically, if users trust their downstream configurations and keep the number of resource attributes minimal, we can allow users to promote that attributes to labels automatically. The fact that we have resource_to_telemetry_conversion for exporter/prometheusremotewriteexporter makes adding the same option to loki exporter nice to have.

We can add a warning to the description of this option in README: use with cautions since a high number of resource attributes can lead to high cardinality that will affect exploring such logs performance in Loki

@kovrus, @gouthamve

github-actions[bot] commented 1 year ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

mar4uk commented 1 year ago

let's keep this issue for a little bit longer

kago-dk commented 11 months ago

Were you still planning to implement resource_to_telemetry_conversion in the Loki Exporter?

mar4uk commented 11 months ago

Yes, it would be good to have

github-actions[bot] commented 9 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

mar4uk commented 9 months ago

still relevant

github-actions[bot] commented 7 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

sathieu commented 7 months ago

This issue is still relevant.

But another road will be possible in the next loki version: https://grafana.com/docs/loki/next/send-data/otel/

github-actions[bot] commented 5 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

jpkrohling commented 5 months ago

@sandeepsukhani, do we have a logic like that already on the Loki side?

sandeepsukhani commented 5 months ago

@sandeepsukhani, do we have a logic like that already on the Loki side?

Hey @jpkrohling, we have this logic documented. The code for converting otlp format to loki format can be found here.

jpkrohling commented 4 months ago

@mar4uk, do you think the logic can be reused?

mar4uk commented 4 months ago

I think so. The logic could be like this: if resource_to_telemetry_conversion is set to true then we convert the same list of resource attributes as the native Loki OTLP endpoint does https://grafana.com/docs/loki/next/send-data/otel/#format-considerations to labels:

All the rest resource attributes will be sent as structured metadata. Does it sound good?

jpkrohling commented 4 months ago

Yes, sounds good to me!

mhulscher commented 4 months ago

I found this issue because I am also looking to store attributes as structured metadata. After the seeing the (static) list of converted attributes I was a little skeptical of the proposed solution. However, the docs clearly mention that it will be possible to extend or even replace this list. That would be amazing!

Edit: for example, host.name is missing from the list. Which would be a useful label to have if you are collecting telemetry from a VM!

mk-raven commented 3 months ago

Also interesting about this issue. Any updates?

crutonjohn commented 2 months ago

this is a feature i'd like as well. been spending hours and hours trying to get otelcol to send "native" loki labels. a plug-and-play option would be awesome.

jpkrohling commented 2 months ago

@mhulscher , @mk-raven , @crutonjohn , given that Loki 3.0 supports OTLP natively, I'm interested in knowing whether you still see the need for the Loki exporter.

mk-raven commented 2 months ago

@jpkrohling hello! We needed this exporter because some service, use loki api for store telemetry data in Clickhouse DB. There are products like qryn, oteldb and other could integrate loki api for natively support logs querying in Grafana UI. Without manage custom plugins. Its great feature for many companies and teams.

jpkrohling commented 2 months ago

qryn, oteldb

A quick look into both makes me believe they support OTLP natively as well.

mk-raven commented 2 months ago

Its true, but Grafana UI doesn't support query in otlp format. Its has Clickhouse plugin, but for many people its hard to using. Better use natively LogQL, PromQL and TraceQL

jpkrohling commented 2 months ago

Better use natively LogQL, PromQL and TraceQL

Ingesting data in OTLP doesn't mean you have to query data in OTLP (even if there was one query language for OTLP). You should still be able to send data in via OTLP and query them via LogQL, as we do with Grafana Cloud :-)

mk-raven commented 2 months ago

But from otlp logs there no query filters in Grafana, if You use LogQL and Loki datasource.

jpkrohling commented 2 months ago

It's certainly possible to use LogQL to query a Loki data source containing logs that were ingested via OTLP.