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

Prometheus Exporters do not interact with Resource attributes #4046

Closed
yangtaoran opened this issue Jan 5, 2022 · 5 comments · Fixed by #5039
Closed

Prometheus Exporters do not interact with Resource attributes #4046

yangtaoran opened this issue Jan 5, 2022 · 5 comments · Fixed by #5039
Labels
Bug Something isn't working metrics

Comments

@yangtaoran
Copy link

yangtaoran commented Jan 5, 2022

https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeterProviderBuilder.java#L56
Here,I set setResource to all meter.I think all metrics will add attributes from the resource,but it not.
I init SdkMeterProvider by follow:

SdkMeterProvider.builder().setResource(Resource.create(Attributes.of(
                AttributeKey.stringKey("instance"), "xxxx")))
                .registerMetricReader(
                        PrometheusHttpServer.builder().setHost("127.0.0.1").setPort(9092).newMetricReaderFactory())
                .buildAndRegisterGlobal();
Meter meter = GlobalMeterProvider.get().get("test");
LongCounter testCounter = meter.counterBuilder("meter_test").setUnit("1").setDescription("test").build();
testCounter.add(1, Attributes.of(AttributeKey.stringKey("hello"), "world"));

I scrap the metrics like this:

meter_test_total{hello="world",} 1.0 1641357854770

I think it will be ”meter_test_total{hello="world",instance="xxxx"} 1.0 1641357854770”

@yangtaoran yangtaoran added the Bug Something isn't working label Jan 5, 2022
@anuraaga
Copy link
Contributor

anuraaga commented Jan 5, 2022

Hi @yangtaoran - there is currently not any support for mapping resource properties into metric attributes for Prometheus exporter. Are you using the prometheus exporter in this repository or are you using the OpenTelemetry collector? Currently I believe the way to achieve what you want is to use resource_to_telemetry_conversion in the prometheus exporter in the collector

https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/prometheusexporter#getting-started

@yangtaoran
Copy link
Author

Hi @yangtaoran - there is currently not any support for mapping resource properties into metric attributes for Prometheus exporter. Are you using the prometheus exporter in this repository or are you using the OpenTelemetry collector? Currently I believe the way to achieve what you want is to use resource_to_telemetry_conversion in the prometheus exporter in the collector

https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/prometheusexporter#getting-started

I am using the prometheus exporter in this repository. So what can do for the SdkMeterProviderBuilder setResource method?According to you, I can use OTLP to export metrics data to the collector, and the collector configure prometheus exporter with resource_to_telemetry_conversion. So the prometheus exporter will export the metrics data with the resource.Is my understanding right?

@anuraaga
Copy link
Contributor

anuraaga commented Jan 6, 2022

Yup I think using OTLP exporter from SDK to collector and using that setting is probably the best bet for now. We need to think of how to better support this in the SDK natively.

@yangtaoran
Copy link
Author

I think It's necessary that the Prometheus exporter from SDK should export metrics data with resource.Although I can do like above,it's complicated.If it is possible,I can push a PR.

@jsuereth
Copy link
Contributor

jsuereth commented Jan 8, 2022

@yangtaoran The prometheus exporter is not fully specified in OTEL yet. I fully expect resource -> prometheus labels to part of that final specification, but we're still discussing the details of what would be done in SDKs.

You can see:

@anuraaga's workaround should be good for now, but expect improvements in the SDK-exporter going forward.

@jsuereth jsuereth changed the title SdkMeterProviderBuilder setResource cannot work Prometheus Exporters do not interact with Resource attributes Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working metrics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants