@introspection-sdk/introspection-node 0.4.2 → 0.4.4
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/.turbo/turbo-build.log +1 -1
- package/dist/client.d.ts +42 -132
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +67 -366
- package/dist/client.js.map +1 -0
- package/dist/converters/claude.d.ts +4 -0
- package/dist/converters/claude.d.ts.map +1 -1
- package/dist/converters/claude.js +7 -0
- package/dist/converters/claude.js.map +1 -0
- package/dist/converters/gemini.d.ts +90 -0
- package/dist/converters/gemini.d.ts.map +1 -0
- package/dist/converters/gemini.js +171 -0
- package/dist/converters/gemini.js.map +1 -0
- package/dist/converters/index.d.ts +1 -1
- package/dist/converters/index.d.ts.map +1 -1
- package/dist/converters/index.js +2 -1
- package/dist/converters/index.js.map +1 -0
- package/dist/converters/openai.js +1 -0
- package/dist/converters/openai.js.map +1 -0
- package/dist/converters/openinference.js +1 -0
- package/dist/converters/openinference.js.map +1 -0
- package/dist/converters/vercel.d.ts.map +1 -1
- package/dist/converters/vercel.js +31 -3
- package/dist/converters/vercel.js.map +1 -0
- package/dist/http.d.ts +36 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +145 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +24 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -32
- package/dist/index.js.map +1 -0
- package/dist/{anthropic.d.ts → otel/anthropic.d.ts} +23 -13
- package/dist/otel/anthropic.d.ts.map +1 -0
- package/dist/{anthropic.js → otel/anthropic.js} +132 -40
- package/dist/otel/anthropic.js.map +1 -0
- package/dist/{claude-hooks.d.ts → otel/claude-hooks.d.ts} +19 -1
- package/dist/otel/claude-hooks.d.ts.map +1 -0
- package/dist/{claude-hooks.js → otel/claude-hooks.js} +94 -20
- package/dist/otel/claude-hooks.js.map +1 -0
- package/dist/otel/claude-wrapper.d.ts.map +1 -0
- package/dist/{claude-wrapper.js → otel/claude-wrapper.js} +2 -1
- package/dist/otel/claude-wrapper.js.map +1 -0
- package/dist/otel/gemini.d.ts +56 -0
- package/dist/otel/gemini.d.ts.map +1 -0
- package/dist/otel/gemini.js +348 -0
- package/dist/otel/gemini.js.map +1 -0
- package/dist/otel/index.d.ts +32 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +41 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/otel/init.d.ts +126 -0
- package/dist/otel/init.d.ts.map +1 -0
- package/dist/otel/init.js +259 -0
- package/dist/otel/init.js.map +1 -0
- package/dist/otel/integrations/anthropic.d.ts +10 -0
- package/dist/otel/integrations/anthropic.d.ts.map +1 -0
- package/dist/otel/integrations/anthropic.js +22 -0
- package/dist/otel/integrations/anthropic.js.map +1 -0
- package/dist/otel/integrations/base.d.ts +83 -0
- package/dist/otel/integrations/base.d.ts.map +1 -0
- package/dist/otel/integrations/base.js +23 -0
- package/dist/otel/integrations/base.js.map +1 -0
- package/dist/otel/integrations/claude-agent.d.ts +13 -0
- package/dist/otel/integrations/claude-agent.d.ts.map +1 -0
- package/dist/otel/integrations/claude-agent.js +27 -0
- package/dist/otel/integrations/claude-agent.js.map +1 -0
- package/dist/otel/integrations/gemini.d.ts +11 -0
- package/dist/otel/integrations/gemini.d.ts.map +1 -0
- package/dist/otel/integrations/gemini.js +21 -0
- package/dist/otel/integrations/gemini.js.map +1 -0
- package/dist/otel/integrations/index.d.ts +39 -0
- package/dist/otel/integrations/index.d.ts.map +1 -0
- package/dist/otel/integrations/index.js +131 -0
- package/dist/otel/integrations/index.js.map +1 -0
- package/dist/otel/integrations/langchain.d.ts +16 -0
- package/dist/otel/integrations/langchain.d.ts.map +1 -0
- package/dist/otel/integrations/langchain.js +41 -0
- package/dist/otel/integrations/langchain.js.map +1 -0
- package/dist/otel/integrations/mastra.d.ts +14 -0
- package/dist/otel/integrations/mastra.d.ts.map +1 -0
- package/dist/otel/integrations/mastra.js +27 -0
- package/dist/otel/integrations/mastra.js.map +1 -0
- package/dist/otel/integrations/openai-agents.d.ts +11 -0
- package/dist/otel/integrations/openai-agents.d.ts.map +1 -0
- package/dist/otel/integrations/openai-agents.js +25 -0
- package/dist/otel/integrations/openai-agents.js.map +1 -0
- package/dist/otel/integrations/pi.d.ts +12 -0
- package/dist/otel/integrations/pi.d.ts.map +1 -0
- package/dist/otel/integrations/pi.js +20 -0
- package/dist/otel/integrations/pi.js.map +1 -0
- package/dist/otel/integrations/vercel.d.ts +15 -0
- package/dist/otel/integrations/vercel.d.ts.map +1 -0
- package/dist/otel/integrations/vercel.js +20 -0
- package/dist/otel/integrations/vercel.js.map +1 -0
- package/dist/{langchain-handler.d.ts → otel/langchain-handler.d.ts} +10 -1
- package/dist/otel/langchain-handler.d.ts.map +1 -0
- package/dist/{langchain-handler.js → otel/langchain-handler.js} +43 -6
- package/dist/otel/langchain-handler.js.map +1 -0
- package/dist/otel/logs.d.ts +82 -0
- package/dist/otel/logs.d.ts.map +1 -0
- package/dist/otel/logs.js +271 -0
- package/dist/otel/logs.js.map +1 -0
- package/dist/{mastra-exporter.d.ts → otel/mastra-exporter.d.ts} +3 -1
- package/dist/otel/mastra-exporter.d.ts.map +1 -0
- package/dist/{mastra-exporter.js → otel/mastra-exporter.js} +71 -17
- package/dist/otel/mastra-exporter.js.map +1 -0
- package/dist/otel/pi.d.ts +59 -0
- package/dist/otel/pi.d.ts.map +1 -0
- package/dist/otel/pi.js +67 -0
- package/dist/otel/pi.js.map +1 -0
- package/dist/otel/register.d.ts +8 -0
- package/dist/otel/register.d.ts.map +1 -0
- package/dist/otel/register.js +48 -0
- package/dist/otel/register.js.map +1 -0
- package/dist/otel/setup.d.ts +52 -0
- package/dist/otel/setup.d.ts.map +1 -0
- package/dist/otel/setup.js +146 -0
- package/dist/otel/setup.js.map +1 -0
- package/dist/{span-processor.d.ts → otel/span-processor.d.ts} +1 -1
- package/dist/otel/span-processor.d.ts.map +1 -0
- package/dist/{span-processor.js → otel/span-processor.js} +11 -5
- package/dist/otel/span-processor.js.map +1 -0
- package/dist/{tracing-processor.d.ts → otel/tracing-processor.d.ts} +4 -1
- package/dist/otel/tracing-processor.d.ts.map +1 -0
- package/dist/{tracing-processor.js → otel/tracing-processor.js} +64 -14
- package/dist/otel/tracing-processor.js.map +1 -0
- package/dist/resources/experiments.d.ts +31 -0
- package/dist/resources/experiments.d.ts.map +1 -0
- package/dist/resources/experiments.js +133 -0
- package/dist/resources/experiments.js.map +1 -0
- package/dist/resources/recipes.d.ts +22 -0
- package/dist/resources/recipes.d.ts.map +1 -0
- package/dist/resources/recipes.js +61 -0
- package/dist/resources/recipes.js.map +1 -0
- package/dist/resources/runtimes.d.ts +76 -0
- package/dist/resources/runtimes.d.ts.map +1 -0
- package/dist/resources/runtimes.js +179 -0
- package/dist/resources/runtimes.js.map +1 -0
- package/dist/runner-resources/files.d.ts +35 -0
- package/dist/runner-resources/files.d.ts.map +1 -0
- package/dist/runner-resources/files.js +131 -0
- package/dist/runner-resources/files.js.map +1 -0
- package/dist/runner-resources/tasks.d.ts +39 -0
- package/dist/runner-resources/tasks.d.ts.map +1 -0
- package/dist/runner-resources/tasks.js +129 -0
- package/dist/runner-resources/tasks.js.map +1 -0
- package/dist/runner.d.ts +80 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +159 -0
- package/dist/runner.js.map +1 -0
- package/dist/streaming.d.ts +8 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +67 -0
- package/dist/streaming.js.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -4
- package/dist/utils.js.map +1 -0
- package/dist/version.js +1 -0
- package/dist/version.js.map +1 -0
- package/package.json +91 -22
- package/src/client.ts +76 -473
- package/src/converters/claude.ts +10 -0
- package/src/converters/gemini.ts +243 -0
- package/src/converters/index.ts +13 -7
- package/src/converters/vercel.ts +41 -3
- package/src/http.ts +163 -0
- package/src/index.ts +110 -75
- package/src/{anthropic.ts → otel/anthropic.ts} +206 -54
- package/src/{claude-hooks.ts → otel/claude-hooks.ts} +119 -20
- package/src/{claude-wrapper.ts → otel/claude-wrapper.ts} +1 -1
- package/src/otel/gemini.ts +491 -0
- package/src/otel/index.ts +121 -0
- package/src/otel/init.ts +411 -0
- package/src/otel/integrations/anthropic.ts +26 -0
- package/src/otel/integrations/base.ts +95 -0
- package/src/otel/integrations/claude-agent.ts +32 -0
- package/src/otel/integrations/gemini.ts +25 -0
- package/src/otel/integrations/index.ts +151 -0
- package/src/otel/integrations/langchain.ts +45 -0
- package/src/otel/integrations/mastra.ts +30 -0
- package/src/otel/integrations/openai-agents.ts +31 -0
- package/src/otel/integrations/pi.ts +24 -0
- package/src/otel/integrations/vercel.ts +24 -0
- package/src/{langchain-handler.ts → otel/langchain-handler.ts} +53 -6
- package/src/otel/logs.ts +394 -0
- package/src/{mastra-exporter.ts → otel/mastra-exporter.ts} +83 -22
- package/src/otel/pi.ts +88 -0
- package/src/otel/register.ts +50 -0
- package/src/otel/setup.ts +215 -0
- package/src/{span-processor.ts → otel/span-processor.ts} +11 -6
- package/src/{tracing-processor.ts → otel/tracing-processor.ts} +94 -19
- package/src/resources/experiments.ts +170 -0
- package/src/resources/recipes.ts +73 -0
- package/src/resources/runtimes.ts +231 -0
- package/src/runner-resources/files.ts +163 -0
- package/src/runner-resources/tasks.ts +156 -0
- package/src/runner.ts +194 -0
- package/src/streaming.ts +57 -0
- package/src/utils.ts +12 -5
- package/dist/ai-sdk-integration.d.ts +0 -123
- package/dist/ai-sdk-integration.d.ts.map +0 -1
- package/dist/ai-sdk-integration.js +0 -475
- package/dist/anthropic.d.ts.map +0 -1
- package/dist/claude-hooks.d.ts.map +0 -1
- package/dist/claude-wrapper.d.ts.map +0 -1
- package/dist/converters/ai-sdk.d.ts +0 -65
- package/dist/converters/ai-sdk.d.ts.map +0 -1
- package/dist/converters/ai-sdk.js +0 -261
- package/dist/langchain-handler.d.ts.map +0 -1
- package/dist/mastra-exporter.d.ts.map +0 -1
- package/dist/span-processor.d.ts.map +0 -1
- package/dist/tracing-processor.d.ts.map +0 -1
- package/src/ai-sdk-integration.ts +0 -691
- package/src/converters/ai-sdk.ts +0 -323
- /package/dist/{claude-wrapper.d.ts → otel/claude-wrapper.d.ts} +0 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-liner bootstrap for the Introspection OTel surface.
|
|
3
|
+
*
|
|
4
|
+
* `init()` detects the installed LLM frameworks and wires them into one shared
|
|
5
|
+
* pipeline, mirroring the Python SDK's `introspection.init()`:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import * as introspection from "@introspection-sdk/introspection-node/otel";
|
|
9
|
+
* import Anthropic from "@anthropic-ai/sdk";
|
|
10
|
+
*
|
|
11
|
+
* await introspection.init({ serviceName: "my-app" });
|
|
12
|
+
*
|
|
13
|
+
* const client = new Anthropic(); // auto-traced — no per-client wiring
|
|
14
|
+
* await introspection.conversation(() =>
|
|
15
|
+
* client.messages.create({ ... }),
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* It also exposes the `track` / `feedback` / `identify` analytics surface and a
|
|
20
|
+
* `conversation()` scope, proxied to a global {@link IntrospectionLogs}.
|
|
21
|
+
*/
|
|
22
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
23
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
24
|
+
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
25
|
+
import { logger } from "../utils.js";
|
|
26
|
+
import { discoverIntegrations, setupIntegrations, teardownIntegrations, } from "./integrations/index.js";
|
|
27
|
+
import { IntrospectionLogs } from "./logs.js";
|
|
28
|
+
import { registerOTelGlobals } from "./setup.js";
|
|
29
|
+
import { IntrospectionSpanProcessor } from "./span-processor.js";
|
|
30
|
+
const state = {
|
|
31
|
+
provider: null,
|
|
32
|
+
ownsProvider: false,
|
|
33
|
+
logs: null,
|
|
34
|
+
handles: {},
|
|
35
|
+
shutdownRegistered: false,
|
|
36
|
+
};
|
|
37
|
+
/** Generate a fresh conversation id (matches the Python SDK's format). */
|
|
38
|
+
export function newConversationId() {
|
|
39
|
+
return `intro_conv_${crypto.randomUUID().replace(/-/g, "")}`;
|
|
40
|
+
}
|
|
41
|
+
function resolveProvider(options, token, serviceName, advanced) {
|
|
42
|
+
// baggage scopes (conversation/agent/identity) need these globals regardless
|
|
43
|
+
// of who owns the provider.
|
|
44
|
+
registerOTelGlobals(options.onConflict);
|
|
45
|
+
if (options.tracerProvider)
|
|
46
|
+
return options.tracerProvider;
|
|
47
|
+
const provider = new NodeTracerProvider({
|
|
48
|
+
resource: serviceName
|
|
49
|
+
? resourceFromAttributes({ [ATTR_SERVICE_NAME]: serviceName })
|
|
50
|
+
: undefined,
|
|
51
|
+
// Order is irrelevant (IntrospectionSpanProcessor exports an isolated
|
|
52
|
+
// converted copy and never mutates the shared span); listed first to match
|
|
53
|
+
// setupTracing()'s ordering.
|
|
54
|
+
spanProcessors: [
|
|
55
|
+
new IntrospectionSpanProcessor({ token, serviceName, advanced }),
|
|
56
|
+
...(options.spanProcessors ?? []),
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
provider.register();
|
|
60
|
+
return provider;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Detect installed LLM frameworks and wire them into one shared provider.
|
|
64
|
+
*
|
|
65
|
+
* Idempotent: repeated calls return the already-configured provider without
|
|
66
|
+
* re-installing integrations.
|
|
67
|
+
*/
|
|
68
|
+
export async function init(options = {}) {
|
|
69
|
+
if (state.provider) {
|
|
70
|
+
logger.debug("introspection.init() already called; returning provider");
|
|
71
|
+
return state.provider;
|
|
72
|
+
}
|
|
73
|
+
const token = options.token ?? process.env.INTROSPECTION_TOKEN;
|
|
74
|
+
const serviceName = options.serviceName ?? process.env.INTROSPECTION_SERVICE_NAME ?? undefined;
|
|
75
|
+
const baseUrl = options.baseUrl ?? process.env.INTROSPECTION_BASE_OTEL_URL ?? undefined;
|
|
76
|
+
const advanced = options.advanced;
|
|
77
|
+
// A custom span exporter (tests) stands in for a token; otherwise a token is
|
|
78
|
+
// required for anything to be exported.
|
|
79
|
+
if (!token && !advanced?.spanExporter && !options.tracerProvider) {
|
|
80
|
+
throw new Error("introspection.init() requires a token. Set INTROSPECTION_TOKEN or pass { token }.");
|
|
81
|
+
}
|
|
82
|
+
const ownsProvider = !options.tracerProvider;
|
|
83
|
+
const provider = resolveProvider(options, token, serviceName, advanced);
|
|
84
|
+
// The track / feedback / identify surface is a separate OTLP log stream.
|
|
85
|
+
const logs = new IntrospectionLogs({
|
|
86
|
+
token,
|
|
87
|
+
serviceName,
|
|
88
|
+
baseOtelUrl: baseUrl,
|
|
89
|
+
additionalHeaders: advanced?.additionalHeaders,
|
|
90
|
+
flushInterval: advanced?.flushInterval,
|
|
91
|
+
maxBatchSize: advanced?.maxBatchSize,
|
|
92
|
+
});
|
|
93
|
+
const ctx = {
|
|
94
|
+
tracerProvider: provider,
|
|
95
|
+
token,
|
|
96
|
+
serviceName,
|
|
97
|
+
baseUrl,
|
|
98
|
+
advanced,
|
|
99
|
+
handles: state.handles,
|
|
100
|
+
};
|
|
101
|
+
// Run discovery + setup BEFORE committing global state, so a failure here
|
|
102
|
+
// doesn't leave a half-configured provider behind the idempotency guard
|
|
103
|
+
// (a later init() would otherwise return the broken provider and never retry).
|
|
104
|
+
try {
|
|
105
|
+
const toInstall = [];
|
|
106
|
+
if (options.autoDiscover !== false) {
|
|
107
|
+
toInstall.push(...(await discoverIntegrations()));
|
|
108
|
+
}
|
|
109
|
+
if (options.integrations)
|
|
110
|
+
toInstall.push(...options.integrations);
|
|
111
|
+
setupIntegrations(toInstall, ctx);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
state.handles = {};
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
state.provider = provider;
|
|
118
|
+
state.ownsProvider = ownsProvider;
|
|
119
|
+
state.logs = logs;
|
|
120
|
+
if (!state.shutdownRegistered) {
|
|
121
|
+
process.once("beforeExit", () => {
|
|
122
|
+
void shutdown();
|
|
123
|
+
});
|
|
124
|
+
state.shutdownRegistered = true;
|
|
125
|
+
}
|
|
126
|
+
return provider;
|
|
127
|
+
}
|
|
128
|
+
/** Return the global logs client. Throws if {@link init} has not been called. */
|
|
129
|
+
export function getClient() {
|
|
130
|
+
if (!state.logs) {
|
|
131
|
+
throw new Error("introspection.init() must be called before using track / feedback / identify.");
|
|
132
|
+
}
|
|
133
|
+
return state.logs;
|
|
134
|
+
}
|
|
135
|
+
/** Return the shared provider. Throws if {@link init} has not been called. */
|
|
136
|
+
export function getTracerProvider() {
|
|
137
|
+
if (!state.provider) {
|
|
138
|
+
throw new Error("introspection.init() must be called first.");
|
|
139
|
+
}
|
|
140
|
+
return state.provider;
|
|
141
|
+
}
|
|
142
|
+
/** Track an analytics event. Requires {@link init} first. */
|
|
143
|
+
export function track(eventName, properties, options) {
|
|
144
|
+
getClient().track(eventName, properties, options);
|
|
145
|
+
}
|
|
146
|
+
/** Record feedback on an AI response. Requires {@link init} first. */
|
|
147
|
+
export function feedback(name, options = {}) {
|
|
148
|
+
getClient().feedback(name, options);
|
|
149
|
+
}
|
|
150
|
+
/** Associate the current context with a user. Requires {@link init} first. */
|
|
151
|
+
export function identify(userId, traits, anonymousId, eventId) {
|
|
152
|
+
getClient().identify(userId, traits, anonymousId, eventId);
|
|
153
|
+
}
|
|
154
|
+
export function conversation(a, b) {
|
|
155
|
+
const conversationId = typeof a === "string" ? a : newConversationId();
|
|
156
|
+
const callback = (typeof a === "string" ? b : a);
|
|
157
|
+
return getClient().withConversation(conversationId, undefined, () => callback(conversationId));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Run `callback` with `gen_ai.agent.name` (+ optional `gen_ai.agent.id`) on the
|
|
161
|
+
* baggage, so spans/events produced within are attributed to that agent.
|
|
162
|
+
* Requires {@link init} first. Mirrors `IntrospectionLogs.withAgent`.
|
|
163
|
+
*/
|
|
164
|
+
export function withAgent(agentName, agentId, callback) {
|
|
165
|
+
return getClient().withAgent(agentName, agentId, callback);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Run `callback` inside a conversation scope, optionally chaining a previous
|
|
169
|
+
* response id. Unlike {@link conversation}, the id is required (no auto-gen).
|
|
170
|
+
* Requires {@link init} first.
|
|
171
|
+
*/
|
|
172
|
+
export function withConversation(conversationId, previousResponseId, callback) {
|
|
173
|
+
return getClient().withConversation(conversationId, previousResponseId, callback);
|
|
174
|
+
}
|
|
175
|
+
/** Run `callback` with `identity.user_id` on the baggage. Requires {@link init} first. */
|
|
176
|
+
export function withUserId(userId, callback) {
|
|
177
|
+
return getClient().withUserId(userId, callback);
|
|
178
|
+
}
|
|
179
|
+
/** Run `callback` with `identity.anonymous_id` on the baggage. Requires {@link init} first. */
|
|
180
|
+
export function withAnonymousId(anonymousId, callback) {
|
|
181
|
+
return getClient().withAnonymousId(anonymousId, callback);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The LangChain handler bound by `init()`. Attach it per-invoke:
|
|
185
|
+
* `chain.invoke(input, { callbacks: [introspection.getLangchainHandler()] })`.
|
|
186
|
+
*/
|
|
187
|
+
export function getLangchainHandler() {
|
|
188
|
+
const handler = state.handles.langchainHandler;
|
|
189
|
+
if (!handler) {
|
|
190
|
+
throw new Error("LangChain integration not configured. Call introspection.init() with @langchain/core installed.");
|
|
191
|
+
}
|
|
192
|
+
return handler;
|
|
193
|
+
}
|
|
194
|
+
/** The Mastra exporter bound by `init()`. Put it in `observability.configs`. */
|
|
195
|
+
export function getMastraExporter() {
|
|
196
|
+
const exporter = state.handles.mastraExporter;
|
|
197
|
+
if (!exporter) {
|
|
198
|
+
throw new Error("Mastra integration not configured. Call introspection.init() with @mastra/core installed.");
|
|
199
|
+
}
|
|
200
|
+
return exporter;
|
|
201
|
+
}
|
|
202
|
+
/** Instrument a Pi `Agent` against the shared provider. Requires {@link init}. */
|
|
203
|
+
export function instrumentPi(agent, meta) {
|
|
204
|
+
const instrumentor = state.handles.piInstrumentor;
|
|
205
|
+
if (!instrumentor) {
|
|
206
|
+
throw new Error("Pi integration not configured. Call introspection.init() with @mariozechner/pi-agent-core installed.");
|
|
207
|
+
}
|
|
208
|
+
instrumentor.instrument(agent, meta);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Wrap the Claude Agent SDK module so its `query()` calls are traced.
|
|
212
|
+
* Equivalent to `withIntrospection(sdk)` but pre-bound to the `init()` config.
|
|
213
|
+
*/
|
|
214
|
+
export function instrumentClaudeAgent(
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
216
|
+
sdk) {
|
|
217
|
+
const fn = state.handles.instrumentClaudeAgent;
|
|
218
|
+
if (!fn) {
|
|
219
|
+
throw new Error("Claude Agent integration not configured. Call introspection.init() with @anthropic-ai/claude-agent-sdk installed.");
|
|
220
|
+
}
|
|
221
|
+
return fn(sdk);
|
|
222
|
+
}
|
|
223
|
+
/** Flush and shut down the logs client and (if owned) the provider. */
|
|
224
|
+
export async function shutdown() {
|
|
225
|
+
const { logs, provider, ownsProvider } = state;
|
|
226
|
+
if (logs) {
|
|
227
|
+
try {
|
|
228
|
+
await logs.shutdown();
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
logger.debug(`Error shutting down logs client: ${String(e)}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (ownsProvider && provider && "shutdown" in provider) {
|
|
235
|
+
try {
|
|
236
|
+
await provider.shutdown();
|
|
237
|
+
}
|
|
238
|
+
catch (e) {
|
|
239
|
+
logger.debug(`Error shutting down provider: ${String(e)}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Run integration teardowns (uninstrument prototype patches) + clear the
|
|
243
|
+
// run-once guard so a later init() re-installs and rebuilds the handles
|
|
244
|
+
// against the new provider instead of being skipped.
|
|
245
|
+
teardownIntegrations();
|
|
246
|
+
state.provider = null;
|
|
247
|
+
state.ownsProvider = false;
|
|
248
|
+
state.logs = null;
|
|
249
|
+
state.handles = {};
|
|
250
|
+
}
|
|
251
|
+
/** Reset module state. Test-only utility. */
|
|
252
|
+
export function _resetForTests() {
|
|
253
|
+
teardownIntegrations();
|
|
254
|
+
state.provider = null;
|
|
255
|
+
state.ownsProvider = false;
|
|
256
|
+
state.logs = null;
|
|
257
|
+
state.handles = {};
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/otel/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAKlE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAGxE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,GAIrB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAyB,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAwCjE,MAAM,KAAK,GAAc;IACvB,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,KAAK;IACnB,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,EAAE;IACX,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AAEF,0EAA0E;AAC1E,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,MAAM,CAAC,UAAU,EAAE,CAAC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C;QACxB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,oCAAoC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IACD,IAAI,YAAY,IAAI,QAAQ,IAAI,UAAU,IAAI,QAAQ,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,MAAO,QAA0C,CAAC,QAAQ,EAAE,CAAC;QAC/D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,iCAAiC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IACD,yEAAyE;IACzE,wEAAwE;IACxE,qDAAqD;IACrD,oBAAoB,EAAE,CAAC;IACvB,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;IACtB,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC;IAC3B,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;AACrB,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,cAAc;IAC5B,oBAAoB,EAAE,CAAC;IACvB,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;IACtB,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC;IAC3B,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Node SDK integration.
|
|
3
|
+
*
|
|
4
|
+
* Patches `Anthropic.Messages.prototype.create` so every `new Anthropic()`
|
|
5
|
+
* client is traced against the shared provider — no per-client wiring.
|
|
6
|
+
*/
|
|
7
|
+
import type { Integration } from "./base.js";
|
|
8
|
+
declare const integration: Integration;
|
|
9
|
+
export default integration;
|
|
10
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/otel/integrations/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,QAAA,MAAM,WAAW,EAAE,WASlB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Node SDK integration.
|
|
3
|
+
*
|
|
4
|
+
* Patches `Anthropic.Messages.prototype.create` so every `new Anthropic()`
|
|
5
|
+
* client is traced against the shared provider — no per-client wiring.
|
|
6
|
+
*/
|
|
7
|
+
// Top-level import gates availability: if `@anthropic-ai/sdk` is not installed
|
|
8
|
+
// the dynamic import of this module rejects and discovery skips the shim.
|
|
9
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
10
|
+
import { AnthropicInstrumentor } from "../anthropic.js";
|
|
11
|
+
const integration = {
|
|
12
|
+
identifier: "anthropic",
|
|
13
|
+
setupOnce({ tracerProvider }) {
|
|
14
|
+
const instrumentor = new AnthropicInstrumentor();
|
|
15
|
+
instrumentor.instrumentClass({ anthropic: Anthropic, tracerProvider });
|
|
16
|
+
// Restore the original prototype on shutdown so a later init() re-patches
|
|
17
|
+
// against the rebuilt provider (the patch captures the provider's tracer).
|
|
18
|
+
return () => instrumentor.uninstrument();
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export default integration;
|
|
22
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/otel/integrations/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,0EAA0E;AAC1E,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,MAAM,WAAW,GAAgB;IAC/B,UAAU,EAAE,WAAW;IACvB,SAAS,CAAC,EAAE,cAAc,EAAE;QAC1B,MAAM,YAAY,GAAG,IAAI,qBAAqB,EAAE,CAAC;QACjD,YAAY,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,CAAC;QACvE,0EAA0E;QAC1E,2EAA2E;QAC3E,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;IAC3C,CAAC;CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration base contract, modeled on Sentry's integration registry and the
|
|
3
|
+
* Python SDK's `Integration` ABC.
|
|
4
|
+
*
|
|
5
|
+
* An {@link Integration} knows how to wire one framework (Anthropic, Gemini,
|
|
6
|
+
* OpenAI Agents, …) into the shared Introspection trace pipeline. `init()`
|
|
7
|
+
* discovers the integrations whose framework is importable and runs each
|
|
8
|
+
* `setupOnce()` exactly once.
|
|
9
|
+
*/
|
|
10
|
+
import type { BasicTracerProvider } from "@opentelemetry/sdk-trace-base";
|
|
11
|
+
import type { AdvancedOptions } from "../../types.js";
|
|
12
|
+
import type { InstrumentedClaudeAgentSDK } from "../claude-wrapper.js";
|
|
13
|
+
import type { IntrospectionCallbackHandler } from "../langchain-handler.js";
|
|
14
|
+
import type { IntrospectionPiInstrumentor } from "../pi.js";
|
|
15
|
+
/**
|
|
16
|
+
* Bound framework handles published by instance/config-based integrations.
|
|
17
|
+
*
|
|
18
|
+
* Some JS framework hooks cannot be wired globally — the caller still has to
|
|
19
|
+
* pass a handler to `chain.invoke({ callbacks })`, put an exporter in the
|
|
20
|
+
* Mastra config, instrument an Agent instance, or wrap the Claude Agent SDK
|
|
21
|
+
* module. For those, the integration publishes a handle here, pre-bound to the
|
|
22
|
+
* `init()` token / provider, and `init()` re-exposes it (e.g.
|
|
23
|
+
* `introspection.getLangchainHandler()`).
|
|
24
|
+
*/
|
|
25
|
+
export interface IntegrationHandles {
|
|
26
|
+
langchainHandler?: IntrospectionCallbackHandler;
|
|
27
|
+
mastraExporter?: any;
|
|
28
|
+
piInstrumentor?: IntrospectionPiInstrumentor;
|
|
29
|
+
instrumentClaudeAgent?: (sdk: any) => InstrumentedClaudeAgentSDK;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Thrown by an integration module/`setupOnce` when the framework cannot be
|
|
33
|
+
* activated (package missing, version too old, …).
|
|
34
|
+
*
|
|
35
|
+
* Swallowed during auto-discovery so a missing framework just skips its shim;
|
|
36
|
+
* re-raised only when an integration is requested explicitly.
|
|
37
|
+
*/
|
|
38
|
+
export declare class DidNotEnable extends Error {
|
|
39
|
+
constructor(message: string);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Everything an integration needs to wire itself into the shared pipeline.
|
|
43
|
+
*
|
|
44
|
+
* Most JS framework hooks (the OpenAI Agents processor, the LangChain handler,
|
|
45
|
+
* the Mastra exporter) own their own OTLP export pipeline and only need the
|
|
46
|
+
* `token` / `serviceName` / `baseUrl`. Instrumentors that emit onto the shared
|
|
47
|
+
* `TracerProvider` (Anthropic, Gemini, Vercel AI SDK, Pi) use `tracerProvider`.
|
|
48
|
+
*/
|
|
49
|
+
export interface IntegrationSetupContext {
|
|
50
|
+
/** The shared provider built (or adopted) by `init()`. */
|
|
51
|
+
tracerProvider: BasicTracerProvider;
|
|
52
|
+
/** Auth token resolved by `init()` (arg → env). */
|
|
53
|
+
token?: string;
|
|
54
|
+
/** Service name resolved by `init()`. */
|
|
55
|
+
serviceName?: string;
|
|
56
|
+
/** OTLP base URL resolved by `init()`. */
|
|
57
|
+
baseUrl?: string;
|
|
58
|
+
/** Advanced options (custom exporter for tests, headers, …). */
|
|
59
|
+
advanced?: AdvancedOptions;
|
|
60
|
+
/** Mutable bag for integrations to publish pre-bound framework handles. */
|
|
61
|
+
handles: IntegrationHandles;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A framework integration. Each built-in integration is a singleton object;
|
|
65
|
+
* users may also pass custom integrations to `init({ integrations: [...] })`.
|
|
66
|
+
*/
|
|
67
|
+
export interface Integration {
|
|
68
|
+
/** Stable identifier used for the run-once guard and `deactivates`. */
|
|
69
|
+
readonly identifier: string;
|
|
70
|
+
/**
|
|
71
|
+
* Identifiers of other integrations to disable when this one is active, so a
|
|
72
|
+
* wrapping framework (e.g. LangChain) does not double-trace the SDK it wraps.
|
|
73
|
+
*/
|
|
74
|
+
readonly deactivates?: readonly string[];
|
|
75
|
+
/**
|
|
76
|
+
* Wire the framework into the shared pipeline. Runs once; may throw
|
|
77
|
+
* {@link DidNotEnable}. May return a teardown callback (e.g. to uninstrument a
|
|
78
|
+
* prototype patch) that `introspection.shutdown()` runs so a later `init()`
|
|
79
|
+
* re-installs cleanly against the rebuilt provider.
|
|
80
|
+
*/
|
|
81
|
+
setupOnce(ctx: IntegrationSetupContext): void | (() => void);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/otel/integrations/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAE5D;;;;;;;;;GASG;AACH,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,CAAC,EAAE,4BAA4B,CAAC;IAEhD,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,cAAc,CAAC,EAAE,2BAA2B,CAAC;IAC7C,qBAAqB,CAAC,EAAE,CAEtB,GAAG,EAAE,GAAG,KACL,0BAA0B,CAAC;CACjC;AAED;;;;;;GAMG;AACH,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAuB;IACtC,0DAA0D;IAC1D,cAAc,EAAE,mBAAmB,CAAC;IACpC,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,2EAA2E;IAC3E,OAAO,EAAE,kBAAkB,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,uBAAuB,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;CAC9D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration base contract, modeled on Sentry's integration registry and the
|
|
3
|
+
* Python SDK's `Integration` ABC.
|
|
4
|
+
*
|
|
5
|
+
* An {@link Integration} knows how to wire one framework (Anthropic, Gemini,
|
|
6
|
+
* OpenAI Agents, …) into the shared Introspection trace pipeline. `init()`
|
|
7
|
+
* discovers the integrations whose framework is importable and runs each
|
|
8
|
+
* `setupOnce()` exactly once.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Thrown by an integration module/`setupOnce` when the framework cannot be
|
|
12
|
+
* activated (package missing, version too old, …).
|
|
13
|
+
*
|
|
14
|
+
* Swallowed during auto-discovery so a missing framework just skips its shim;
|
|
15
|
+
* re-raised only when an integration is requested explicitly.
|
|
16
|
+
*/
|
|
17
|
+
export class DidNotEnable extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "DidNotEnable";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/otel/integrations/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA8BH;;;;;;GAMG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Agent SDK integration.
|
|
3
|
+
*
|
|
4
|
+
* The Claude Agent SDK is instrumented by wrapping its module
|
|
5
|
+
* (`withIntrospection(sdk)`), which there is no global hook for. So this
|
|
6
|
+
* integration publishes a pre-bound `instrumentClaudeAgent(sdk)` handle that
|
|
7
|
+
* `init()` re-exposes as `introspection.instrumentClaudeAgent(sdk)`.
|
|
8
|
+
*/
|
|
9
|
+
import "@anthropic-ai/claude-agent-sdk";
|
|
10
|
+
import type { Integration } from "./base.js";
|
|
11
|
+
declare const integration: Integration;
|
|
12
|
+
export default integration;
|
|
13
|
+
//# sourceMappingURL=claude-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-agent.d.ts","sourceRoot":"","sources":["../../../src/otel/integrations/claude-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,gCAAgC,CAAC;AAGxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,QAAA,MAAM,WAAW,EAAE,WAclB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Agent SDK integration.
|
|
3
|
+
*
|
|
4
|
+
* The Claude Agent SDK is instrumented by wrapping its module
|
|
5
|
+
* (`withIntrospection(sdk)`), which there is no global hook for. So this
|
|
6
|
+
* integration publishes a pre-bound `instrumentClaudeAgent(sdk)` handle that
|
|
7
|
+
* `init()` re-exposes as `introspection.instrumentClaudeAgent(sdk)`.
|
|
8
|
+
*/
|
|
9
|
+
// Presence gate.
|
|
10
|
+
import "@anthropic-ai/claude-agent-sdk";
|
|
11
|
+
import { withIntrospection } from "../claude-wrapper.js";
|
|
12
|
+
const integration = {
|
|
13
|
+
identifier: "claude_agent",
|
|
14
|
+
setupOnce({ token, serviceName, baseUrl, advanced, handles }) {
|
|
15
|
+
handles.instrumentClaudeAgent = (sdk) => withIntrospection(sdk, {
|
|
16
|
+
token,
|
|
17
|
+
serviceName,
|
|
18
|
+
baseUrl,
|
|
19
|
+
additionalHeaders: advanced?.additionalHeaders,
|
|
20
|
+
advanced: advanced?.spanExporter
|
|
21
|
+
? { spanExporter: advanced.spanExporter }
|
|
22
|
+
: undefined,
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export default integration;
|
|
27
|
+
//# sourceMappingURL=claude-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-agent.js","sourceRoot":"","sources":["../../../src/otel/integrations/claude-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,iBAAiB;AACjB,OAAO,gCAAgC,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD,MAAM,WAAW,GAAgB;IAC/B,UAAU,EAAE,cAAc;IAC1B,SAAS,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE;QAC1D,OAAO,CAAC,qBAAqB,GAAG,CAAC,GAAG,EAAE,EAAE,CACtC,iBAAiB,CAAC,GAAG,EAAE;YACrB,KAAK;YACL,WAAW;YACX,OAAO;YACP,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB;YAC9C,QAAQ,EAAE,QAAQ,EAAE,YAAY;gBAC9B,CAAC,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE;gBACzC,CAAC,CAAC,SAAS;SACd,CAAC,CAAC;IACP,CAAC;CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini (`@google/genai`) integration.
|
|
3
|
+
*
|
|
4
|
+
* Patches `Models.prototype.generateContentInternal` / `…StreamInternal` so
|
|
5
|
+
* every `GoogleGenAI` client is traced. Preserves the thought-signature
|
|
6
|
+
* capture the standalone `GeminiInstrumentor` is built for.
|
|
7
|
+
*/
|
|
8
|
+
import type { Integration } from "./base.js";
|
|
9
|
+
declare const integration: Integration;
|
|
10
|
+
export default integration;
|
|
11
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/otel/integrations/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,QAAA,MAAM,WAAW,EAAE,WASlB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini (`@google/genai`) integration.
|
|
3
|
+
*
|
|
4
|
+
* Patches `Models.prototype.generateContentInternal` / `…StreamInternal` so
|
|
5
|
+
* every `GoogleGenAI` client is traced. Preserves the thought-signature
|
|
6
|
+
* capture the standalone `GeminiInstrumentor` is built for.
|
|
7
|
+
*/
|
|
8
|
+
import * as genai from "@google/genai";
|
|
9
|
+
import { GeminiInstrumentor } from "../gemini.js";
|
|
10
|
+
const integration = {
|
|
11
|
+
identifier: "gemini",
|
|
12
|
+
setupOnce({ tracerProvider }) {
|
|
13
|
+
const instrumentor = new GeminiInstrumentor();
|
|
14
|
+
instrumentor.instrumentClass({ genai, tracerProvider });
|
|
15
|
+
// Restore the original prototype on shutdown so a later init() re-patches
|
|
16
|
+
// against the rebuilt provider (the patch captures the provider's tracer).
|
|
17
|
+
return () => instrumentor.uninstrument();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export default integration;
|
|
21
|
+
//# sourceMappingURL=gemini.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/otel/integrations/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,MAAM,WAAW,GAAgB;IAC/B,UAAU,EAAE,QAAQ;IACpB,SAAS,CAAC,EAAE,cAAc,EAAE;QAC1B,MAAM,YAAY,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC9C,YAAY,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;QACxD,0EAA0E;QAC1E,2EAA2E;QAC3E,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;IAC3C,CAAC;CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration discovery + setup loader for `introspection.init()`.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Python SDK's registry: built-in integrations are resolved
|
|
5
|
+
* lazily (a missing framework just skips its shim), `setupOnce` runs at most
|
|
6
|
+
* once per identifier per process, and an integration may `deactivate` others.
|
|
7
|
+
*/
|
|
8
|
+
import { DidNotEnable, type Integration, type IntegrationHandles, type IntegrationSetupContext } from "./base.js";
|
|
9
|
+
export { DidNotEnable };
|
|
10
|
+
export type { Integration, IntegrationHandles, IntegrationSetupContext };
|
|
11
|
+
/**
|
|
12
|
+
* Distinguish "framework package not installed" (expected — skip quietly) from
|
|
13
|
+
* a real error inside an installed integration (a bug we shouldn't hide).
|
|
14
|
+
*/
|
|
15
|
+
export declare function isModuleNotFound(e: unknown): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Return the built-in integrations whose framework is importable.
|
|
18
|
+
*
|
|
19
|
+
* Each module's top-level framework import determines availability: a missing
|
|
20
|
+
* package makes the dynamic import reject, which we log at debug and skip. Any
|
|
21
|
+
* OTHER failure (a real error inside an installed integration) is surfaced at
|
|
22
|
+
* warn level rather than silently swallowed — it's a bug, not an absent peer.
|
|
23
|
+
*/
|
|
24
|
+
export declare function discoverIntegrations(): Promise<Integration[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Run each integration's `setupOnce` once, honouring `deactivates`.
|
|
27
|
+
*
|
|
28
|
+
* @returns the set of identifiers installed so far this process.
|
|
29
|
+
*/
|
|
30
|
+
export declare function setupIntegrations(integrations: Integration[], ctx: IntegrationSetupContext): Set<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Run every integration teardown and clear the run-once guard, so the next
|
|
33
|
+
* `setupIntegrations()` (e.g. after `introspection.shutdown()` + a fresh
|
|
34
|
+
* `init()`) re-installs against the rebuilt provider instead of being skipped.
|
|
35
|
+
*/
|
|
36
|
+
export declare function teardownIntegrations(): void;
|
|
37
|
+
/** Clear the run-once guard (running teardowns). Test-only utility. */
|
|
38
|
+
export declare function resetInstalledForTests(): void;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/otel/integrations/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC7B,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,CAAC;AA0BzE;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAOpD;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAmBnE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,WAAW,EAAE,EAC3B,GAAG,EAAE,uBAAuB,GAC3B,GAAG,CAAC,MAAM,CAAC,CAoCb;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAS3C;AAED,uEAAuE;AACvE,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
|