Skip to content

fix: provide unique metric identity for workers#1134

Merged
ferhatelmas merged 1 commit into
masterfrom
ferhat/metric-identity
Jun 4, 2026
Merged

fix: provide unique metric identity for workers#1134
ferhatelmas merged 1 commit into
masterfrom
ferhat/metric-identity

Conversation

@ferhatelmas

@ferhatelmas ferhatelmas commented Jun 4, 2026

Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Under Watt metrics can conflict with same hostname.

What is the new behavior?

Give unique writer identity:

  • hostname:applicationId:worker:<workerId>
  • hostname:pid:<process.pid>

Additional context

Also, add service.name into example collector config, was forgotten in #1112

Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Copilot AI review requested due to automatic review settings June 4, 2026 12:49
@ferhatelmas ferhatelmas requested a review from a team as a code owner June 4, 2026 12:49

Copilot AI left a comment

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.

Pull request overview

This PR fixes OpenTelemetry metric writer collisions (notably under Watt when multiple workers share the same hostname) by adding a stable, unique service instance identity to the metric Resource and ensuring it is propagated into Prometheus/remote-write label sets via the example collector config.

Changes:

  • Derive a unique service.instance.id based on hostname + Platformatic application/worker identity (or PID fallback) and attach it to the OTel Resource.
  • Expose additional identity/resource attributes (service.instance.id, worker.id, platformatic.application.id) as constant labels for the Prometheus exporter.
  • Update the example OTel Collector config (and add tests) to copy these Resource attributes into datapoint attributes/labels (including service.name).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/internal/monitoring/otel-metrics.ts Adds unique metric identity (service instance id + worker/app ids) to the OTel Resource and Prometheus constant-label filtering.
src/internal/monitoring/otel-metrics.test.ts Adds coverage for Watt worker identity mapping and verifies collector config contains the new promotion rules.
monitoring/otel/config/otel-collector-config.yml Promotes Resource identity attributes (and service.name) into metric datapoint attributes for stable routing/unique writer labels.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 26952733055

Coverage increased (+0.04%) to 76.346%

Details

  • Coverage increased (+0.04%) from the base build.
  • Patch coverage: 18 of 18 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 11029
Covered Lines: 8854
Line Coverage: 80.28%
Relevant Branches: 6452
Covered Branches: 4492
Branch Coverage: 69.62%
Branches in Coverage %: Yes
Coverage Strength: 364.9 hits per line

💛 - Coveralls

@ferhatelmas ferhatelmas merged commit afea83e into master Jun 4, 2026
23 checks passed
@ferhatelmas ferhatelmas deleted the ferhat/metric-identity branch June 4, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants