Skip to content

Conversation

aknuds1
Copy link
Contributor

@aknuds1 aknuds1 commented Jun 16, 2025

Add support to the OTLP endpoint for including scope metadata as metric labels.

Fixes #16557.

@aknuds1 aknuds1 force-pushed the arve/16557 branch 3 times, most recently from 7b47dc6 to 00598c5 Compare June 16, 2025 08:49
@aknuds1 aknuds1 changed the title WIP: OTLP: Support including scope metadata as metric labels OTLP: Support including scope metadata as metric labels Jun 16, 2025
@aknuds1 aknuds1 marked this pull request as ready for review June 16, 2025 09:05
@aknuds1 aknuds1 requested a review from Copilot June 16, 2025 09:15
@aknuds1 aknuds1 force-pushed the arve/16557 branch 2 times, most recently from c01b2c5 to af944bb Compare June 16, 2025 09:17
Copilot

This comment was marked as outdated.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds optional support for including OTel scope metadata (name, version, schema URL, attributes) as Prometheus metric labels in the OTLP remote write translation pipeline.
Key changes:

  • Introduce a ConvertScopeMetadata flag in OTLP settings and config, propagating it through the write handler and converter.
  • Add a scope type and thread it through all converter methods to inject scope labels in createAttributes.
  • Update tests and documentation to cover scope metadata conversion for gauge, sum, and histogram metrics.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
storage/remote/write_handler.go Wire new ConvertScopeMetadata option into exporter settings
storage/remote/otlptranslator/prometheusremotewrite/*.go Add scope parameter to converter methods and inject scope labels via createAttributes
storage/remote/otlptranslator/prometheusremotewrite/helper.go Update createAttributes to preallocate and append scope labels
storage/remote/otlptranslator/prometheusremotewrite/*_test.go Extend tests for gauge, sum, and histogram conversion with and without scope metadata
docs/configuration/configuration.md Document new convert_scope_metadata config flag
config/config.go, config/config_test.go, config/testdata/*.yml Add parsing and test for new OTLP config flag
CHANGELOG.md Document feature under unreleased section
Comments suppressed due to low confidence (3)

storage/remote/otlptranslator/prometheusremotewrite/number_data_points_test.go:149

  • Only the basic sum case is tested with convertScope: true; recommend adding test cases for convertScope: true in the exemplars, monotonic and non-monotonic sum scenarios to ensure full coverage.
tests := []struct {

storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go:95

  • [nitpick] The unexported type name scope is very generic and can be confused with other concepts; consider renaming it to something more descriptive like scopeMetadata or otelScope.
type scope struct {

storage/remote/otlptranslator/prometheusremotewrite/helper.go:118

  • [nitpick] Passing scope through every converter method increases signature complexity; consider bundling scope metadata into the converter struct or Settings to simplify method signatures.
func createAttributes(resource pcommon.Resource, attributes pcommon.Map, scope scope, settings Settings,

Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this Arve! I can't take a deep look at the code for a few days, so I'm leaving just one suggestion for now :)

@aknuds1
Copy link
Contributor Author

aknuds1 commented Jun 18, 2025

I think we can merge, as I've looked it over again and it checks out AFAICT. If there turns out to be any overlooked issues, we can address them in a new PR.

@aknuds1 aknuds1 merged commit 964bd7d into prometheus:main Jun 18, 2025
27 checks passed
@aknuds1 aknuds1 deleted the arve/16557 branch June 18, 2025 07:14
@jmichalek132
Copy link
Contributor

I guess this should be ported to remote write exporter in the collector too right?

@aknuds1
Copy link
Contributor Author

aknuds1 commented Jun 18, 2025

I guess this should be ported to remote write exporter in the collector too right?

@jmichalek132 Not really familiar with the OTel Collector side of things, but probably yes. Considering that OTel spec now stipulates that scope metadata (name/version/schema URL/attributes) should be part of Prometheus metric identity.

@ArthurSens
Copy link
Member

Yes!

bboreham pushed a commit that referenced this pull request Jul 8, 2025
Reverts #16730 and #16760

This is being done because we've noticed a problem in the spec that could
lead to name collisions if attributes name, version or schema_url are added
to the scope. They would collide with the already reserved labels
otel_scope_name, otel_scope_version and otel_scope_schema_url.

Since this new configuration option never made it into a release, we can
safely remove it from the 3.5 release. We'll sort this out for the 3.6 release

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OTLP: Translate OTel scope attributes to labels
4 participants