@watchtowerobservability/node 0.5.0 → 0.7.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 +88 -9
- package/dist/cjs/checkin.d.ts +7 -0
- package/dist/cjs/checkin.js +18 -0
- package/dist/cjs/env.d.ts +12 -0
- package/dist/cjs/env.js +37 -0
- package/dist/cjs/errors.d.ts +8 -0
- package/dist/cjs/errors.js +23 -0
- package/dist/cjs/filter.d.ts +2 -0
- package/dist/cjs/filter.js +16 -0
- package/dist/cjs/index.d.ts +48 -10
- package/dist/cjs/index.js +119 -53
- package/dist/cjs/instrument.d.ts +10 -0
- package/dist/cjs/instrument.js +74 -0
- package/dist/cjs/integrations/db.d.ts +3 -0
- package/dist/cjs/integrations/db.js +4 -1
- package/dist/cjs/integrations/genai-agents.d.ts +4 -1
- package/dist/cjs/integrations/genai-agents.js +27 -24
- package/dist/cjs/integrations/genai-frameworks.d.ts +25 -0
- package/dist/cjs/integrations/genai-frameworks.js +211 -0
- package/dist/cjs/integrations/genai.d.ts +1 -0
- package/dist/cjs/integrations/genai.js +7 -2
- package/dist/cjs/integrations/next-build.d.ts +31 -0
- package/dist/cjs/integrations/next-build.js +95 -0
- package/dist/cjs/integrations/next-tunnel.d.ts +14 -0
- package/dist/cjs/integrations/next-tunnel.js +52 -0
- package/dist/cjs/integrations/next.d.ts +24 -1
- package/dist/cjs/integrations/next.js +39 -7
- package/dist/cjs/load.js +37 -5
- package/dist/cjs/next-sourcemaps-cli.d.ts +2 -0
- package/dist/cjs/next-sourcemaps-cli.js +9 -0
- package/dist/cjs/origin.d.ts +9 -0
- package/dist/cjs/origin.js +43 -0
- package/dist/cjs/redact.d.ts +8 -0
- package/dist/cjs/redact.js +43 -0
- package/dist/cjs/register.d.ts +1 -0
- package/dist/cjs/register.js +29 -0
- package/dist/cjs/sampling.d.ts +53 -0
- package/dist/cjs/sampling.js +98 -0
- package/dist/cjs/scrub.d.ts +7 -0
- package/dist/cjs/scrub.js +39 -0
- package/dist/cjs/shutdown.d.ts +14 -0
- package/dist/cjs/shutdown.js +26 -0
- package/dist/cjs/sql.js +11 -1
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/esm/checkin.d.ts +7 -0
- package/dist/esm/checkin.js +15 -0
- package/dist/esm/env.d.ts +12 -0
- package/dist/esm/env.js +33 -0
- package/dist/esm/errors.d.ts +8 -0
- package/dist/esm/errors.js +22 -0
- package/dist/esm/filter.d.ts +2 -0
- package/dist/esm/filter.js +13 -0
- package/dist/esm/index.d.ts +48 -10
- package/dist/esm/index.js +117 -53
- package/dist/esm/instrument.d.ts +10 -0
- package/dist/esm/instrument.js +71 -0
- package/dist/esm/integrations/db.d.ts +3 -0
- package/dist/esm/integrations/db.js +5 -2
- package/dist/esm/integrations/genai-agents.d.ts +4 -1
- package/dist/esm/integrations/genai-agents.js +4 -4
- package/dist/esm/integrations/genai-frameworks.d.ts +25 -0
- package/dist/esm/integrations/genai-frameworks.js +206 -0
- package/dist/esm/integrations/genai.d.ts +1 -0
- package/dist/esm/integrations/genai.js +3 -1
- package/dist/esm/integrations/next-build.d.ts +31 -0
- package/dist/esm/integrations/next-build.js +58 -0
- package/dist/esm/integrations/next-tunnel.d.ts +14 -0
- package/dist/esm/integrations/next-tunnel.js +49 -0
- package/dist/esm/integrations/next.d.ts +24 -1
- package/dist/esm/integrations/next.js +32 -6
- package/dist/esm/load.js +80 -2
- package/dist/esm/next-sourcemaps-cli.d.ts +2 -0
- package/dist/esm/next-sourcemaps-cli.js +7 -0
- package/dist/esm/origin.d.ts +9 -0
- package/dist/esm/origin.js +39 -0
- package/dist/esm/redact.d.ts +8 -0
- package/dist/esm/redact.js +39 -0
- package/dist/esm/register.d.ts +1 -0
- package/dist/esm/register.js +27 -0
- package/dist/esm/sampling.d.ts +53 -0
- package/dist/esm/sampling.js +91 -0
- package/dist/esm/scrub.d.ts +7 -0
- package/dist/esm/scrub.js +34 -0
- package/dist/esm/shutdown.d.ts +14 -0
- package/dist/esm/shutdown.js +23 -0
- package/dist/esm/sql.js +11 -1
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/package.json +40 -2
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.langchainCallbackHandler = langchainCallbackHandler;
|
|
4
|
+
exports.instrumentVercelAI = instrumentVercelAI;
|
|
5
|
+
exports.instrumentMastra = instrumentMastra;
|
|
6
|
+
// GenAI spans for the TypeScript agent frameworks: LangGraph.js (a LangChain.js callback handler), the Vercel AI SDK
|
|
7
|
+
// agent loop (generateText / streamText with several steps) and Mastra agents. Same shape as the Python
|
|
8
|
+
// instrumentors and `genai-agents.ts`: `invoke_agent` / `chat` / `execute_tool` spans, nested as the run nests,
|
|
9
|
+
// never any prompt, completion or tool argument text. CrewAI has no JavaScript port, so there is no CrewAI hook here.
|
|
10
|
+
// Nothing is imported from the frameworks: each function takes their object.
|
|
11
|
+
const api_1 = require("@opentelemetry/api");
|
|
12
|
+
const genai_agents_js_1 = require("./genai-agents.js");
|
|
13
|
+
const num = (v) => (typeof v === 'number' ? v : undefined);
|
|
14
|
+
const thenable = (v) => !!v && typeof v.then === 'function';
|
|
15
|
+
function fail(span, e) {
|
|
16
|
+
span.recordException(e);
|
|
17
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: e?.message });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* langchainCallbackHandler(): pass it as `callbacks: [handler]` to a LangChain.js model, chain or LangGraph.js graph
|
|
21
|
+
* (`graph.invoke(input, { callbacks: [handler] })`). LangGraph nodes (chains whose metadata names `langgraph_node`)
|
|
22
|
+
* and the graph itself become `invoke_agent` spans, tools `execute_tool`, model calls `chat`, nested as they run;
|
|
23
|
+
* plain LCEL chains get no span. Returns a plain handler object (LangChain wraps it) with the open spans for tests.
|
|
24
|
+
*/
|
|
25
|
+
function langchainCallbackHandler() {
|
|
26
|
+
const open = new Map(), up = new Map();
|
|
27
|
+
const begin = (runId, parentId, name, attrs) => {
|
|
28
|
+
up.set(runId, parentId);
|
|
29
|
+
let p = parentId;
|
|
30
|
+
while (p !== undefined && !open.has(p))
|
|
31
|
+
p = up.get(p); // a parent without a span: skip to its own parent
|
|
32
|
+
open.set(runId, (0, genai_agents_js_1.start)(name, attrs, p === undefined ? undefined : open.get(p)));
|
|
33
|
+
};
|
|
34
|
+
const close = (runId, error) => {
|
|
35
|
+
up.delete(runId);
|
|
36
|
+
const span = open.get(runId);
|
|
37
|
+
open.delete(runId);
|
|
38
|
+
if (span && error !== undefined)
|
|
39
|
+
fail(span, error);
|
|
40
|
+
return span;
|
|
41
|
+
};
|
|
42
|
+
const llmStart = (extra, llm) => (runId, parentId) => {
|
|
43
|
+
const p = (0, genai_agents_js_1.obj)((0, genai_agents_js_1.obj)(extra).invocation_params), k = (0, genai_agents_js_1.obj)((0, genai_agents_js_1.obj)(llm).kwargs);
|
|
44
|
+
const model = (0, genai_agents_js_1.s)(p.model) || (0, genai_agents_js_1.s)(p.model_name) || (0, genai_agents_js_1.s)(k.model) || (0, genai_agents_js_1.s)(k.modelName);
|
|
45
|
+
begin(runId, parentId, `chat ${model}`.trim(), { 'gen_ai.operation.name': 'chat', 'gen_ai.system': 'langchain', 'gen_ai.request.model': model });
|
|
46
|
+
};
|
|
47
|
+
const ender = (runId, error) => { close(runId, error)?.end(); };
|
|
48
|
+
const h = {
|
|
49
|
+
open,
|
|
50
|
+
handleChatModelStart: (llm, _m, runId, parentId, extra) => llmStart(extra, llm)(runId, parentId),
|
|
51
|
+
handleLLMStart: (llm, _p, runId, parentId, extra) => llmStart(extra, llm)(runId, parentId),
|
|
52
|
+
handleLLMEnd: (output, runId) => {
|
|
53
|
+
const span = close(runId);
|
|
54
|
+
if (!span)
|
|
55
|
+
return;
|
|
56
|
+
const o = (0, genai_agents_js_1.obj)(output), tu = (0, genai_agents_js_1.obj)((0, genai_agents_js_1.obj)(o.llmOutput).tokenUsage);
|
|
57
|
+
const first = Array.isArray(o.generations) && Array.isArray(o.generations[0]) ? (0, genai_agents_js_1.obj)(o.generations[0][0]) : {};
|
|
58
|
+
const msg = (0, genai_agents_js_1.obj)(first.message), um = (0, genai_agents_js_1.obj)(msg.usage_metadata), rm = (0, genai_agents_js_1.obj)(msg.response_metadata);
|
|
59
|
+
const input = num(tu.promptTokens) ?? num(um.input_tokens), out = num(tu.completionTokens) ?? num(um.output_tokens);
|
|
60
|
+
if (input !== undefined)
|
|
61
|
+
span.setAttribute('gen_ai.usage.input_tokens', input);
|
|
62
|
+
if (out !== undefined)
|
|
63
|
+
span.setAttribute('gen_ai.usage.output_tokens', out);
|
|
64
|
+
if ((0, genai_agents_js_1.s)(rm.model_name))
|
|
65
|
+
span.setAttribute('gen_ai.response.model', (0, genai_agents_js_1.s)(rm.model_name));
|
|
66
|
+
if ((0, genai_agents_js_1.s)(rm.finish_reason))
|
|
67
|
+
span.setAttribute('gen_ai.response.finish_reasons', [(0, genai_agents_js_1.s)(rm.finish_reason)]);
|
|
68
|
+
span.end();
|
|
69
|
+
},
|
|
70
|
+
handleLLMError: (e, runId) => ender(runId, e),
|
|
71
|
+
handleChainStart: (_c, _i, runId, parentId, _t, metadata, _rt, runName) => {
|
|
72
|
+
const m = (0, genai_agents_js_1.obj)(metadata), node = (0, genai_agents_js_1.s)(m.langgraph_node);
|
|
73
|
+
// only LangGraph runs get spans (the graph root and its nodes); plain LCEL chains are noise
|
|
74
|
+
if (!node && !(parentId === undefined && m.langgraph_step !== undefined)) {
|
|
75
|
+
up.set(runId, parentId);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const who = node && runName === node ? node : runName || node || 'graph';
|
|
79
|
+
begin(runId, parentId, `invoke_agent ${who}`, { 'gen_ai.operation.name': 'invoke_agent', 'gen_ai.agent.name': who, 'gen_ai.system': 'langgraph' });
|
|
80
|
+
},
|
|
81
|
+
handleChainEnd: (_o, runId) => ender(runId),
|
|
82
|
+
handleChainError: (e, runId) => ender(runId, e),
|
|
83
|
+
handleToolStart: (tool, _i, runId, parentId, _t, _m, runName) => {
|
|
84
|
+
const name = runName || (0, genai_agents_js_1.s)((0, genai_agents_js_1.obj)(tool).name) || (0, genai_agents_js_1.s)((0, genai_agents_js_1.obj)((0, genai_agents_js_1.obj)(tool).kwargs).name);
|
|
85
|
+
begin(runId, parentId, `execute_tool ${name}`.trim(), { 'gen_ai.operation.name': 'execute_tool', 'gen_ai.tool.name': name });
|
|
86
|
+
},
|
|
87
|
+
handleToolEnd: (_o, runId) => ender(runId),
|
|
88
|
+
handleToolError: (e, runId) => ender(runId, e),
|
|
89
|
+
};
|
|
90
|
+
return h;
|
|
91
|
+
}
|
|
92
|
+
/** Wraps every `execute` of an AI SDK / Mastra tool set so each call is an `execute_tool` span under the agent run. */
|
|
93
|
+
function wrapTools(tools, root) {
|
|
94
|
+
const out = {};
|
|
95
|
+
for (const [name, t] of Object.entries((0, genai_agents_js_1.obj)(tools))) {
|
|
96
|
+
const tool = (0, genai_agents_js_1.obj)(t), exec = tool.execute;
|
|
97
|
+
if (typeof exec !== 'function') {
|
|
98
|
+
out[name] = t;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
out[name] = {
|
|
102
|
+
...tool,
|
|
103
|
+
execute: (...a) => {
|
|
104
|
+
const sp = (0, genai_agents_js_1.start)(`execute_tool ${name}`, { 'gen_ai.operation.name': 'execute_tool', 'gen_ai.tool.name': name }, root);
|
|
105
|
+
const done = (e) => { if (e !== undefined)
|
|
106
|
+
fail(sp, e); sp.end(); };
|
|
107
|
+
try {
|
|
108
|
+
const r = exec.apply(tool, a);
|
|
109
|
+
if (thenable(r))
|
|
110
|
+
r.then(() => done(), (e) => done(e ?? new Error('tool failed')));
|
|
111
|
+
else
|
|
112
|
+
done();
|
|
113
|
+
return r;
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
done(e);
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* One agent run as an `invoke_agent` span. `onStepFinish` (injected, the caller's own still runs) turns every model
|
|
126
|
+
* step into a `chat` span with usage, timed from the previous step's end; tool `execute` calls become
|
|
127
|
+
* `execute_tool` spans. `optsAt` is the position of the options argument. A stream ends the run in `onFinish` /
|
|
128
|
+
* `onError`; a promise ends it when it settles.
|
|
129
|
+
*/
|
|
130
|
+
function agentRun(system, name, orig, self, args, optsAt, stream) {
|
|
131
|
+
const root = (0, genai_agents_js_1.start)(`invoke_agent ${name}`.trim(), { 'gen_ai.operation.name': 'invoke_agent', 'gen_ai.agent.name': name, 'gen_ai.system': system });
|
|
132
|
+
let ended = false, last = Date.now();
|
|
133
|
+
const end = (e) => { if (ended)
|
|
134
|
+
return; ended = true; if (e !== undefined)
|
|
135
|
+
fail(root, e); root.end(); };
|
|
136
|
+
const opts = { ...(0, genai_agents_js_1.obj)(args[optsAt]) };
|
|
137
|
+
const onStep = opts.onStepFinish, onFinish = opts.onFinish, onError = opts.onError;
|
|
138
|
+
opts.onStepFinish = (e) => {
|
|
139
|
+
const d = (0, genai_agents_js_1.obj)(e), u = (0, genai_agents_js_1.obj)(d.usage), r = (0, genai_agents_js_1.obj)(d.response);
|
|
140
|
+
const model = (0, genai_agents_js_1.s)(r.modelId) || (0, genai_agents_js_1.s)(r.model) || (0, genai_agents_js_1.s)(d.model);
|
|
141
|
+
const sp = (0, genai_agents_js_1.start)(`chat ${model}`.trim(), { 'gen_ai.operation.name': 'chat', 'gen_ai.system': system, 'gen_ai.response.model': model }, root, last);
|
|
142
|
+
const input = num(u.inputTokens) ?? num(u.promptTokens), out = num(u.outputTokens) ?? num(u.completionTokens);
|
|
143
|
+
if (input !== undefined)
|
|
144
|
+
sp.setAttribute('gen_ai.usage.input_tokens', input);
|
|
145
|
+
if (out !== undefined)
|
|
146
|
+
sp.setAttribute('gen_ai.usage.output_tokens', out);
|
|
147
|
+
if ((0, genai_agents_js_1.s)(d.finishReason))
|
|
148
|
+
sp.setAttribute('gen_ai.response.finish_reasons', [(0, genai_agents_js_1.s)(d.finishReason)]);
|
|
149
|
+
sp.end();
|
|
150
|
+
last = Date.now();
|
|
151
|
+
return onStep?.(e);
|
|
152
|
+
};
|
|
153
|
+
if (stream) {
|
|
154
|
+
opts.onFinish = (e) => { end(); return onFinish?.(e); };
|
|
155
|
+
opts.onError = (e) => { end((0, genai_agents_js_1.obj)(e).error ?? e ?? new Error('stream failed')); return onError?.(e); };
|
|
156
|
+
}
|
|
157
|
+
if (opts.tools)
|
|
158
|
+
opts.tools = wrapTools(opts.tools, root);
|
|
159
|
+
const a = [...args];
|
|
160
|
+
a[optsAt] = opts;
|
|
161
|
+
let res;
|
|
162
|
+
try {
|
|
163
|
+
res = api_1.context.with(api_1.trace.setSpan(api_1.context.active(), root), () => orig.apply(self, a));
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
end(e);
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
if (!stream) {
|
|
170
|
+
// side branch only: the caller keeps the framework's own promise
|
|
171
|
+
if (thenable(res))
|
|
172
|
+
res.then(() => end(), (e) => end(e ?? new Error('run failed')));
|
|
173
|
+
else
|
|
174
|
+
end();
|
|
175
|
+
}
|
|
176
|
+
return res;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* instrumentVercelAI({ generateText, streamText }) with the functions from `ai`: returns wrapped copies (ES module
|
|
180
|
+
* exports cannot be patched). Pass `agentName` to name the run (default: the `experimental_telemetry.functionId`, else `agent`).
|
|
181
|
+
* const { generateText } = instrumentVercelAI({ generateText: ai.generateText });
|
|
182
|
+
* A multi-step loop (`maxSteps` / `stopWhen`) gives one `invoke_agent` span with a `chat` span per step and an
|
|
183
|
+
* `execute_tool` span per tool call.
|
|
184
|
+
*/
|
|
185
|
+
function instrumentVercelAI(ai, agentName) {
|
|
186
|
+
const out = { ...ai };
|
|
187
|
+
const nameOf = (a) => agentName || (0, genai_agents_js_1.s)((0, genai_agents_js_1.obj)((0, genai_agents_js_1.obj)(a[0]).experimental_telemetry).functionId) || 'agent';
|
|
188
|
+
if (typeof ai.generateText === 'function') {
|
|
189
|
+
const f = ai.generateText;
|
|
190
|
+
out.generateText = function (...a) { return agentRun('vercel_ai', nameOf(a), f, this, a, 0, false); };
|
|
191
|
+
}
|
|
192
|
+
if (typeof ai.streamText === 'function') {
|
|
193
|
+
const f = ai.streamText;
|
|
194
|
+
out.streamText = function (...a) { return agentRun('vercel_ai', nameOf(a), f, this, a, 0, true); };
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
/** instrumentMastra(agent): wraps `agent.generate` and `agent.stream` of a Mastra `Agent`; the run is named after the agent. Returns the agent. */
|
|
199
|
+
function instrumentMastra(agent) {
|
|
200
|
+
const a = agent;
|
|
201
|
+
const name = (0, genai_agents_js_1.s)(a.name) || 'agent';
|
|
202
|
+
for (const [method, stream] of [['generate', false], ['stream', true]]) {
|
|
203
|
+
const f = a[method];
|
|
204
|
+
if (typeof f !== 'function' || f.__wt)
|
|
205
|
+
continue;
|
|
206
|
+
const wrapped = function (...args) { return agentRun('mastra', name, f, this, args, 1, stream); };
|
|
207
|
+
wrapped.__wt = true;
|
|
208
|
+
a[method] = wrapped;
|
|
209
|
+
}
|
|
210
|
+
return agent;
|
|
211
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { instrumentLlamaIndex, instrumentOpenAIAgents } from './genai-agents.js';
|
|
2
|
+
export { instrumentMastra, instrumentVercelAI, langchainCallbackHandler } from './genai-frameworks.js';
|
|
2
3
|
/**
|
|
3
4
|
* instrumentOpenAI(new OpenAI()): chat.completions.create and responses.create. Returns the client.
|
|
4
5
|
* For an OpenAI-compatible gateway pass its name: instrumentOpenAI(new OpenAI({ baseURL: litellmUrl }), 'litellm').
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.instrumentOpenAIAgents = exports.instrumentLlamaIndex = void 0;
|
|
3
|
+
exports.langchainCallbackHandler = exports.instrumentVercelAI = exports.instrumentMastra = exports.instrumentOpenAIAgents = exports.instrumentLlamaIndex = void 0;
|
|
4
4
|
exports.instrumentOpenAI = instrumentOpenAI;
|
|
5
5
|
exports.instrumentBedrock = instrumentBedrock;
|
|
6
6
|
exports.instrumentGoogleGenAI = instrumentGoogleGenAI;
|
|
@@ -9,7 +9,8 @@ exports.instrumentMistral = instrumentMistral;
|
|
|
9
9
|
exports.instrumentOllama = instrumentOllama;
|
|
10
10
|
exports.vercelAiTelemetry = vercelAiTelemetry;
|
|
11
11
|
// GenAI spans (OTel GenAI semconv) for the openai, anthropic, AWS Bedrock, Google GenAI, Mistral and Ollama SDKs (and
|
|
12
|
-
// LiteLLM through its OpenAI-compatible proxy), LlamaIndex and the OpenAI Agents SDK (genai-agents.ts),
|
|
12
|
+
// LiteLLM through its OpenAI-compatible proxy), LlamaIndex and the OpenAI Agents SDK (genai-agents.ts), LangGraph.js,
|
|
13
|
+
// Mastra and the Vercel AI SDK agent loop (genai-frameworks.ts), and a
|
|
13
14
|
// telemetry option for the Vercel AI SDK. Streams record time to first chunk, usage and tool calls (genai-stream.ts).
|
|
14
15
|
// Prompt and completion text is never recorded.
|
|
15
16
|
const api_1 = require("@opentelemetry/api");
|
|
@@ -17,6 +18,10 @@ const genai_stream_js_1 = require("./genai-stream.js");
|
|
|
17
18
|
var genai_agents_js_1 = require("./genai-agents.js");
|
|
18
19
|
Object.defineProperty(exports, "instrumentLlamaIndex", { enumerable: true, get: function () { return genai_agents_js_1.instrumentLlamaIndex; } });
|
|
19
20
|
Object.defineProperty(exports, "instrumentOpenAIAgents", { enumerable: true, get: function () { return genai_agents_js_1.instrumentOpenAIAgents; } });
|
|
21
|
+
var genai_frameworks_js_1 = require("./genai-frameworks.js");
|
|
22
|
+
Object.defineProperty(exports, "instrumentMastra", { enumerable: true, get: function () { return genai_frameworks_js_1.instrumentMastra; } });
|
|
23
|
+
Object.defineProperty(exports, "instrumentVercelAI", { enumerable: true, get: function () { return genai_frameworks_js_1.instrumentVercelAI; } });
|
|
24
|
+
Object.defineProperty(exports, "langchainCallbackHandler", { enumerable: true, get: function () { return genai_frameworks_js_1.langchainCallbackHandler; } });
|
|
20
25
|
const DONE = Symbol('wt.instrumented');
|
|
21
26
|
const plain = (b) => (b || {});
|
|
22
27
|
function wrap(target, method, system, req = plain) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface SourcemapOptions {
|
|
2
|
+
/** Directory holding the client build; default `.next/static`. */
|
|
3
|
+
dir?: string;
|
|
4
|
+
/** Default WT_API_URL, then https://api.watchtower.observer. */
|
|
5
|
+
apiUrl?: string;
|
|
6
|
+
/** A key with scope `ci:write` (it covers releases and artifacts; `admin:write` also works). Default WT_API_KEY. */
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
/** Project id or slug the maps belong to. Default WT_PROJECT. */
|
|
9
|
+
project?: string;
|
|
10
|
+
/** Release version: must equal the `release` the browser SDK reports. Default WT_RELEASE. */
|
|
11
|
+
release?: string;
|
|
12
|
+
/** Keep the .map files after a successful upload (default: delete them so they are never served). */
|
|
13
|
+
keep?: boolean;
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
log?: (line: string) => void;
|
|
16
|
+
}
|
|
17
|
+
type NextConfig = Record<string, unknown>;
|
|
18
|
+
type ConfigOrFn = NextConfig | ((...a: unknown[]) => NextConfig | Promise<NextConfig>);
|
|
19
|
+
/**
|
|
20
|
+
* `module.exports = withWatchtower(nextConfig, { sourcemaps: true })`: turns on `productionBrowserSourceMaps` so
|
|
21
|
+
* `next build` writes client maps (works with webpack and Turbopack). Then run `wt-next-sourcemaps` after the build
|
|
22
|
+
* (`"build": "next build && wt-next-sourcemaps"`) to upload them and delete the .map files from `.next/static`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withWatchtower(config?: ConfigOrFn, opts?: {
|
|
25
|
+
sourcemaps?: boolean;
|
|
26
|
+
}): ConfigOrFn;
|
|
27
|
+
/** Upload every `.map` under `dir` as `_next/static/<path>` for the release, then delete them. Throws (leaving the files) when an upload fails. */
|
|
28
|
+
export declare function uploadSourcemaps(o?: SourcemapOptions): Promise<{
|
|
29
|
+
uploaded: number;
|
|
30
|
+
}>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.withWatchtower = withWatchtower;
|
|
37
|
+
exports.uploadSourcemaps = uploadSourcemaps;
|
|
38
|
+
// Build-time helpers for Next.js: `withWatchtower` (next.config) and `uploadSourcemaps` (after `next build`).
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const nodePath = __importStar(require("node:path"));
|
|
41
|
+
/**
|
|
42
|
+
* `module.exports = withWatchtower(nextConfig, { sourcemaps: true })`: turns on `productionBrowserSourceMaps` so
|
|
43
|
+
* `next build` writes client maps (works with webpack and Turbopack). Then run `wt-next-sourcemaps` after the build
|
|
44
|
+
* (`"build": "next build && wt-next-sourcemaps"`) to upload them and delete the .map files from `.next/static`.
|
|
45
|
+
*/
|
|
46
|
+
function withWatchtower(config = {}, opts = {}) {
|
|
47
|
+
const apply = (c) => (opts.sourcemaps ? { ...c, productionBrowserSourceMaps: true } : c);
|
|
48
|
+
if (typeof config !== 'function')
|
|
49
|
+
return apply(config);
|
|
50
|
+
return async (...a) => apply(await config(...a));
|
|
51
|
+
}
|
|
52
|
+
function* maps(dir) {
|
|
53
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
54
|
+
const p = nodePath.join(dir, e.name);
|
|
55
|
+
if (e.isDirectory())
|
|
56
|
+
yield* maps(p);
|
|
57
|
+
else if (e.name.endsWith('.map'))
|
|
58
|
+
yield p;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Upload every `.map` under `dir` as `_next/static/<path>` for the release, then delete them. Throws (leaving the files) when an upload fails. */
|
|
62
|
+
async function uploadSourcemaps(o = {}) {
|
|
63
|
+
const env = process.env;
|
|
64
|
+
const key = o.apiKey || env.WT_API_KEY;
|
|
65
|
+
const project = o.project || env.WT_PROJECT;
|
|
66
|
+
const release = o.release || env.WT_RELEASE;
|
|
67
|
+
if (!key)
|
|
68
|
+
throw new Error('WT_API_KEY is required (a key with scope ci:write)');
|
|
69
|
+
if (!project)
|
|
70
|
+
throw new Error('WT_PROJECT (project id) is required');
|
|
71
|
+
if (!release)
|
|
72
|
+
throw new Error('WT_RELEASE is required');
|
|
73
|
+
const dir = nodePath.resolve(o.dir || '.next/static');
|
|
74
|
+
const f = o.fetch || fetch;
|
|
75
|
+
const log = o.log || (() => { });
|
|
76
|
+
const root = `${(o.apiUrl || env.WT_API_URL || 'https://api.watchtower.observer').replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(project)}`;
|
|
77
|
+
const call = async (path, init, okStatus = []) => {
|
|
78
|
+
const res = await f(root + path, { ...init, headers: { authorization: `Bearer ${key}`, ...init.headers } });
|
|
79
|
+
if (!res.ok && !okStatus.includes(res.status))
|
|
80
|
+
throw new Error(`watchtower ${init.method} ${path.split('?')[0]} -> HTTP ${res.status}`);
|
|
81
|
+
};
|
|
82
|
+
const files = fs.existsSync(dir) ? [...maps(dir)] : [];
|
|
83
|
+
await call('/releases', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ version: release }) }, [409]); // 409: exists
|
|
84
|
+
for (const file of files) {
|
|
85
|
+
const name = `_next/static/${nodePath.relative(dir, file).split(nodePath.sep).join('/')}`;
|
|
86
|
+
await call(`/artifacts?${new URLSearchParams({ kind: 'sourcemap', name, release })}`, {
|
|
87
|
+
method: 'POST', headers: { 'content-type': 'application/octet-stream' }, body: new Uint8Array(fs.readFileSync(file)),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (!o.keep)
|
|
91
|
+
for (const file of files)
|
|
92
|
+
fs.rmSync(file);
|
|
93
|
+
log(`uploaded ${files.length} source maps for release ${release}${o.keep ? '' : ' and deleted them'}`);
|
|
94
|
+
return { uploaded: files.length };
|
|
95
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface TunnelOptions {
|
|
2
|
+
/** Edge base URL the requests are forwarded to. */
|
|
3
|
+
endpoint: string;
|
|
4
|
+
/** Route prefix to strip; default `/api/wt`. */
|
|
5
|
+
basePath?: string;
|
|
6
|
+
/** Request body cap in bytes; default 1 MiB (over it: 413). */
|
|
7
|
+
maxBodyBytes?: number;
|
|
8
|
+
fetch?: typeof fetch;
|
|
9
|
+
}
|
|
10
|
+
/** Next route handlers `{ GET, POST }` forwarding allow-listed RUM paths to the edge. Only the publishable key (`?k=` or a `wtp_` bearer) is forwarded as auth; cookies and other headers are not. */
|
|
11
|
+
export declare function tunnelHandler(o: TunnelOptions): {
|
|
12
|
+
GET: (r: Request) => Promise<Response>;
|
|
13
|
+
POST: (r: Request) => Promise<Response>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// First-party tunnel for browser telemetry (ad blockers block third-party telemetry hosts).
|
|
3
|
+
// app/api/wt/[...path]/route.ts: export const { GET, POST } = tunnelHandler({ endpoint: process.env.WT_EDGE_URL! });
|
|
4
|
+
// Browser SDK: init({ endpoint: '/api/wt', publishableKey: 'wtp_...' }).
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.tunnelHandler = tunnelHandler;
|
|
7
|
+
// only what the browser SDK calls: /v1/rum/*, /v1/replay/<session>/chunks and /v1/logs
|
|
8
|
+
const ALLOWED = /^\/v1\/(rum\/[A-Za-z0-9/_-]+|replay\/[A-Za-z0-9_-]+\/chunks|logs)$/;
|
|
9
|
+
const FORWARD = ['content-type', 'content-encoding', 'user-agent'];
|
|
10
|
+
/** Next route handlers `{ GET, POST }` forwarding allow-listed RUM paths to the edge. Only the publishable key (`?k=` or a `wtp_` bearer) is forwarded as auth; cookies and other headers are not. */
|
|
11
|
+
function tunnelHandler(o) {
|
|
12
|
+
const base = (o.basePath ?? '/api/wt').replace(/\/+$/, '');
|
|
13
|
+
const max = o.maxBodyBytes ?? 1024 * 1024;
|
|
14
|
+
const edge = o.endpoint.replace(/\/+$/, '');
|
|
15
|
+
const send = o.fetch ?? fetch;
|
|
16
|
+
const handle = async (req) => {
|
|
17
|
+
const url = new URL(req.url);
|
|
18
|
+
const path = url.pathname.startsWith(base) ? url.pathname.slice(base.length) : url.pathname;
|
|
19
|
+
if (!ALLOWED.test(path) || path.includes('..'))
|
|
20
|
+
return new Response('not found', { status: 404 });
|
|
21
|
+
const headers = {};
|
|
22
|
+
for (const h of FORWARD) {
|
|
23
|
+
const v = req.headers.get(h);
|
|
24
|
+
if (v)
|
|
25
|
+
headers[h] = v;
|
|
26
|
+
}
|
|
27
|
+
const bearer = /^Bearer (wtp_\S+)$/.exec(req.headers.get('authorization') ?? '');
|
|
28
|
+
if (bearer)
|
|
29
|
+
headers.authorization = `Bearer ${bearer[1]}`;
|
|
30
|
+
const k = url.searchParams.get('k');
|
|
31
|
+
let body;
|
|
32
|
+
if (req.method === 'POST') {
|
|
33
|
+
if (Number(req.headers.get('content-length') ?? 0) > max)
|
|
34
|
+
return new Response('payload too large', { status: 413 });
|
|
35
|
+
body = await req.arrayBuffer();
|
|
36
|
+
if (body.byteLength > max)
|
|
37
|
+
return new Response('payload too large', { status: 413 });
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const res = await send(`${edge}${path}${k ? `?k=${encodeURIComponent(k)}` : ''}`, { method: req.method, headers, body });
|
|
41
|
+
const out = new Headers();
|
|
42
|
+
const ct = res.headers.get('content-type');
|
|
43
|
+
if (ct)
|
|
44
|
+
out.set('content-type', ct);
|
|
45
|
+
return new Response(res.status === 204 ? null : await res.arrayBuffer(), { status: res.status, headers: out });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return new Response('bad gateway', { status: 502 });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return { GET: handle, POST: handle };
|
|
52
|
+
}
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
+
import type { ReadableSpan } from '@opentelemetry/sdk-trace';
|
|
2
|
+
import * as wt from '../index.js';
|
|
3
|
+
export { withWatchtower, uploadSourcemaps } from './next-build.js';
|
|
4
|
+
export type { SourcemapOptions } from './next-build.js';
|
|
5
|
+
export { tunnelHandler } from './next-tunnel.js';
|
|
6
|
+
export type { TunnelOptions } from './next-tunnel.js';
|
|
7
|
+
export interface NextOptions extends wt.InitOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Next.js's own spans (`next.span_type` set: load route module, prepare route module, resolve page components, start
|
|
10
|
+
* response, middleware, generateMetadata ...). `"sample"` (default) keeps `nextInternalsRate` of them, `"drop"` none,
|
|
11
|
+
* `"keep"` all. Request (`BaseServer.handleRequest`), route handler, render, server action and fetch spans, every
|
|
12
|
+
* SERVER/CLIENT span and every errored span are always kept. A dropped span's children stay in the trace.
|
|
13
|
+
*/
|
|
14
|
+
nextInternals?: 'drop' | 'sample' | 'keep';
|
|
15
|
+
/** Share of internal spans kept with `nextInternals: "sample"`; default 0.1. */
|
|
16
|
+
nextInternalsRate?: number;
|
|
17
|
+
}
|
|
18
|
+
/** Whether `span` is one of Next's internal spans (not a request, route handler, render, server action or fetch). */
|
|
19
|
+
export declare function isNextInternal(span: ReadableSpan): boolean;
|
|
20
|
+
/** The `spanFilter` for a `nextInternals` mode; `rand` is injectable for tests. */
|
|
21
|
+
export declare function nextInternalsFilter(mode?: 'drop' | 'sample' | 'keep', rate?: number, rand?: () => number): (s: ReadableSpan) => boolean;
|
|
22
|
+
/** Build a Next.js instrumentation `register` that passes `options` to `init`; no-op off the Node.js runtime or without a key. */
|
|
23
|
+
export declare function makeRegister(options?: NextOptions): () => Promise<void>;
|
|
1
24
|
/** Next.js instrumentation hook: init from WT_* env on the Node.js runtime; no-op without WT_INGEST_KEY. */
|
|
2
|
-
export declare
|
|
25
|
+
export declare const register: () => Promise<void>;
|
|
3
26
|
/** Next.js onRequestError: server render, route handler and server action errors. */
|
|
4
27
|
export declare function onRequestError(err: unknown, request?: {
|
|
5
28
|
path?: string;
|
|
@@ -33,17 +33,49 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.register =
|
|
36
|
+
exports.register = exports.tunnelHandler = exports.uploadSourcemaps = exports.withWatchtower = void 0;
|
|
37
|
+
exports.isNextInternal = isNextInternal;
|
|
38
|
+
exports.nextInternalsFilter = nextInternalsFilter;
|
|
39
|
+
exports.makeRegister = makeRegister;
|
|
37
40
|
exports.onRequestError = onRequestError;
|
|
38
41
|
// instrumentation.js: module.exports = require('@watchtowerobservability/node/next');
|
|
42
|
+
// or, with options: export const register = makeRegister({ redact }); export { onRequestError } from '@watchtowerobservability/node/next';
|
|
43
|
+
const api_1 = require("@opentelemetry/api");
|
|
39
44
|
const wt = __importStar(require("../index.js"));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
var next_build_js_1 = require("./next-build.js");
|
|
46
|
+
Object.defineProperty(exports, "withWatchtower", { enumerable: true, get: function () { return next_build_js_1.withWatchtower; } });
|
|
47
|
+
Object.defineProperty(exports, "uploadSourcemaps", { enumerable: true, get: function () { return next_build_js_1.uploadSourcemaps; } });
|
|
48
|
+
var next_tunnel_js_1 = require("./next-tunnel.js");
|
|
49
|
+
Object.defineProperty(exports, "tunnelHandler", { enumerable: true, get: function () { return next_tunnel_js_1.tunnelHandler; } });
|
|
50
|
+
const KEEP_TYPES = new Set([
|
|
51
|
+
'BaseServer.handleRequest', 'AppRouteRouteHandlers.runHandler', 'AppRender.fetch', 'AppRender.getBodyResult',
|
|
52
|
+
'Render.getServerSideProps', 'Render.getStaticProps', 'NextNodeServer.runApi',
|
|
53
|
+
]);
|
|
54
|
+
const KEEP_NAMES = /^(render route|executing api route|fetch |.*server action)/i;
|
|
55
|
+
/** Whether `span` is one of Next's internal spans (not a request, route handler, render, server action or fetch). */
|
|
56
|
+
function isNextInternal(span) {
|
|
57
|
+
const type = span.attributes['next.span_type'];
|
|
58
|
+
if (typeof type !== 'string')
|
|
59
|
+
return false;
|
|
60
|
+
return !KEEP_TYPES.has(type) && !KEEP_NAMES.test(span.name) && span.kind !== 1 && span.kind !== 2 && span.status.code !== api_1.SpanStatusCode.ERROR;
|
|
61
|
+
}
|
|
62
|
+
/** The `spanFilter` for a `nextInternals` mode; `rand` is injectable for tests. */
|
|
63
|
+
function nextInternalsFilter(mode = 'sample', rate = 0.1, rand = Math.random) {
|
|
64
|
+
return (s) => mode === 'keep' || !isNextInternal(s) || (mode === 'sample' && rand() < rate);
|
|
46
65
|
}
|
|
66
|
+
/** Build a Next.js instrumentation `register` that passes `options` to `init`; no-op off the Node.js runtime or without a key. */
|
|
67
|
+
function makeRegister(options = {}) {
|
|
68
|
+
return async function register() {
|
|
69
|
+
const rt = process.env.NEXT_RUNTIME;
|
|
70
|
+
if ((rt && rt !== 'nodejs') || !(options.apiKey || process.env.WT_INGEST_KEY))
|
|
71
|
+
return;
|
|
72
|
+
const { nextInternals, nextInternalsRate, ...init } = options;
|
|
73
|
+
const own = nextInternalsFilter(nextInternals, nextInternalsRate);
|
|
74
|
+
wt.init({ ...init, spanFilter: init.spanFilter ? (s) => own(s) && init.spanFilter(s) : own });
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Next.js instrumentation hook: init from WT_* env on the Node.js runtime; no-op without WT_INGEST_KEY. */
|
|
78
|
+
exports.register = makeRegister();
|
|
47
79
|
/** Next.js onRequestError: server render, route handler and server action errors. */
|
|
48
80
|
async function onRequestError(err, request, context) {
|
|
49
81
|
const c = context || {};
|
package/dist/cjs/load.js
CHANGED
|
@@ -2,13 +2,45 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.load = load;
|
|
4
4
|
exports.need = need;
|
|
5
|
-
// Optional-peer loader
|
|
6
|
-
//
|
|
5
|
+
// Optional-peer loader. Each peer is required by a LITERAL name inside a try block so bundlers (webpack, esbuild, Next's
|
|
6
|
+
// file tracer) can follow it; a computed `require(name)` is invisible to them. This is the CommonJS form;
|
|
7
|
+
// scripts/build.mjs prepends `const require = createRequire(import.meta.url)` for dist/esm (webpack follows that too).
|
|
8
|
+
// The cwd fallback only matters when `require` does not exist (test runners running the TS source as ESM).
|
|
7
9
|
const node_module_1 = require("node:module");
|
|
10
|
+
const NONE = Symbol('not a known peer');
|
|
11
|
+
function known(id) {
|
|
12
|
+
try { // bundlers only tolerate an optional require that is lexically inside try
|
|
13
|
+
switch (id) {
|
|
14
|
+
case '@opentelemetry/context-async-hooks': return require('@opentelemetry/context-async-hooks');
|
|
15
|
+
case '@opentelemetry/core': return require('@opentelemetry/core');
|
|
16
|
+
case '@opentelemetry/exporter-logs-otlp-http': return require('@opentelemetry/exporter-logs-otlp-http');
|
|
17
|
+
case '@opentelemetry/exporter-metrics-otlp-http': return require('@opentelemetry/exporter-metrics-otlp-http');
|
|
18
|
+
case '@opentelemetry/exporter-trace-otlp-http': return require('@opentelemetry/exporter-trace-otlp-http');
|
|
19
|
+
case '@opentelemetry/otlp-transformer': return require('@opentelemetry/otlp-transformer');
|
|
20
|
+
case '@opentelemetry/resources': return require('@opentelemetry/resources');
|
|
21
|
+
case '@opentelemetry/sdk-logs': return require('@opentelemetry/sdk-logs');
|
|
22
|
+
case '@opentelemetry/sdk-metrics': return require('@opentelemetry/sdk-metrics');
|
|
23
|
+
case '@opentelemetry/sdk-trace': return require('@opentelemetry/sdk-trace');
|
|
24
|
+
case '@opentelemetry/instrumentation-runtime-node': return require('@opentelemetry/instrumentation-runtime-node');
|
|
25
|
+
case '@opentelemetry/instrumentation': return require('@opentelemetry/instrumentation');
|
|
26
|
+
case '@opentelemetry/instrumentation-http': return require('@opentelemetry/instrumentation-http');
|
|
27
|
+
case '@opentelemetry/instrumentation-undici': return require('@opentelemetry/instrumentation-undici');
|
|
28
|
+
case '@opentelemetry/instrumentation-pg': return require('@opentelemetry/instrumentation-pg');
|
|
29
|
+
case '@opentelemetry/instrumentation-ioredis': return require('@opentelemetry/instrumentation-ioredis');
|
|
30
|
+
case '@opentelemetry/instrumentation-mysql2': return require('@opentelemetry/instrumentation-mysql2');
|
|
31
|
+
case 'winston-transport': return require('winston-transport');
|
|
32
|
+
default: return NONE;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
8
39
|
function load(id) {
|
|
9
|
-
if (typeof require
|
|
10
|
-
return
|
|
11
|
-
|
|
40
|
+
if (typeof require !== 'function')
|
|
41
|
+
return (0, node_module_1.createRequire)(`${process.cwd()}/`)(id);
|
|
42
|
+
const m = known(id);
|
|
43
|
+
return m === NONE ? require(id) : m;
|
|
12
44
|
}
|
|
13
45
|
const SDK_PEERS = [
|
|
14
46
|
'@opentelemetry/context-async-hooks', '@opentelemetry/core', '@opentelemetry/exporter-logs-otlp-http',
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// `wt-next-sourcemaps [dir]`: upload .next/static source maps after `next build` (env: WT_API_KEY, WT_PROJECT, WT_RELEASE, WT_API_URL), then delete them.
|
|
5
|
+
const next_build_js_1 = require("./integrations/next-build.js");
|
|
6
|
+
(0, next_build_js_1.uploadSourcemaps)({ dir: process.argv[2], log: (l) => console.log(`[watchtower] ${l}`) }).catch((e) => {
|
|
7
|
+
console.error(`[watchtower] source map upload failed: ${e.message}`);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SpanProcessor } from '@opentelemetry/sdk-trace';
|
|
2
|
+
export interface Frame {
|
|
3
|
+
file: string;
|
|
4
|
+
line: number;
|
|
5
|
+
fn?: string;
|
|
6
|
+
}
|
|
7
|
+
/** The first application frame of a V8 stack, or undefined. */
|
|
8
|
+
export declare function firstAppFrame(stack: string): Frame | undefined;
|
|
9
|
+
export declare function codeOrigin(): SpanProcessor;
|