Skip to content

Prometheus: update resource translation#4956

Open
dashpole wants to merge 6 commits intoopen-telemetry:mainfrom
dashpole:prom_stabilize_resource
Open

Prometheus: update resource translation#4956
dashpole wants to merge 6 commits intoopen-telemetry:mainfrom
dashpole:prom_stabilize_resource

Conversation

@dashpole
Copy link
Copy Markdown
Contributor

Part of #4753

Fixes #4577

Related to open-telemetry/opentelemetry-collector-contrib#45982

Issues with the current state

  • The receiver can get both job (from scrape config) and service.name from target info. Currently, we let one win, but ideally we would keep both.
  • Users that push OTLP to prometheus still expect to see service.name and service.instance.id, and are confused when it is missing. We should consider keeping those and having a job + instance. We can add configuration to disable it, if necessary.

Changes

There are a bunch of changes to the formatting and wording included in this PR. If needed, I can split those out.

Add prometheus.job and prometheus.instance as labels based on job and instance from receivers. In the receiver, we can give users the option not to default these to service.name and service.instance.id. This solves the issue we currently have where service.name can be present in target_info, and conflict with the job and instance from the prometheus target. This would allow us to preserve both in those cases. On the exporter side, we translate them back to job and instance, and can also preserve the original service.name and service.instance.id separately.

Alternatives

  • Use job and instance instead of prometheus.job or prometheus.instance.
  • Default to not producing the new prometheus.* attributes. This means less change for users, but more issues with the current state where job or service.name has to be dropped.

@open-telemetry/prometheus-interoperability @aknuds1 @kln21002 @cyrille-leclerc

@ArthurSens
Copy link
Copy Markdown
Member

Hmmmm, to make quicker progress here, would it make sense to focus on the Prometheus -> OTLP transformation and leave OTLP -> Prometheus in a separate PR?

I feel like OTLP -> Prometheus is a lot more complicated, and will require deeper discussions with other parts of OTel, like Infrastructure semantic conventions, OBI, etc 🤔

@dashpole
Copy link
Copy Markdown
Contributor Author

My main goal is to make sure that everything still round-trips properly. If I make changes to one direction, I usually have to make the inverse change to the other direction to ensure that. I can remove some of the editorial changes to the OTLP -> Prometheus section if that helps. But I would like aggregated exporters to accept prometheus.job and prometheus.instance if we add those to the receiver.

Copy link
Copy Markdown
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

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

Please see comments :)

Comment thread specification/compatibility/prometheus_and_openmetrics.md Outdated
Comment thread specification/compatibility/prometheus_and_openmetrics.md
@dashpole dashpole moved this to Discussion Needed in Prometheus SIG Mar 18, 2026
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 3, 2026

This PR was marked stale. It will be closed in 14 days without additional activity.

@github-actions github-actions Bot added the Stale label Apr 3, 2026
@dashpole
Copy link
Copy Markdown
Contributor Author

dashpole commented Apr 6, 2026

@github-actions github-actions Bot removed the Stale label Apr 7, 2026
@dashpole dashpole changed the title [WIP] Prometheus: update resource translation Prometheus: update resource translation Apr 10, 2026
@dashpole dashpole marked this pull request as ready for review April 10, 2026 15:41
@dashpole dashpole requested review from a team as code owners April 10, 2026 15:41
The following attributes SHOULD be associated with scraped metrics as resource
attributes, and MUST NOT be added as metric attributes:
If `service.name` or `service.instance.id` are not provided by `target_info`,
they MUST be defaulted to the `job` and `instance` labels, respectively.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if job has the form of namespace/name whether it should be used to set service.namespace accordingly. I was trying to square this with the text on lines 640-642, which would insert the service.namespace, and then if there was another level of federation the service.namespace value might disappear.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

job would be formed that way if you are using a prometheus or PRW collector exporter (since SDKs don't populate job/instance themselves), and then need to translate it back to OTLP at a future point. Generally, that isn't a thing that happens much in practice, since it is much easier to just send OTLP than to round-trip through PRW or the Prometheus format. So it is something we could do, but probably has little value in practice.

Overall, I'm trying to deemphasize job == service.name in this PR to allow them to be separate things conceptually.

Copy link
Copy Markdown
Contributor

@jmacd jmacd left a comment

Choose a reason for hiding this comment

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

I left a very minor question.

Copy link
Copy Markdown
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.

I did a pass through the PR, and so far, I have just one comment.

I feel like I haven't fully grasped the potential consequences of this change, so I'm taking some extra time to reflect, I hope that's ok :)

Comment thread specification/compatibility/prometheus_and_openmetrics.md
@ArthurSens ArthurSens moved this from Discussion Needed to In progress in Prometheus SIG Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

[OTel to Prometheus] Promote resource attr service.name, service.namespace, and service.instance.id as Prometheus metric labels

4 participants