Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of prometheus exporter to apply resource attributes as labels #4732

Closed
codeboten opened this issue Nov 27, 2023 · 3 comments · Fixed by #4733
Closed

Allow configuration of prometheus exporter to apply resource attributes as labels #4732

codeboten opened this issue Nov 27, 2023 · 3 comments · Fixed by #4733
Assignees
Labels
enhancement New feature or request pkg:exporter:prometheus Related to the Prometheus exporter package

Comments

@codeboten
Copy link
Contributor

Problem Statement

To ensure backwards compatibility with OpenCensus generated metrics, the OpenTelemetry collector needs to be able to apply resource attributes as labels on every metric emitted by the Prometheus exporter.

Additional Context

This is related to open-telemetry/opentelemetry-specification#3761
Collector issue capturing additional details open-telemetry/opentelemetry-collector#7454

@codeboten codeboten added the enhancement New feature or request label Nov 27, 2023
@pellared pellared added the pkg:exporter:prometheus Related to the Prometheus exporter package label Nov 28, 2023
@codeboten
Copy link
Contributor Author

i'm happy to take this on with some guidance 😬

@dashpole
Copy link
Contributor

It would be nice for the Option to take a Filter so that it can be used with NewAllowKeysFilter and NewDenyKeysFilter, or a custom (e.g. regex) function.

The option name could be something like WithResourceAsConstantLabels(Filter) (opinions welcome).

You should cache the constant labels generated by the filter, similar to how we cache targetInfo.

constant labels then need to be plumbed to each addFooMetric function, and appended to the existing attributes, e.g. here:

keys, values := getAttrs(dp.Attributes, ks, vs)

I'm happy to help however I can!

@codeboten
Copy link
Contributor Author

@dashpole @MadVikingGod here's a first look at what i'm thinking based on your guidance, PTAL: #4733

codeboten pushed a commit to codeboten/opentelemetry-go that referenced this issue Nov 29, 2023
This PR adds the `WithResourceAsConstantLabels` option to the Prometheus exporter to allow users to configure resource attributes to be applied on every metric.

Fixes open-telemetry#4732

Signed-off-by: Alex Boten <aboten@lightstep.com>
codeboten pushed a commit to codeboten/opentelemetry-go that referenced this issue Nov 29, 2023
This PR adds the `WithResourceAsConstantLabels` option to the Prometheus exporter to allow users to configure resource attributes to be applied on every metric.

Fixes open-telemetry#4732

Signed-off-by: Alex Boten <aboten@lightstep.com>
MrAlias added a commit that referenced this issue Dec 1, 2023
…#4733)

* add option for resource attributes in metrics for prometheus exporter

This PR adds the `WithResourceAsConstantLabels` option to the Prometheus exporter to allow users to configure resource attributes to be applied on every metric.

Fixes #4732

Signed-off-by: Alex Boten <aboten@lightstep.com>

* add test, changelog

Signed-off-by: Alex Boten <aboten@lightstep.com>

* add test for including only a subset of tags, dont use a ptr

Signed-off-by: Alex Boten <aboten@lightstep.com>

* Update exporters/prometheus/config.go

Co-authored-by: David Ashpole <dashpole@google.com>

* include feedback from review

Signed-off-by: Alex Boten <aboten@lightstep.com>

* cache results

Signed-off-by: Alex Boten <aboten@lightstep.com>

* removed map in favour of single keyVals

Signed-off-by: Alex Boten <aboten@lightstep.com>

* Update exporters/prometheus/config.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* move check outside the createResourceAttributes and rename func

Signed-off-by: Alex Boten <aboten@lightstep.com>

---------

Signed-off-by: Alex Boten <aboten@lightstep.com>
Co-authored-by: David Ashpole <dashpole@google.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg:exporter:prometheus Related to the Prometheus exporter package
Development

Successfully merging a pull request may close this issue.

3 participants