Skip to content

Commit 78bff46

Browse files
committed
docs(openfeature): document ESM-resolvable fallback entrypoint
Node's ESM resolver does not append `.js` to package subpaths without an exports map, so the extensionless fallback fails before file tracing starts. Pin both the ESM import and automatic nft discovery from the default entrypoint.
1 parent e9dc87b commit 78bff46

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ When using the experimental OpenFeature provider, file-traced deployments can fo
9797
its dependencies into the output with a side-effect import before accessing `tracer.openfeature`:
9898

9999
```js
100-
import 'dd-trace/openfeature'
100+
import 'dd-trace/openfeature.js'
101101
```
102102

103103
This is a fallback for build tools that do not recognize the provider's optional-require wrapper.

packages/dd-trace/test/openfeature/file-tracing.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict'
22

33
const assert = require('node:assert/strict')
4+
const { spawnSync } = require('node:child_process')
5+
const { mkdirSync, mkdtempSync, rmSync, symlinkSync } = require('node:fs')
6+
const { tmpdir } = require('node:os')
47
const path = require('node:path')
58

69
const { nodeFileTrace } = require('@vercel/nft')
@@ -25,6 +28,10 @@ async function assertTracesProvider (entrypoint) {
2528
}
2629

2730
describe('OpenFeature file tracing', () => {
31+
it('traces the provider dependency tree through the default entrypoint', async () => {
32+
await assertTracesProvider(path.join(repoRoot, 'index.js'))
33+
})
34+
2835
it('traces the provider dependency tree through the runtime wrapper', async () => {
2936
await assertTracesProvider(path.join(repoRoot, 'packages/dd-trace/src/openfeature/flagging_provider.js'))
3037
})
@@ -36,4 +43,23 @@ describe('OpenFeature file tracing', () => {
3643
it('loads the provider through the explicit entrypoint', () => {
3744
require(path.join(repoRoot, 'openfeature.js'))
3845
})
46+
47+
it('loads the explicit entrypoint as an ESM package subpath', () => {
48+
const fixtureRoot = mkdtempSync(path.join(tmpdir(), 'dd-trace-openfeature-'))
49+
const nodeModulesPath = path.join(fixtureRoot, 'node_modules')
50+
51+
try {
52+
mkdirSync(nodeModulesPath)
53+
symlinkSync(repoRoot, path.join(nodeModulesPath, 'dd-trace'), 'junction')
54+
const result = spawnSync(
55+
process.execPath,
56+
['--input-type=module', '--eval', "import 'dd-trace/openfeature.js'"],
57+
{ cwd: fixtureRoot, encoding: 'utf8' }
58+
)
59+
60+
assert.strictEqual(result.status, 0, result.stderr)
61+
} finally {
62+
rmSync(fixtureRoot, { recursive: true, force: true })
63+
}
64+
})
3965
})

0 commit comments

Comments
 (0)