Skip to content

feat: support OpenTelemetry SDK 2.0#364

Merged
sjvans merged 40 commits into
2from
otel-2.0
Jun 26, 2026
Merged

feat: support OpenTelemetry SDK 2.0#364
sjvans merged 40 commits into
2from
otel-2.0

Conversation

@sjvans

@sjvans sjvans commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

@PDT42
PDT42 marked this pull request as ready for review August 20, 2025 06:57

@hyperspace-pr-bot hyperspace-pr-bot Bot 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.

The PR correctly migrates to OpenTelemetry SDK 2.0 APIs (resourceFromAttributes, getStringFromEnv, parentSpanContext, instrumentationScope, etc.), but there are several correctness issues to address: a concrete undefined-in-array bug when Dynatrace OneAgent is used for tracing, and three places where the old guard against overwriting an already-initialized global provider (metrics, tracing, logging) has been removed and only replaced with TODO comments — this is the stated open CALM interoperability scope, but the code currently overwrites blindly with no warning.

PR Bot Information

Version: 1.26.5

  • File Content Strategy: Full file content
  • LLM: anthropic--claude-4.6-sonnet
  • Event Trigger: issue_comment.created
  • Correlation ID: d7a94678-c811-475c-8923-a4466d093d55

Comment thread lib/tracing/index.js Outdated
Comment thread lib/metrics/index.js Outdated
Comment thread lib/metrics/index.js Outdated
Comment thread lib/metrics/index.js Outdated
Comment thread lib/logging/index.js Outdated
Comment thread lib/tracing/index.js Outdated
Comment thread lib/metrics/index.js Outdated
@mrl-sap

mrl-sap commented Jun 25, 2026

Copy link
Copy Markdown

Unfortunately, @openteletry/core has a CVE finding (CVE-2026-54285) which requires an update to 2.8.0 to fix. As this PR is a pre-requisite for updating, its merge would be greatly appreciated :-)

