autotel-adapters 2.0.29 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/next-config.cjs +87 -0
- package/dist/next-config.d.cts +47 -0
- package/dist/next-config.d.ts +47 -0
- package/dist/next-config.js +57 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -95,6 +95,29 @@ Navigation helpers such as `redirect()` and `notFound()` remain framework
|
|
|
95
95
|
control flow: `withAutotel()` rethrows their signals without recording a
|
|
96
96
|
phantom request error, including when a signal is wrapped in `cause`.
|
|
97
97
|
|
|
98
|
+
### `next.config`: one `@opentelemetry/api`
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// next.config.ts
|
|
102
|
+
import { withAutotelConfig } from 'autotel-adapters/next-config';
|
|
103
|
+
|
|
104
|
+
export default withAutotelConfig(
|
|
105
|
+
{ reactCompiler: true },
|
|
106
|
+
{ externals: ['@prisma/instrumentation'] }, // optional
|
|
107
|
+
);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Next bundles every server package it is not told to keep external. When autotel
|
|
111
|
+
and an instrumentation land on different sides of that line they run on two
|
|
112
|
+
copies of `@opentelemetry/api`. `withAutotelConfig` adds `@opentelemetry/api` (and `externals`) to
|
|
113
|
+
`serverExternalPackages`, so every bundle loads the app's one copy.
|
|
114
|
+
|
|
115
|
+
Each of them must be a dependency of the app: Next bundles a listed
|
|
116
|
+
package it cannot resolve from the app directory, which is what happens to a
|
|
117
|
+
workspace package's dependency in a monorepo. `withAutotelConfig` fails the
|
|
118
|
+
build instead. `autotel-adapters/next-config` has no runtime dependency, so
|
|
119
|
+
`next.config.ts` can import it.
|
|
120
|
+
|
|
98
121
|
## Nitro
|
|
99
122
|
|
|
100
123
|
```ts
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
let node_path = require("node:path");
|
|
30
|
+
node_path = __toESM(node_path, 1);
|
|
31
|
+
let node_fs = require("node:fs");
|
|
32
|
+
node_fs = __toESM(node_fs, 1);
|
|
33
|
+
|
|
34
|
+
//#region src/next-config.ts
|
|
35
|
+
/**
|
|
36
|
+
* Next.js config for autotel: one `@opentelemetry/api` for every bundle.
|
|
37
|
+
*
|
|
38
|
+
* When autotel and an instrumentation (`@prisma/instrumentation`) land on
|
|
39
|
+
* different sides of the bundle, they run on two copies of
|
|
40
|
+
* `@opentelemetry/api`. Next bundles every package it is not told to
|
|
41
|
+
* externalize, including a listed one it cannot resolve from the app (a
|
|
42
|
+
* workspace package's dependency, or a workspace link).
|
|
43
|
+
*
|
|
44
|
+
* Externalizing `@opentelemetry/api` itself gives every package the app's one
|
|
45
|
+
* copy at runtime, bundled or not. This module has no runtime dependency, so
|
|
46
|
+
* `next.config.ts` can import it.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Add `@opentelemetry/api` (and `externals`) to `serverExternalPackages`.
|
|
50
|
+
*
|
|
51
|
+
* Throws when one is not resolvable from the app, since Next would bundle it.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // next.config.ts
|
|
56
|
+
* import { withAutotelConfig } from 'autotel-adapters/next-config';
|
|
57
|
+
*
|
|
58
|
+
* export default withAutotelConfig(
|
|
59
|
+
* { reactCompiler: true },
|
|
60
|
+
* { externals: ['@prisma/instrumentation'] },
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function withAutotelConfig(config, options = {}) {
|
|
65
|
+
const projectDir = options.projectDir ?? process.cwd();
|
|
66
|
+
const wanted = ["@opentelemetry/api", ...options.externals ?? []];
|
|
67
|
+
const missing = wanted.filter((name) => !resolvableFrom(projectDir, name));
|
|
68
|
+
if (missing.length > 0) throw new Error(`[autotel] ${missing.join(", ")} must be resolvable from ${projectDir} for Next.js to keep it external; otherwise Next bundles it without a warning and autotel can end up on a second @opentelemetry/api copy. Add ${missing.length === 1 ? "it" : "them"} to the dependencies of this app.`);
|
|
69
|
+
return {
|
|
70
|
+
...config,
|
|
71
|
+
serverExternalPackages: [.../* @__PURE__ */ new Set([...config.serverExternalPackages ?? [], ...wanted])]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Whether `name` is installed where a bundler looks from `dir`: a
|
|
76
|
+
* `node_modules/<name>` here or in a parent. `require.resolve` also reads
|
|
77
|
+
* NODE_PATH, which pnpm sets for scripts and Next's resolver ignores.
|
|
78
|
+
*/
|
|
79
|
+
function resolvableFrom(dir, name) {
|
|
80
|
+
for (let current = node_path.resolve(dir);; current = node_path.dirname(current)) {
|
|
81
|
+
if (node_fs.existsSync(node_path.join(current, "node_modules", name, "package.json"))) return true;
|
|
82
|
+
if (node_path.dirname(current) === current) return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
exports.withAutotelConfig = withAutotelConfig;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/next-config.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Next.js config for autotel: one `@opentelemetry/api` for every bundle.
|
|
4
|
+
*
|
|
5
|
+
* When autotel and an instrumentation (`@prisma/instrumentation`) land on
|
|
6
|
+
* different sides of the bundle, they run on two copies of
|
|
7
|
+
* `@opentelemetry/api`. Next bundles every package it is not told to
|
|
8
|
+
* externalize, including a listed one it cannot resolve from the app (a
|
|
9
|
+
* workspace package's dependency, or a workspace link).
|
|
10
|
+
*
|
|
11
|
+
* Externalizing `@opentelemetry/api` itself gives every package the app's one
|
|
12
|
+
* copy at runtime, bundled or not. This module has no runtime dependency, so
|
|
13
|
+
* `next.config.ts` can import it.
|
|
14
|
+
*/
|
|
15
|
+
/** The part of a Next.js config this reads and writes. */
|
|
16
|
+
export interface NextConfigLike {
|
|
17
|
+
serverExternalPackages?: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface AutotelNextConfigOptions {
|
|
20
|
+
/**
|
|
21
|
+
* More packages to keep external, e.g. `['@prisma/instrumentation']`.
|
|
22
|
+
* `@opentelemetry/api` is always included.
|
|
23
|
+
*/
|
|
24
|
+
externals?: string[];
|
|
25
|
+
/** The app's directory, for checking each package resolves. Default: cwd. */
|
|
26
|
+
projectDir?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Add `@opentelemetry/api` (and `externals`) to `serverExternalPackages`.
|
|
30
|
+
*
|
|
31
|
+
* Throws when one is not resolvable from the app, since Next would bundle it.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // next.config.ts
|
|
36
|
+
* import { withAutotelConfig } from 'autotel-adapters/next-config';
|
|
37
|
+
*
|
|
38
|
+
* export default withAutotelConfig(
|
|
39
|
+
* { reactCompiler: true },
|
|
40
|
+
* { externals: ['@prisma/instrumentation'] },
|
|
41
|
+
* );
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function withAutotelConfig<T extends object>(config: T & NextConfigLike, options?: AutotelNextConfigOptions): T & {
|
|
45
|
+
serverExternalPackages: string[];
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/next-config.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Next.js config for autotel: one `@opentelemetry/api` for every bundle.
|
|
4
|
+
*
|
|
5
|
+
* When autotel and an instrumentation (`@prisma/instrumentation`) land on
|
|
6
|
+
* different sides of the bundle, they run on two copies of
|
|
7
|
+
* `@opentelemetry/api`. Next bundles every package it is not told to
|
|
8
|
+
* externalize, including a listed one it cannot resolve from the app (a
|
|
9
|
+
* workspace package's dependency, or a workspace link).
|
|
10
|
+
*
|
|
11
|
+
* Externalizing `@opentelemetry/api` itself gives every package the app's one
|
|
12
|
+
* copy at runtime, bundled or not. This module has no runtime dependency, so
|
|
13
|
+
* `next.config.ts` can import it.
|
|
14
|
+
*/
|
|
15
|
+
/** The part of a Next.js config this reads and writes. */
|
|
16
|
+
export interface NextConfigLike {
|
|
17
|
+
serverExternalPackages?: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface AutotelNextConfigOptions {
|
|
20
|
+
/**
|
|
21
|
+
* More packages to keep external, e.g. `['@prisma/instrumentation']`.
|
|
22
|
+
* `@opentelemetry/api` is always included.
|
|
23
|
+
*/
|
|
24
|
+
externals?: string[];
|
|
25
|
+
/** The app's directory, for checking each package resolves. Default: cwd. */
|
|
26
|
+
projectDir?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Add `@opentelemetry/api` (and `externals`) to `serverExternalPackages`.
|
|
30
|
+
*
|
|
31
|
+
* Throws when one is not resolvable from the app, since Next would bundle it.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // next.config.ts
|
|
36
|
+
* import { withAutotelConfig } from 'autotel-adapters/next-config';
|
|
37
|
+
*
|
|
38
|
+
* export default withAutotelConfig(
|
|
39
|
+
* { reactCompiler: true },
|
|
40
|
+
* { externals: ['@prisma/instrumentation'] },
|
|
41
|
+
* );
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function withAutotelConfig<T extends object>(config: T & NextConfigLike, options?: AutotelNextConfigOptions): T & {
|
|
45
|
+
serverExternalPackages: string[];
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
|
|
4
|
+
//#region src/next-config.ts
|
|
5
|
+
/**
|
|
6
|
+
* Next.js config for autotel: one `@opentelemetry/api` for every bundle.
|
|
7
|
+
*
|
|
8
|
+
* When autotel and an instrumentation (`@prisma/instrumentation`) land on
|
|
9
|
+
* different sides of the bundle, they run on two copies of
|
|
10
|
+
* `@opentelemetry/api`. Next bundles every package it is not told to
|
|
11
|
+
* externalize, including a listed one it cannot resolve from the app (a
|
|
12
|
+
* workspace package's dependency, or a workspace link).
|
|
13
|
+
*
|
|
14
|
+
* Externalizing `@opentelemetry/api` itself gives every package the app's one
|
|
15
|
+
* copy at runtime, bundled or not. This module has no runtime dependency, so
|
|
16
|
+
* `next.config.ts` can import it.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Add `@opentelemetry/api` (and `externals`) to `serverExternalPackages`.
|
|
20
|
+
*
|
|
21
|
+
* Throws when one is not resolvable from the app, since Next would bundle it.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // next.config.ts
|
|
26
|
+
* import { withAutotelConfig } from 'autotel-adapters/next-config';
|
|
27
|
+
*
|
|
28
|
+
* export default withAutotelConfig(
|
|
29
|
+
* { reactCompiler: true },
|
|
30
|
+
* { externals: ['@prisma/instrumentation'] },
|
|
31
|
+
* );
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function withAutotelConfig(config, options = {}) {
|
|
35
|
+
const projectDir = options.projectDir ?? process.cwd();
|
|
36
|
+
const wanted = ["@opentelemetry/api", ...options.externals ?? []];
|
|
37
|
+
const missing = wanted.filter((name) => !resolvableFrom(projectDir, name));
|
|
38
|
+
if (missing.length > 0) throw new Error(`[autotel] ${missing.join(", ")} must be resolvable from ${projectDir} for Next.js to keep it external; otherwise Next bundles it without a warning and autotel can end up on a second @opentelemetry/api copy. Add ${missing.length === 1 ? "it" : "them"} to the dependencies of this app.`);
|
|
39
|
+
return {
|
|
40
|
+
...config,
|
|
41
|
+
serverExternalPackages: [.../* @__PURE__ */ new Set([...config.serverExternalPackages ?? [], ...wanted])]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether `name` is installed where a bundler looks from `dir`: a
|
|
46
|
+
* `node_modules/<name>` here or in a parent. `require.resolve` also reads
|
|
47
|
+
* NODE_PATH, which pnpm sets for scripts and Next's resolver ignores.
|
|
48
|
+
*/
|
|
49
|
+
function resolvableFrom(dir, name) {
|
|
50
|
+
for (let current = path.resolve(dir);; current = path.dirname(current)) {
|
|
51
|
+
if (fs.existsSync(path.join(current, "node_modules", name, "package.json"))) return true;
|
|
52
|
+
if (path.dirname(current) === current) return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { withAutotelConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autotel-adapters",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Framework adapters and composable DX helpers for autotel",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
"import": "./dist/next.js",
|
|
34
34
|
"require": "./dist/next.cjs"
|
|
35
35
|
},
|
|
36
|
+
"./next-config": {
|
|
37
|
+
"types": "./dist/next-config.d.ts",
|
|
38
|
+
"import": "./dist/next-config.js",
|
|
39
|
+
"require": "./dist/next-config.cjs"
|
|
40
|
+
},
|
|
36
41
|
"./nitro": {
|
|
37
42
|
"types": "./dist/nitro.d.ts",
|
|
38
43
|
"import": "./dist/nitro.js",
|
|
@@ -86,8 +91,8 @@
|
|
|
86
91
|
"NOTICE"
|
|
87
92
|
],
|
|
88
93
|
"dependencies": {
|
|
89
|
-
"autotel": "8.
|
|
90
|
-
"autotel-edge": "6.1.
|
|
94
|
+
"autotel": "8.4.0",
|
|
95
|
+
"autotel-edge": "6.1.3"
|
|
91
96
|
},
|
|
92
97
|
"peerDependencies": {
|
|
93
98
|
"hono": ">=4.13.13",
|