Skip to content

Commit fc23ba0

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`. `index.d.ts` imports from `"opentracing"` directly and the package becomes a regular runtime dependency. npm, yarn, and pnpm hoist a single copy that both dd-trace and the consumer resolve to, and TypeScript dedupes the nominal class identity by `name@version` Package ID, so `initGlobalTracer(tracer)` accepts dd-trace's `Tracer`. The range is `>=0.14.0` rather than `>=0.14.7` to widen the hoist window for consumers pinned to an older patch — the repository was archived on 2023-05-23 and the type surface is identical across 0.14.0–0.14.7. 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 fc23ba0

10 files changed

Lines changed: 8 additions & 27 deletions

File tree

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@
161161
],
162162
"dependencies": {
163163
"dc-polyfill": "^0.1.11",
164-
"import-in-the-middle": "^3.0.1"
164+
"import-in-the-middle": "^3.0.1",
165+
"opentracing": ">=0.14.0"
165166
},
166167
"optionalDependencies": {
167168
"@datadog/libdatadog": "0.9.3",
@@ -218,7 +219,6 @@
218219
"node-preload": "^0.2.1",
219220
"nyc": "^18.0.0",
220221
"octokit": "^5.0.3",
221-
"opentracing": ">=0.14.7",
222222
"p-limit": "^7.2.0",
223223
"proxyquire": "^2.1.3",
224224
"retry": "^0.13.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",

vendor/rspack.config.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ module.exports = {
8080
}),
8181
new CopyRspackPlugin({
8282
patterns: [
83-
// The OpenTracing types are exposed in the public API of dd-trace so
84-
// they need to be available in the package.
85-
{
86-
from: '**/*.d.ts',
87-
context: join(__dirname, 'node_modules', 'opentracing', 'lib'),
88-
to: 'opentracing'
89-
},
9083
// Binaries need to be copied manually.
9184
{
9285
from: 'source-map/lib/mappings.wasm',

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3435,7 +3435,7 @@ once@^1.4.0:
34353435
dependencies:
34363436
wrappy "1"
34373437

3438-
opentracing@>=0.14.7:
3438+
opentracing@>=0.14.0:
34393439
version "0.14.7"
34403440
resolved "https://registry.yarnpkg.com/opentracing/-/opentracing-0.14.7.tgz#25d472bd0296dc0b64d7b94cbc995219031428f5"
34413441
integrity sha512-vz9iS7MJ5+Bp1URw8Khvdyw1H/hGvzHWlKQ7eRrQojSCDL1/SrWfrY9QebLw97n2deyRtzHRC3MkQfVNUCo91Q==

0 commit comments

Comments
 (0)