@introspection-sdk/introspection-node 0.4.3 → 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/otel/anthropic.d.ts +14 -12
- package/dist/otel/anthropic.d.ts.map +1 -1
- package/dist/otel/anthropic.js +89 -47
- package/dist/otel/anthropic.js.map +1 -1
- package/dist/otel/gemini.d.ts +15 -7
- package/dist/otel/gemini.d.ts.map +1 -1
- package/dist/otel/gemini.js +88 -37
- package/dist/otel/gemini.js.map +1 -1
- package/dist/otel/index.d.ts +5 -0
- package/dist/otel/index.d.ts.map +1 -1
- package/dist/otel/index.js +8 -0
- package/dist/otel/index.js.map +1 -1
- 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/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 +29 -0
- package/dist/otel/setup.d.ts.map +1 -1
- package/dist/otel/setup.js +22 -3
- package/dist/otel/setup.js.map +1 -1
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +12 -4
- package/dist/utils.js.map +1 -1
- package/package.json +17 -5
- package/src/otel/anthropic.ts +128 -63
- package/src/otel/gemini.ts +139 -45
- package/src/otel/index.ts +41 -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/otel/register.ts +50 -0
- package/src/otel/setup.ts +44 -3
- package/src/utils.ts +12 -5
- package/.turbo/turbo-check-types.log +0 -4
- package/.turbo/turbo-lint.log +0 -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 +0 -54
- package/dist/anthropic.d.ts.map +0 -1
- package/dist/anthropic.js +0 -375
- package/dist/claude-hooks.d.ts +0 -328
- package/dist/claude-hooks.d.ts.map +0 -1
- package/dist/claude-hooks.js +0 -571
- package/dist/claude-wrapper.d.ts +0 -93
- package/dist/claude-wrapper.d.ts.map +0 -1
- package/dist/claude-wrapper.js +0 -154
- 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/converters/openclaw.d.ts +0 -16
- package/dist/converters/openclaw.d.ts.map +0 -1
- package/dist/converters/openclaw.js +0 -49
- package/dist/langchain-handler.d.ts +0 -103
- package/dist/langchain-handler.d.ts.map +0 -1
- package/dist/langchain-handler.js +0 -518
- package/dist/mastra-exporter.d.ts +0 -85
- package/dist/mastra-exporter.d.ts.map +0 -1
- package/dist/mastra-exporter.js +0 -471
- package/dist/span-processor.d.ts +0 -62
- package/dist/span-processor.d.ts.map +0 -1
- package/dist/span-processor.js +0 -313
- package/dist/tracing-processor.d.ts +0 -136
- package/dist/tracing-processor.d.ts.map +0 -1
- package/dist/tracing-processor.js +0 -368
- package/dist/types/genai.d.ts +0 -165
- package/dist/types/genai.d.ts.map +0 -1
- package/dist/types/genai.js +0 -82
|
@@ -0,0 +1,126 @@
|
|
|
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 { type TracerProvider } from "@opentelemetry/api";
|
|
23
|
+
import type { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
24
|
+
import type { AdvancedOptions, FeedbackOptions, UserTraits } from "../types.js";
|
|
25
|
+
import type { InstrumentedClaudeAgentSDK } from "./claude-wrapper.js";
|
|
26
|
+
import { type Integration } from "./integrations/index.js";
|
|
27
|
+
import type { Agent } from "@mariozechner/pi-agent-core";
|
|
28
|
+
import type { AgentMeta } from "./pi.js";
|
|
29
|
+
import { IntrospectionLogs } from "./logs.js";
|
|
30
|
+
import { type ConflictBehavior } from "./setup.js";
|
|
31
|
+
/** Options for {@link init}. */
|
|
32
|
+
export interface InitOptions {
|
|
33
|
+
/** Auth token. Falls back to `INTROSPECTION_TOKEN`. */
|
|
34
|
+
token?: string;
|
|
35
|
+
/** Service name for spans. Falls back to `INTROSPECTION_SERVICE_NAME`. */
|
|
36
|
+
serviceName?: string;
|
|
37
|
+
/** OTLP base URL. Falls back to `INTROSPECTION_BASE_OTEL_URL`. */
|
|
38
|
+
baseUrl?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Use this provider instead of creating one. The caller owns its span
|
|
41
|
+
* processors (attach an {@link IntrospectionSpanProcessor} yourself).
|
|
42
|
+
*/
|
|
43
|
+
tracerProvider?: TracerProvider;
|
|
44
|
+
/**
|
|
45
|
+
* Extra span processors composed onto the provider `init()` creates — the
|
|
46
|
+
* one-call dual-export path. Each runs alongside the Introspection processor,
|
|
47
|
+
* e.g. `init({ spanProcessors: [new BatchSpanProcessor(langfuseExporter)] })`.
|
|
48
|
+
* Ignored when `tracerProvider` is supplied.
|
|
49
|
+
*/
|
|
50
|
+
spanProcessors?: SpanProcessor[];
|
|
51
|
+
/** Extra integrations to install beyond auto-discovery. */
|
|
52
|
+
integrations?: Integration[];
|
|
53
|
+
/** Install every importable built-in integration (default `true`). */
|
|
54
|
+
autoDiscover?: boolean;
|
|
55
|
+
/** Behaviour when an OTel context manager / propagator is already registered. */
|
|
56
|
+
onConflict?: ConflictBehavior;
|
|
57
|
+
/** Advanced configuration (custom exporter, headers, …). */
|
|
58
|
+
advanced?: AdvancedOptions;
|
|
59
|
+
}
|
|
60
|
+
/** Generate a fresh conversation id (matches the Python SDK's format). */
|
|
61
|
+
export declare function newConversationId(): string;
|
|
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 declare function init(options?: InitOptions): Promise<TracerProvider>;
|
|
69
|
+
/** Return the global logs client. Throws if {@link init} has not been called. */
|
|
70
|
+
export declare function getClient(): IntrospectionLogs;
|
|
71
|
+
/** Return the shared provider. Throws if {@link init} has not been called. */
|
|
72
|
+
export declare function getTracerProvider(): TracerProvider;
|
|
73
|
+
/** Track an analytics event. Requires {@link init} first. */
|
|
74
|
+
export declare function track(eventName: string, properties?: Record<string, unknown>, options?: {
|
|
75
|
+
eventId?: string;
|
|
76
|
+
}): void;
|
|
77
|
+
/** Record feedback on an AI response. Requires {@link init} first. */
|
|
78
|
+
export declare function feedback(name: string, options?: FeedbackOptions): void;
|
|
79
|
+
/** Associate the current context with a user. Requires {@link init} first. */
|
|
80
|
+
export declare function identify(userId: string, traits?: UserTraits, anonymousId?: string, eventId?: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Run `callback` inside a conversation scope: every span/event produced within
|
|
83
|
+
* is stamped with `gen_ai.conversation.id`. Generates an id when none is given.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* await introspection.conversation((id) => client.messages.create({ ... }));
|
|
87
|
+
* await introspection.conversation("conv_123", (id) => run());
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function conversation<T>(callback: (conversationId: string) => T | Promise<T>): Promise<T>;
|
|
91
|
+
export declare function conversation<T>(conversationId: string, callback: (conversationId: string) => T | Promise<T>): Promise<T>;
|
|
92
|
+
/**
|
|
93
|
+
* Run `callback` with `gen_ai.agent.name` (+ optional `gen_ai.agent.id`) on the
|
|
94
|
+
* baggage, so spans/events produced within are attributed to that agent.
|
|
95
|
+
* Requires {@link init} first. Mirrors `IntrospectionLogs.withAgent`.
|
|
96
|
+
*/
|
|
97
|
+
export declare function withAgent<T>(agentName: string, agentId: string | undefined, callback: () => T | Promise<T>): Promise<T>;
|
|
98
|
+
/**
|
|
99
|
+
* Run `callback` inside a conversation scope, optionally chaining a previous
|
|
100
|
+
* response id. Unlike {@link conversation}, the id is required (no auto-gen).
|
|
101
|
+
* Requires {@link init} first.
|
|
102
|
+
*/
|
|
103
|
+
export declare function withConversation<T>(conversationId: string | undefined, previousResponseId: string | undefined, callback: () => T | Promise<T>): Promise<T>;
|
|
104
|
+
/** Run `callback` with `identity.user_id` on the baggage. Requires {@link init} first. */
|
|
105
|
+
export declare function withUserId<T>(userId: string, callback: () => T | Promise<T>): Promise<T>;
|
|
106
|
+
/** Run `callback` with `identity.anonymous_id` on the baggage. Requires {@link init} first. */
|
|
107
|
+
export declare function withAnonymousId<T>(anonymousId: string, callback: () => T | Promise<T>): Promise<T>;
|
|
108
|
+
/**
|
|
109
|
+
* The LangChain handler bound by `init()`. Attach it per-invoke:
|
|
110
|
+
* `chain.invoke(input, { callbacks: [introspection.getLangchainHandler()] })`.
|
|
111
|
+
*/
|
|
112
|
+
export declare function getLangchainHandler(): import("./langchain-handler.js").IntrospectionCallbackHandler;
|
|
113
|
+
/** The Mastra exporter bound by `init()`. Put it in `observability.configs`. */
|
|
114
|
+
export declare function getMastraExporter(): any;
|
|
115
|
+
/** Instrument a Pi `Agent` against the shared provider. Requires {@link init}. */
|
|
116
|
+
export declare function instrumentPi(agent: Agent, meta: AgentMeta): void;
|
|
117
|
+
/**
|
|
118
|
+
* Wrap the Claude Agent SDK module so its `query()` calls are traced.
|
|
119
|
+
* Equivalent to `withIntrospection(sdk)` but pre-bound to the `init()` config.
|
|
120
|
+
*/
|
|
121
|
+
export declare function instrumentClaudeAgent(sdk: any): InstrumentedClaudeAgentSDK;
|
|
122
|
+
/** Flush and shut down the logs client and (if owned) the provider. */
|
|
123
|
+
export declare function shutdown(): Promise<void>;
|
|
124
|
+
/** Reset module state. Test-only utility. */
|
|
125
|
+
export declare function _resetForTests(): void;
|
|
126
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/otel/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAEV,aAAa,EACd,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAIL,KAAK,WAAW,EAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAA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nB,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,kEAQlC;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,QAQhC;AAED,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI,CAQhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAEnC,GAAG,EAAE,GAAG,GACP,0BAA0B,CAQ5B;AAED,uEAAuE;AACvE,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAwB9C;AAED,6CAA6C;AAC7C,wBAAgB,cAAc,IAAI,IAAI,CAMrC"}
|
|
@@ -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,0BA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
|
|
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,EA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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
|