sjvans and others added 5 commits June 26, 2026 14:34
otel 2.0 requires processors and readers to be registered once. with
calm, you need to pre-load their instrumentation (cf.
[Auto-instrumentation for
Node.js](https://support.sap.com/en/alm/sap-cloud-alm/operations/expert-portal/data-collection-infrastructure/autoinstrumentation-nodejs.html)),
which then already has registered all processors and readers, which was
the main hurdle in supporting otel 2.0.

with v2.0.4 (eta end of july), `@sap/xotel-agent-ext-js` will offer
`addDelegate()` functionality in order for `@cap-js/telemetry` to once
again add their processors and readers during server start.

there is no explicit feature flag. instead, if the project has
dependency `@sap/xotel-agent-ext-js`, running with calm is assumed. in
this case, all other setup (e.g., resource description, sampling,
metrics views, etc. -- cf[.
TracerConfig](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-trace-base.TracerConfig.html),
[MeterProviderOptions](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-metrics.MeterProviderOptions.html),
and
[LoggerProviderOptions](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-logs.LoggerProviderOptions.html))
is done via calm means.
# Replace Deprecated `@opentelemetry/host-metrics` with
`@opentelemetry/instrumentation-host-metrics`

### Changes

♻️ **Refactor**: Migrated from the deprecated
`@opentelemetry/host-metrics` package to the new
`@opentelemetry/instrumentation-host-metrics` package, aligning with the
standard OpenTelemetry instrumentation pattern.

Previously, host metrics were handled by a dedicated custom module
(`lib/metrics/host.js`) with manual view-based filtering to drop
`system.*` metrics. The new package supports a `metricGroups` config
option, enabling a cleaner approach to restricting collected metrics.

### Changes

* `lib/metrics/host.js`: **Removed** — the custom host metrics wrapper
is no longer needed.
* `lib/index.js`: Added auto-detection logic for
`@opentelemetry/instrumentation-host-metrics` (similar to
`instrumentation-runtime-node`). By default, restricts collection to
`['process.cpu', 'process.memory']` unless manually configured or
`HOST_METRICS_RETAIN_SYSTEM=true` is set.
* `lib/metrics/index.js`: Removed the call to `require('./host')()` and
eliminated the `views`-based workaround for dropping `system.*` metrics
from the `MeterProvider` constructor.
* `lib/exporter/ConsoleMetricExporter.js`: Updated scope name check from
an `endsWith(':host-metrics')` pattern to an exact match on
`'@opentelemetry/instrumentation-host-metrics'`.
* `package.json`: Replaced `@opentelemetry/host-metrics` dev dependency
with `@opentelemetry/instrumentation-host-metrics@^0.2.0`. Also pinned
several `@opentelemetry/*` packages to `^2.8`.
* `test/bookshop/package.json`: Replaced `@opentelemetry/host-metrics`
with `@opentelemetry/instrumentation-host-metrics`; removed explicit
`instrumentation-runtime-node` config (now auto-detected); added
`devDependencies` section.
* `README.md`: Updated references from `@opentelemetry/host-metrics` to
`@opentelemetry/instrumentation-host-metrics`, revised host metrics
documentation to describe the new `metricGroups` config approach, and
expanded the table of contents.
* `CHANGELOG.md`: Added entry under version 1.7.0 noting the
replacement.
* `package-lock.json`: Removed from the repository.

- [ ] 🔄 Regenerate and Update Summary



<details>
<summary>PR Bot Information</summary>

**Version:** `1.26.11`

- Summary Prompt: [Default
Prompt](https://github.tools.sap/intelligent-insights/i2-pull-request/blob/main/src/services/llm/prompts/summary_instructions_prompt.md)
- Correlation ID: `8d350630-0a40-4070-8bf8-8c53bab1fda1`
- File Content Strategy: Full file content
- Event Trigger: `pull_request.opened`
- Output Template: [Default
Template](https://github.tools.sap/intelligent-insights/i2-pull-request/blob/main/src/services/llm/prompts/summary_default_output_template.md)
- LLM: `anthropic--claude-4.6-sonnet`
</details>
@sjvans
sjvans changed the base branch from main to 2 June 26, 2026 14:05
Comment thread README.md Outdated
@sjvans
sjvans merged commit b8f5c0c into 2 Jun 26, 2026
3 checks passed
@sjvans
sjvans deleted the otel-2.0 branch June 26, 2026 14:20
@sjvans sjvans mentioned this pull request Jun 28, 2026
1 task
sjvans added a commit that referenced this pull request Jun 29, 2026
# Release: `v2.0.0` — OpenTelemetry SDK 2.0 Support

### New Features

🚀 This major release upgrades `@cap-js/telemetry` to support
**OpenTelemetry SDK 2.0**, introduces
`@opentelemetry/instrumentation-undici` as a default instrumentation,
adds CALM (`@sap/xotel-agent-ext-js`) integration, and drops support for
`@sap/cds^8`.

### Changes

* `package.json`: Bumped version to `2.0.0`. Updated all
`@opentelemetry/*` dependencies to SDK 2.x-compatible versions. Replaced
`@opentelemetry/host-metrics` with
`@opentelemetry/instrumentation-host-metrics`. Added
`@opentelemetry/instrumentation-undici` as a new default
instrumentation. Dropped `@sap/cds^8` peer dependency support. Updated
`vcap` binding config for Dynatrace and Cloud Logging to also match by
tag.
* `cds-plugin.js`: Removed the startup check that blocked usage with
OpenTelemetry SDK 2.0. Added a workaround for `cds build` command
detection.
* `lib/index.js`: Refactored to support two setup modes:
`setup_standalone` (default) and `setup_with_calm` (when
`@sap/xotel-agent-ext-js` is detected). Auto-detection of
`@opentelemetry/instrumentation-host-metrics` as an instrumentation,
with `metricGroups` limited to `['process.cpu', 'process.memory']` by
default.
* `lib/tracing/index.js`: Added CALM delegate support for span
processors. Replaced deprecated `Resource` with
`resourceFromAttributes`. Updated to use `spanProcessors` constructor
option instead of `addSpanProcessor`. Added SAP Passport cleanup for new
transactions.
* `lib/metrics/index.js`: Added CALM delegate support for metric
readers. Replaced deprecated `Resource`/`View`/`DropAggregation` APIs
with `resourceFromAttributes` and `readers` constructor option. Removed
`lib/metrics/host.js` (replaced by instrumentation-based approach).
* `lib/logging/index.js`: Added CALM delegate support for log
processors. Refactored provider initialization. Improved error message
for missing Cloud Logging credentials.
* `lib/utils.js`: Replaced `getEnv`/`getEnvWithoutDefaults` with
`getStringFromEnv`. Replaced `new Resource(...)` with
`resourceFromAttributes(...)` throughout.
* `lib/exporter/ConsoleSpanExporter.js`: Updated span parent references
from deprecated `parentSpanId` to `parentSpanContext?.spanId`.
* `lib/exporter/ConsoleMetricExporter.js`: Updated scope name check for
host metrics instrumentation.
* `lib/tracing/trace.js`: Updated `instrumentationLibrary` reference to
`instrumentationScope` (SDK 2.0 rename).
* `README.md`: Removed the "not yet supported" warning for OpenTelemetry
SDK 2.0. Updated host metrics docs to reflect the new `metricGroups`
configuration. Added `undici` to default instrumentations list.
Clarified Cloud Logging user-provided service tag requirement to `"Cloud
Logging"` only.
* `CHANGELOG.md`: Updated version header to `2.0.0` with added, changed,
fixed, and removed entries.
* `.github/workflows/ci.yml`: Updated CI matrix to test only with
`cds-version: [9]`; added branch `2` to push triggers.
* `test/bookshop/.cdsrc.json`: Extracted CDS profile-based test
configurations from `package.json` into a dedicated config file.
* Various test files: Migrated from `cds.test().in(...)` to
`cds.test(..., '--profile', ...)` pattern; reduced wait times from 300ms
to 150ms in metrics tests.

- [ ] 🔄 Regenerate and Update Summary



<details>
<summary>PR Bot Information</summary>

**Version:** `1.26.11`

- Event Trigger: `pull_request.edited`
- Output Template: [Default
Template](https://github.tools.sap/intelligent-insights/i2-pull-request/blob/main/src/services/llm/prompts/summary_default_output_template.md)
- Correlation ID: `99a59df9-b306-487f-9485-bc9d1b221f55`
- Summary Prompt: [Default
Prompt](https://github.tools.sap/intelligent-insights/i2-pull-request/blob/main/src/services/llm/prompts/summary_instructions_prompt.md)
- File Content Strategy: Full file content
- LLM: `anthropic--claude-4.6-sonnet`
</details>

---

compiled of:
- #364
  + #424
  + #442
- #407
- #374
- #425
- #443

---------

Co-authored-by: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com>
Co-authored-by: I548646 <paul.erlenwein@sap.com>
Co-authored-by: Paul <paul.erlenwein@gmail.com>
Co-authored-by: hyperspace-insights[bot] <209611008+hyperspace-insights[bot]@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.

6 participants