Skip to content

fix(opentelemetry-bridge): update to OTel SDK 2.x, fix opentelemetryBridgeEnabled to cover metrics integration#5126

Merged
trentm merged 12 commits into
elastic:mainfrom
gsoldevila:chore/opentelemetry-2x
Jul 7, 2026
Merged

fix(opentelemetry-bridge): update to OTel SDK 2.x, fix opentelemetryBridgeEnabled to cover metrics integration#5126
trentm merged 12 commits into
elastic:mainfrom
gsoldevila:chore/opentelemetry-2x

Conversation

@gsoldevila

@gsoldevila gsoldevila commented Jun 29, 2026

Copy link
Copy Markdown
Member

Summary

Upgrades @opentelemetry/core and @opentelemetry/sdk-metrics from 1.x to 2.8.0, and migrates the agent's OTel Metrics integration to the 2.x SDK API.

This picks up the upstream fix for CVE-2026-54285 (unbounded baggage header processing) in @opentelemetry/core, which is currently pulled in transitively at 1.30.1 by elastic-apm-node (via @opentelemetry/sdk-metrics@^1.12.0).

This supersedes the dependabot-only bumps (#5097, #5095, #5113) which fail CI because they bump the dependency without migrating the calling code to the 2.x API.

Update(@trentm): This also extends the opentelemetryBridgeEnabled config setting to also cover OTel Metrics integration, only allows the setting to be true for new-enough Node.js versions, ensures @opentelemetry/ deps are only require'd if the setting is enabled.
See 50577ce
Closes: #4956

What changed

OTel Metrics SDK 2.x has two breaking changes that the agent relied on:

  1. Aggregation classes removed. ExplicitBucketHistogramAggregation, SumAggregation, LastValueAggregation, and DropAggregation are replaced by AggregationOption config objects keyed by AggregationType.
  2. MeterProvider.addMetricReader() removed. Metric readers must now be passed via the constructor readers option.

Files updated:

  • lib/opentelemetry-metrics/ElasticApmMetricExporter.js — aggregation config objects + AggregationType import; selectAggregation now returns an AggregationOption.
  • lib/opentelemetry-metrics/index.jsMeterProvider reader passed via constructor.
  • lib/instrumentation/modules/@opentelemetry/sdk-metrics.jsApmMeterProvider appends the agent's reader to user-supplied readers and passes them to super(); supported-version guard moved to >=2.0.0 <3.
  • test/opentelemetry-metrics/fixtures/* and examples/opentelemetry-metrics/use-otel-metrics-sdk.js — migrated to the 2.x API (plain view-option objects, readers).
  • package.json + lockfiles (root and fixtures) bumped to core/sdk-metrics 2.8.0.

Test plan

  • node test/opentelemetry-metrics/fixtures.test.js85/85 pass locally (this is the suite that fails on the dependabot-only PRs).
  • eslint clean on all changed files.
  • lint:tav and test:deps pass.
  • Full CI (test-vers matrix across Node versions) — needs maintainer run.
  • Confirm minimum-supported @opentelemetry/sdk-metrics bump to 2.0.0 is acceptable (drops auto-instrumentation of user MeterProviders on 1.x SDKs).

Note: opened from a fork; raised while remediating the CVE downstream in Kibana, where elastic-apm-node is the remaining consumer pinning @opentelemetry/core < 2.8.0.

Made with Cursor

@github-actions

Copy link
Copy Markdown

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

…cs to 2.x

Bumps `@opentelemetry/core` and `@opentelemetry/sdk-metrics` from 1.x to
2.8.0. This picks up the upstream fix for CVE-2026-54285 (unbounded
`baggage` header processing) in `@opentelemetry/core`.

The OTel Metrics SDK 2.x has breaking API changes that required updating
the agent's metrics integration:

- The aggregation classes (`ExplicitBucketHistogramAggregation`,
  `SumAggregation`, `LastValueAggregation`, `DropAggregation`) were
  removed in favour of `AggregationOption` config objects keyed by
  `AggregationType`.
- `MeterProvider.addMetricReader()` was removed; metric readers must now
  be passed via the constructor `readers` option.

Updated `lib/opentelemetry-metrics`, the `@opentelemetry/sdk-metrics`
instrumentation, the OTel metrics test fixtures, and the example to the
2.x API. The minimum supported `@opentelemetry/sdk-metrics` version for
instrumentation is now 2.0.0.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gsoldevila
gsoldevila force-pushed the chore/opentelemetry-2x branch from 11d7ffe to 98cf439 Compare June 29, 2026 16:00
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

✅ Elastic Docs Style Checker (Vale)

No issues found on modified lines!


The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale.

@gsoldevila
gsoldevila marked this pull request as ready for review June 29, 2026 16:09
@gsoldevila
gsoldevila requested a review from a team as a code owner June 29, 2026 16:09
trentm added 5 commits July 6, 2026 14:13
…entelemetryBridgeEnabled

- Extend the `opentelemetryBridgeEnabled` config setting to *also* cover
  the integration with `@opentelemetry/sdk-metrics`. This was an
  oversight with OTel Metrics support was added after the initial
  support for OTel Tracing.
  This handles elastic#4956

- Ensure that `@opentelemetry/*` libs are **only require'd if
  `opentelemetryBridgeEnabled` is true** and if the current running
  Node.js version is in the supported range for the included
  Node.js SDK.

  If a user explicitly tries to enable the OTel Bridge, but
  is using too old of a Node.js version (e.g. 14 or 16), then
  the APM agent will log a warning and set
  `opentelemetryBridgeEnabled = false`.

These changes allow the OpenTelemetry integration support to
update the internally included `@opentelemetry/*` libs without
hard breaking usage of the APM agent with older Node.js versions.

It *does* mean that the OpenTelemetry Bridge no longer works with
Node.js 14 and 18 (requires "^18.19.0 || >=20.6.0"). This is breaking
for those users, but the Bridge is experimental, so that is allowed
in minor releases.

Closes: elastic#4956
…tests; refactor to avoid circular import and interaction with hooking of sdk-metrics package
@trentm trentm self-assigned this Jul 6, 2026
@trentm trentm changed the title chore(deps): upgrade @opentelemetry/core and @opentelemetry/sdk-metrics to 2.x fix(opentelemetry-bridge): update to OTel SDK 2.x, fix opentelemetryBridgeEnabled to cover metrics integration Jul 6, 2026
trentm
trentm previously approved these changes Jul 6, 2026

@trentm trentm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

Comment thread test/opentelemetry-bridge/fixtures.test.js Outdated
@trentm
trentm merged commit 45c2bcd into elastic:main Jul 7, 2026
33 of 35 checks passed
@trentm

trentm commented Jul 9, 2026

Copy link
Copy Markdown
Member

@gsoldevila elastic-apm-node@4.18.0 is out with the upgrade to OTel SDK 2.x libs (#5137).

gsoldevila added a commit to elastic/kibana that referenced this pull request Jul 13, 2026
## Summary

- Bumps `elastic-apm-node` from `4.15.0` to `4.18.0`
- `4.17.0` fixes IPv6 URL parsing errors (`Could not set destination
context: Invalid URL`) reported in
[sdh-apm#2043](elastic/sdh-apm#2043)
- `4.18.0` also updates OpenTelemetry 2.x dependencies
([apm-agent-nodejs#5126](elastic/apm-agent-nodejs#5126))

Renovate has not opened this bump yet due to the 14-day
`minimumReleaseAge` on the APM dependency group.

## Test plan

- [ ] CI green
- [ ] Verify Kibana starts with default APM config


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
qn895 pushed a commit to qn895/kibana that referenced this pull request Jul 13, 2026
## Summary

- Bumps `elastic-apm-node` from `4.15.0` to `4.18.0`
- `4.17.0` fixes IPv6 URL parsing errors (`Could not set destination
context: Invalid URL`) reported in
[sdh-apm#2043](elastic/sdh-apm#2043)
- `4.18.0` also updates OpenTelemetry 2.x dependencies
([apm-agent-nodejs#5126](elastic/apm-agent-nodejs#5126))

Renovate has not opened this bump yet due to the 14-day
`minimumReleaseAge` on the APM dependency group.

## Test plan

- [ ] CI green
- [ ] Verify Kibana starts with default APM config


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
biamalveiro pushed a commit to biamalveiro/kibana that referenced this pull request Jul 14, 2026
## Summary

- Bumps `elastic-apm-node` from `4.15.0` to `4.18.0`
- `4.17.0` fixes IPv6 URL parsing errors (`Could not set destination
context: Invalid URL`) reported in
[sdh-apm#2043](elastic/sdh-apm#2043)
- `4.18.0` also updates OpenTelemetry 2.x dependencies
([apm-agent-nodejs#5126](elastic/apm-agent-nodejs#5126))

Renovate has not opened this bump yet due to the 14-day
`minimumReleaseAge` on the APM dependency group.

## Test plan

- [ ] CI green
- [ ] Verify Kibana starts with default APM config


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
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.

disable @opentelemetry/api instrumentation (for OTel Metrics API support) unless opentelemetryBridgeEnabled=true

3 participants