Skip to content

Conversation

@instanacd
Copy link
Contributor

@instanacd instanacd commented Oct 8, 2025

Changes

  • Load @opentelemetry/api from the app root to ensure all instrumentations and monkey patches share the same global API instance.

  • Add peer dependency with bounded version range (>=1.3.0 <1.10.0) to enforce compatibility and avoid runtime issues like NonRecordingSpan.

  • Updated all @opentelemetry instrumentations versions to latest

What This PR resolves

This PR addresses the multiple API instance issue that occurred when @opentelemetry/api was also installed at the application root. In such cases, our openTelemetry integretion was not functioning correctly before.

When the OTEL SDK and our collector are used together within the same application:

  • If the OTEL SDK is initialized first, it now correctly captures all our instrumented libraries (including our OTEL). Previously, this was not happening. OTEL also works.

  • If our collector is initialized first, it currently blocks OTEL tracing - this is a known issue and will be addressed separately.

This PR resolves the multiple instance problem. Tests demonstrating OTEL SDK and our collector behaviors will be included in a separate PR.

There is still issue when our collector initialized first.

References:

https://github.com/open-telemetry/opentelemetry-js/issues/4832
open-telemetry/opentelemetry-js#5454
https://jsw.ibm.com/browse/INSTA-59002

@instanacd instanacd requested a review from a team as a code owner October 8, 2025 09:06
Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

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

Still compatible with Node v18 and with Otel API version >=1.3.

@aryamohanan aryamohanan self-assigned this Oct 8, 2025
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch 3 times, most recently from e103c73 to 545ac45 Compare October 9, 2025 06:04
@aryamohanan aryamohanan added the WIP label Oct 9, 2025
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch 2 times, most recently from 5c8f56d to 8d4ea7e Compare October 10, 2025 08:59
@aryamohanan aryamohanan marked this pull request as draft October 10, 2025 11:42
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch from af14bde to cedf865 Compare October 13, 2025 04:06
@aryamohanan
Copy link
Contributor

aryamohanan commented Oct 13, 2025

A few tests are failing, specifically, the ones that assert fs spans. The issue noticed after the recent update, where the otel fs package was installed at the root level, leading to a conflict between different OpenTelemetry API instances.

Root Cause: Multiple OTEL API instances are being loaded that intercept the tracing

Working case: When modules are loaded from the same location (packages/core/node_modules), both the core code and the FS instrumentation share a single OTEL API instance. As a result, spans are created correctly.

Non-working case: When the FS instrumentation is loaded from a different location (e.g., root node_modules), it uses a separate OTEL API instance. Since our core code applies monkey patches to its own API instance(packages/code/node_modules), the instrumentation does not receive those patches, causing spans to be missing and tests to fail.

@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch from c3fef76 to 70473cf Compare October 14, 2025 08:08
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch 2 times, most recently from 0949a9d to fc8f9a2 Compare October 15, 2025 15:46
@aryamohanan aryamohanan changed the title [Prod Dependency Bot] Bumped @opentelemetry/instrumentation-fs from 0.12.0 to 0.26.0 fix: unified OpenTelemetry API instance to prevent duplicate instances Oct 15, 2025
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch 2 times, most recently from 21be414 to f3fedf8 Compare October 17, 2025 04:22
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch from d1b232d to e5592d2 Compare November 3, 2025 08:39
@aryamohanan aryamohanan marked this pull request as draft November 3, 2025 09:08
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch from e5592d2 to 8be2f32 Compare November 4, 2025 04:14
@aryamohanan aryamohanan marked this pull request as ready for review November 4, 2025 07:22
@aryamohanan
Copy link
Contributor

Known Issues

  • OpenTelemetry API version compatibility:
    If a customer installs @opentelemetry/api with a version below v1.3.0, tracing will not function correctly.
    In such cases, installing v1.3.0 at the project root and v1.9.0 (latest) in our directory, the issue due to mismatched API instances and incomparable version
    Generally, this is not a valid setup since versions below v1.3.0 are incompatible with most OpenTelemetry instrumentations.

  • OpenTelemetry SDK + Instana initialization order:
    When both OpenTelemetry SDK and Instana are used together, and our collector is initialized first, tracing fails to work.
    This is a known limitation and needs to be addressed separately.

  • AsyncHooksContextManager usage:
    The current use of AsyncHooksContextManager should be revisited. It may not be applied correctly or could be irrelevant in the existing setup.

Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

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

Great work <3

aryamohanan added a commit that referenced this pull request Nov 4, 2025
This change fixes an issue where multiple instances of @opentelemetry/api were being loaded — one from the application root and another from instana core. This caused the OpenTelemetry integration to not work correctly.

By adding dependency with a bounded version range (>=1.3.0 <1.10.0), we ensure that only one compatible version of the API is installed, maintaining consistent behavior across environments.

ref #2054
https://jsw.ibm.com/browse/INSTA-59002
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch from 7b082c4 to 6891e76 Compare November 5, 2025 06:38
@instana instana deleted a comment from sonarqubecloud bot Nov 5, 2025
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch 4 times, most recently from b54e0dc to a18aab6 Compare November 10, 2025 03:51
@aryamohanan aryamohanan changed the title fix: unified OpenTelemetry API instance to prevent duplicate instances fix: OpenTelemetry instrumentation packages updates Nov 10, 2025
@aryamohanan aryamohanan force-pushed the build-opentelemetryinstrumentationfs-0260 branch from a18aab6 to 3752d3e Compare November 10, 2025 06:57
@sonarqubecloud
Copy link

@aryamohanan aryamohanan requested a review from kirrg001 November 10, 2025 13:36
Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

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

Super sweet

@aryamohanan aryamohanan merged commit 729640b into main Nov 10, 2025
4 checks passed
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.

5 participants