Skip to content

Commit c0959cf

Browse files
committed
fix(types): import opentracing from the consumer's installed package
`opentracing.initGlobalTracer(tracer)` fails to type-check because dd-trace's public types reach into `./vendor/dist/opentracing` while consumers reach into their own `node_modules/opentracing`. `Reference` / `Tracer` / `Span` declare `protected` members, so the two copies are nominally distinct classes and the dd-trace `Tracer` is not a subtype of the consumer's `opentracing.Tracer`. Type imports reference `opentracing` directly again and the package becomes an optional peer dependency so consumers using the integration share a single class identity with dd-trace's types without forcing every install to pull in opentracing. The vendored type copy and its rspack build step are dropped; dd-trace's runtime never required the package. Fixes: #8523 Refs: #6958
1 parent 806f177 commit c0959cf

11 files changed

Lines changed: 15 additions & 25 deletions

File tree

LICENSE-3rdparty.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"mutexify","https://github.com/mafintosh/mutexify","['MIT']","['Mathias Buus']"
8484
"node-addon-api","https://github.com/nodejs/node-addon-api","['MIT']","['nodejs']"
8585
"node-gyp-build","https://github.com/prebuild/node-gyp-build","['MIT']","['Mathias Buus']"
86-
"opentracing","https://github.com/opentracing/opentracing-javascript","['Apache-2.0']","['opentracing']"
8786
"oxc-parser","https://github.com/oxc-project/oxc","['MIT']","['Boshen and oxc contributors']"
8887
"pprof-format","https://github.com/DataDog/pprof-format","['MIT']","['Datadog Inc.']"
8988
"protobufjs","https://github.com/protobufjs/protobuf.js","['BSD-3-Clause']","['Daniel Wirtz']"

docs/API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ const opentracing = require('opentracing')
379379
opentracing.initGlobalTracer(tracer)
380380
```
381381

382+
`opentracing` is declared as an optional peer dependency and is not installed with `dd-trace`. Add it to your own dependencies (`npm install --save opentracing`) when using the OpenTracing API so the runtime and TypeScript types line up with the same package instance.
383+
382384
The following tags are available to override Datadog-specific options:
383385

384386
* `service.name`: The service name to be used for this span. The service name from the tracer will be used if this is not provided.

docs/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
SPAN_TYPE,
2626
} from '../ext/tags'
2727
import { HTTP, WEB } from '../ext/types'
28-
import * as opentracing from '../vendor/dist/opentracing';
28+
import * as opentracing from 'opentracing';
2929
import { IncomingMessage, OutgoingMessage } from 'http';
3030

3131
opentracing.initGlobalTracer(tracer);

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ClientRequest, IncomingMessage, OutgoingMessage, ServerResponse } from "http";
22
import { LookupFunction } from 'net';
3-
import * as opentracing from "./vendor/dist/opentracing";
3+
import * as opentracing from "opentracing";
44
import * as otel from "@opentelemetry/api";
55

66
/**

index.d.v5.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ClientRequest, IncomingMessage, OutgoingMessage, ServerResponse } from "http";
22
import { LookupFunction } from 'net';
3-
import * as opentracing from "./vendor/dist/opentracing";
3+
import * as opentracing from "opentracing";
44
import * as otel from "@opentelemetry/api";
55

66
/**

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@
163163
"dc-polyfill": "^0.1.11",
164164
"import-in-the-middle": "^3.0.1"
165165
},
166+
"peerDependencies": {
167+
"opentracing": ">=0.14.7"
168+
},
169+
"peerDependenciesMeta": {
170+
"opentracing": {
171+
"optional": true
172+
}
173+
},
166174
"optionalDependencies": {
167175
"@datadog/libdatadog": "0.9.3",
168176
"@datadog/native-appsec": "11.0.1",

packages/dd-trace/test/opentracing/tracer.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { describe, it, beforeEach } = require('mocha')
77
const sinon = require('sinon')
88
const proxyquire = require('proxyquire')
99

10-
const opentracing = require('../../../../vendor/dist/opentracing')
10+
const opentracing = require('opentracing')
1111
require('../setup/core')
1212
const SpanContext = require('../../src/opentracing/span_context')
1313
const formats = require('../../../../ext/formats')

packages/dd-trace/test/scope.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const assert = require('node:assert/strict')
55
const { describe, it, beforeEach } = require('mocha')
66
const sinon = require('sinon')
77

8-
const { Span } = require('../../../vendor/dist/opentracing')
8+
const { Span } = require('opentracing')
99
require('./setup/core')
1010
const Scope = require('../src/scope')
1111

vendor/package-lock.json

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"meriyah": "^6.1.4",
2323
"module-details-from-path": "^1.0.4",
2424
"mutexify": "^1.4.0",
25-
"opentracing": ">=0.14.7",
2625
"pprof-format": "^2.1.1",
2726
"protobufjs": "^8.0.1",
2827
"retry": "^0.13.1",

0 commit comments

Comments
 (0)