-
Notifications
You must be signed in to change notification settings - Fork 357
chore(otel): make otel api a peer dependency #6914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mabdinur
wants to merge
17
commits into
master
Choose a base branch
from
munir/make-otel-api-a-peer-dependency
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2ba638d
chore(otel): make otel api peer dependency
mabdinur d14e2cc
yarn
mabdinur 9142cc2
Merge branch 'master' into munir/make-otel-api-a-peer-dependency
mabdinur fce4244
revert openfeatures change
mabdinur 0e5b129
bundle opentelemetry in the same way as openfeature
mabdinur 1956ce1
fix license issue
mabdinur 2d399ac
fix linting errors
mabdinur 0162595
update docs
mabdinur e3a3ad8
Merge branch 'master' into munir/make-otel-api-a-peer-dependency
mabdinur a859c70
make changes from code review
mabdinur 9bc5022
check for peer deps and log warnings
mabdinur c6c21ac
mark peerdep as option fix license
mabdinur d5af68f
more clean ups
mabdinur 95a16af
add noop tracerprovider
mabdinur 2b8ca29
fix llmobs test
mabdinur b85f71f
remove comments
mabdinur 11589bb
do not store processors
mabdinur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,7 +364,17 @@ The following tags are available to override Datadog-specific options: | |
|
|
||
| <h2 id="opentelemetry-api">OpenTelemetry Compatibility</h2> | ||
|
|
||
| This library is OpenTelemetry compliant. Use the [OpenTelemetry API](https://opentelemetry.io/docs/instrumentation/js/) and the Datadog Tracer (dd-trace) library to measure execution times for specific pieces of code. In the following example, a Datadog TracerProvider is registered with @opentelemetry/api: | ||
| This library is OpenTelemetry compliant. The OpenTelemetry API packages (`@opentelemetry/api` and `@opentelemetry/api-logs`) are peer dependencies and must be installed separately. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Install the required packages: | ||
|
|
||
| ```bash | ||
| npm install @opentelemetry/api | ||
| # For OpenTelemetry logs support (optional) | ||
| npm install @opentelemetry/api-logs | ||
| ``` | ||
|
|
||
| Use the [OpenTelemetry API](https://opentelemetry.io/docs/instrumentation/js/) and the Datadog Tracer (dd-trace) library to measure execution times for specific pieces of code. In the following example, a Datadog TracerProvider is registered with @opentelemetry/api: | ||
|
|
||
| ```javascript | ||
| const tracer = require('dd-trace').init() | ||
|
|
@@ -381,7 +391,9 @@ The following attributes are available to override Datadog-specific options: | |
|
|
||
| <h3 id="opentelemetry-logs">OpenTelemetry Logs</h3> | ||
|
|
||
| dd-trace-js includes experimental support for OpenTelemetry logs, designed as a drop-in replacement for the OpenTelemetry SDK. This support is primarily intended for logging libraries rather than direct user configuration. Enable it by setting `DD_LOGS_OTEL_ENABLED=true` and use the [OpenTelemetry Logs API](https://open-telemetry.github.io/opentelemetry-js/modules/_opentelemetry_api-logs.html) to emit structured log data: | ||
| dd-trace-js includes experimental support for OpenTelemetry logs, designed as a drop-in replacement for the OpenTelemetry SDK. This support is primarily intended for logging libraries rather than direct user configuration. The `@opentelemetry/api-logs` package is a peer dependency and must be installed separately. If it is not installed, OpenTelemetry logs functionality is not available. | ||
|
|
||
| Enable it by setting `DD_LOGS_OTEL_ENABLED=true` and use the [OpenTelemetry Logs API](https://open-telemetry.github.io/opentelemetry-js/modules/_opentelemetry_api-logs.html) to emit structured log data: | ||
|
|
||
| ```javascript | ||
| require('dd-trace').init() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ describe('opentelemetry', () => { | |
| let cwd | ||
| const timeout = 5000 | ||
| const dependencies = [ | ||
| '@opentelemetry/api@1.8.0', | ||
| '@opentelemetry/api@1.9.0', | ||
BridgeAR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| '@opentelemetry/instrumentation', | ||
| '@opentelemetry/instrumentation-http', | ||
| '@opentelemetry/[email protected]', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| 'use strict' | ||
|
|
||
| const log = require('../log') | ||
|
|
||
| /** | ||
| * Checks if OpenTelemetry Core and Resources peer dependencies are available. | ||
| * @returns {boolean} True if dependencies are available, false otherwise | ||
| */ | ||
| function checkOpenTelemetryHelpers () { | ||
| let available = true | ||
| try { | ||
| require.resolve('@opentelemetry/core') | ||
| } catch { | ||
| log.warn('Failed to resolve @opentelemetry/core. Install it with: npm install @opentelemetry/core') | ||
| available = false | ||
| } | ||
| try { | ||
| require.resolve('@opentelemetry/resources') | ||
| } catch { | ||
| log.warn('Failed to resolve @opentelemetry/resources. Install it with: npm install @opentelemetry/resources') | ||
| available = false | ||
| } | ||
| return available | ||
| } | ||
|
|
||
| /** | ||
| * Checks if OpenTelemetry peer dependencies are available. | ||
| * @returns {boolean} True if dependencies are available, false otherwise | ||
| */ | ||
| function checkOpenTelemetryAPIDeps () { | ||
| try { | ||
| require.resolve('@opentelemetry/api') | ||
| } catch { | ||
| log.warn('Failed to resolve @opentelemetry/api. Install it with: npm install @opentelemetry/api') | ||
| checkOpenTelemetryHelpers() | ||
| return false | ||
| } | ||
| return checkOpenTelemetryHelpers() | ||
| } | ||
|
|
||
| /** | ||
| * Checks if OpenTelemetry API Logs peer dependency is available. | ||
| * @returns {boolean} True if dependencies are available, false otherwise | ||
| */ | ||
| function checkOpenTelemetryLogsApiDeps () { | ||
| let available = checkOpenTelemetryAPIDeps() | ||
| try { | ||
| require.resolve('@opentelemetry/api-logs') | ||
| } catch { | ||
| log.warn('Failed to resolve @opentelemetry/api-logs. Install it with: npm install @opentelemetry/api-logs') | ||
| available = false | ||
| } | ||
| return available | ||
| } | ||
|
|
||
| module.exports = { | ||
| checkOpenTelemetryAPIDeps, | ||
| checkOpenTelemetryLogsApiDeps | ||
| } |
49 changes: 49 additions & 0 deletions
49
packages/dd-trace/src/opentelemetry/noop/tracer_provider.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 'use strict' | ||
|
|
||
| const noopSpan = { | ||
| spanContext: () => ({}), | ||
| setAttribute: () => {}, | ||
| setAttributes: () => {}, | ||
| addEvent: () => {}, | ||
| updateName: () => {}, | ||
| setStatus: () => {}, | ||
| end: () => {}, | ||
| isRecording: () => false | ||
| } | ||
|
|
||
| const noopTracer = { | ||
| startSpan: () => noopSpan, | ||
| startActiveSpan: () => noopSpan, | ||
| } | ||
|
|
||
| const noopSpanProcessor = { | ||
| onStart: () => {}, | ||
| onEnd: () => {}, | ||
| shutdown: () => Promise.resolve(), | ||
| forceFlush: () => Promise.resolve() | ||
| } | ||
|
|
||
| class NoopTracerProvider { | ||
| constructor (config = {}) { | ||
| this.config = config | ||
| this.resource = config.resource | ||
| } | ||
|
|
||
| getTracer () { | ||
| return noopTracer | ||
| } | ||
|
|
||
| addSpanProcessor () {} | ||
|
|
||
| getActiveSpanProcessor () { | ||
| return noopSpanProcessor | ||
| } | ||
|
|
||
| register () {} | ||
|
|
||
| forceFlush () {} | ||
|
|
||
| shutdown () {} | ||
| } | ||
|
|
||
| module.exports = NoopTracerProvider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.