@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,151 @@
|
|
|
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
|
+
|
|
9
|
+
import { logger } from "../../utils.js";
|
|
10
|
+
import {
|
|
11
|
+
DidNotEnable,
|
|
12
|
+
type Integration,
|
|
13
|
+
type IntegrationHandles,
|
|
14
|
+
type IntegrationSetupContext,
|
|
15
|
+
} from "./base.js";
|
|
16
|
+
|
|
17
|
+
export { DidNotEnable };
|
|
18
|
+
export type { Integration, IntegrationHandles, IntegrationSetupContext };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Built-in integrations, loaded lazily. Each thunk dynamically imports an
|
|
22
|
+
* integration module; that module imports its framework at the top level, so
|
|
23
|
+
* if the framework is not installed the import rejects and the integration is
|
|
24
|
+
* skipped. Order matters only for `deactivates` resolution (handled below).
|
|
25
|
+
*/
|
|
26
|
+
const BUILTIN_INTEGRATIONS: ReadonlyArray<
|
|
27
|
+
() => Promise<{ default: Integration }>
|
|
28
|
+
> = [
|
|
29
|
+
() => import("./anthropic.js"),
|
|
30
|
+
() => import("./gemini.js"),
|
|
31
|
+
() => import("./openai-agents.js"),
|
|
32
|
+
() => import("./vercel.js"),
|
|
33
|
+
() => import("./claude-agent.js"),
|
|
34
|
+
() => import("./langchain.js"),
|
|
35
|
+
() => import("./mastra.js"),
|
|
36
|
+
() => import("./pi.js"),
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const installed = new Set<string>();
|
|
40
|
+
// Teardown callbacks returned by integration setupOnce (e.g. uninstrument a
|
|
41
|
+
// prototype patch), run by teardownIntegrations() on shutdown.
|
|
42
|
+
const teardowns: Array<() => void> = [];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Distinguish "framework package not installed" (expected — skip quietly) from
|
|
46
|
+
* a real error inside an installed integration (a bug we shouldn't hide).
|
|
47
|
+
*/
|
|
48
|
+
export function isModuleNotFound(e: unknown): boolean {
|
|
49
|
+
const code = (e as { code?: string } | null)?.code;
|
|
50
|
+
if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
54
|
+
return /Cannot find (module|package)|Failed to resolve/i.test(msg);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Return the built-in integrations whose framework is importable.
|
|
59
|
+
*
|
|
60
|
+
* Each module's top-level framework import determines availability: a missing
|
|
61
|
+
* package makes the dynamic import reject, which we log at debug and skip. Any
|
|
62
|
+
* OTHER failure (a real error inside an installed integration) is surfaced at
|
|
63
|
+
* warn level rather than silently swallowed — it's a bug, not an absent peer.
|
|
64
|
+
*/
|
|
65
|
+
export async function discoverIntegrations(): Promise<Integration[]> {
|
|
66
|
+
const found: Integration[] = [];
|
|
67
|
+
for (const load of BUILTIN_INTEGRATIONS) {
|
|
68
|
+
try {
|
|
69
|
+
const mod = await load();
|
|
70
|
+
if (mod.default) found.push(mod.default);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
if (isModuleNotFound(e)) {
|
|
73
|
+
logger.debug(
|
|
74
|
+
`Skipping integration (framework not installed): ${String(e)}`,
|
|
75
|
+
);
|
|
76
|
+
} else {
|
|
77
|
+
logger.warn(
|
|
78
|
+
`Integration failed to load with an unexpected error (skipping): ${String(e)}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return found;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Run each integration's `setupOnce` once, honouring `deactivates`.
|
|
88
|
+
*
|
|
89
|
+
* @returns the set of identifiers installed so far this process.
|
|
90
|
+
*/
|
|
91
|
+
export function setupIntegrations(
|
|
92
|
+
integrations: Integration[],
|
|
93
|
+
ctx: IntegrationSetupContext,
|
|
94
|
+
): Set<string> {
|
|
95
|
+
// First-wins de-dupe by identifier.
|
|
96
|
+
const byId = new Map<string, Integration>();
|
|
97
|
+
for (const integration of integrations) {
|
|
98
|
+
if (!byId.has(integration.identifier)) {
|
|
99
|
+
byId.set(integration.identifier, integration);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const disabled = new Set<string>();
|
|
104
|
+
for (const integration of byId.values()) {
|
|
105
|
+
for (const id of integration.deactivates ?? []) disabled.add(id);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for (const [identifier, integration] of byId) {
|
|
109
|
+
if (disabled.has(identifier)) {
|
|
110
|
+
logger.debug(
|
|
111
|
+
`Skipping ${identifier} (deactivated by another integration)`,
|
|
112
|
+
);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (installed.has(identifier)) continue;
|
|
116
|
+
try {
|
|
117
|
+
const teardown = integration.setupOnce(ctx);
|
|
118
|
+
if (typeof teardown === "function") teardowns.push(teardown);
|
|
119
|
+
installed.add(identifier);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
if (e instanceof DidNotEnable) {
|
|
122
|
+
logger.debug(`Could not enable ${identifier}: ${e.message}`);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return new Set(installed);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Run every integration teardown and clear the run-once guard, so the next
|
|
134
|
+
* `setupIntegrations()` (e.g. after `introspection.shutdown()` + a fresh
|
|
135
|
+
* `init()`) re-installs against the rebuilt provider instead of being skipped.
|
|
136
|
+
*/
|
|
137
|
+
export function teardownIntegrations(): void {
|
|
138
|
+
for (const teardown of teardowns.splice(0)) {
|
|
139
|
+
try {
|
|
140
|
+
teardown();
|
|
141
|
+
} catch (e) {
|
|
142
|
+
logger.debug(`Error tearing down integration: ${String(e)}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
installed.clear();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Clear the run-once guard (running teardowns). Test-only utility. */
|
|
149
|
+
export function resetInstalledForTests(): void {
|
|
150
|
+
teardownIntegrations();
|
|
151
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain / LangGraph integration.
|
|
3
|
+
*
|
|
4
|
+
* The callback handler is attached per-invoke (`chain.invoke(input, { callbacks
|
|
5
|
+
* })`), so this integration builds the handler — pre-bound to the `init()`
|
|
6
|
+
* token — and publishes it via `introspection.getLangchainHandler()`.
|
|
7
|
+
*
|
|
8
|
+
* Deactivates the Anthropic integration: when LangChain drives the Anthropic
|
|
9
|
+
* model, the handler already traces the call, so the prototype-level Anthropic
|
|
10
|
+
* patch would double-trace it.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Presence gate.
|
|
14
|
+
import "@langchain/core/callbacks/base";
|
|
15
|
+
|
|
16
|
+
import { IntrospectionCallbackHandler } from "../langchain-handler.js";
|
|
17
|
+
import type { Integration } from "./base.js";
|
|
18
|
+
|
|
19
|
+
const integration: Integration = {
|
|
20
|
+
identifier: "langchain",
|
|
21
|
+
// Intentional, and matches the Python SDK: when @langchain/core is present,
|
|
22
|
+
// auto-discovery skips the always-on raw-Anthropic prototype patch so a
|
|
23
|
+
// LangChain → ChatAnthropic call isn't traced twice (once by LangChain's
|
|
24
|
+
// callback handler, once by the raw `messages.create` patch).
|
|
25
|
+
//
|
|
26
|
+
// Trade-off (by design): if an app has BOTH @langchain/core installed AND
|
|
27
|
+
// makes raw `@anthropic-ai/sdk` calls outside LangChain, those raw calls
|
|
28
|
+
// won't be auto-traced. To trace them, instrument explicitly with
|
|
29
|
+
// `new AnthropicInstrumentor().instrumentClass(...)`, or call
|
|
30
|
+
// `init({ autoDiscover: false, integrations: [anthropicIntegration] })`.
|
|
31
|
+
deactivates: ["anthropic"],
|
|
32
|
+
setupOnce({ token, serviceName, baseUrl, advanced, handles }) {
|
|
33
|
+
handles.langchainHandler = new IntrospectionCallbackHandler({
|
|
34
|
+
token,
|
|
35
|
+
serviceName,
|
|
36
|
+
baseUrl,
|
|
37
|
+
additionalHeaders: advanced?.additionalHeaders,
|
|
38
|
+
advanced: advanced?.spanExporter
|
|
39
|
+
? { spanExporter: advanced.spanExporter }
|
|
40
|
+
: undefined,
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default integration;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mastra integration.
|
|
3
|
+
*
|
|
4
|
+
* The Mastra exporter is wired into Mastra's `observability.configs` rather
|
|
5
|
+
* than globally, so this integration builds the exporter — pre-bound to the
|
|
6
|
+
* `init()` token — and publishes it via `introspection.getMastraExporter()`.
|
|
7
|
+
*
|
|
8
|
+
* Importing `../mastra-exporter.js` (which requires `@mastra/observability`)
|
|
9
|
+
* is the presence gate: a missing Mastra makes discovery skip this shim.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { IntrospectionMastraExporter } from "../mastra-exporter.js";
|
|
13
|
+
import type { Integration } from "./base.js";
|
|
14
|
+
|
|
15
|
+
const integration: Integration = {
|
|
16
|
+
identifier: "mastra",
|
|
17
|
+
setupOnce({ token, baseUrl, advanced, handles }) {
|
|
18
|
+
handles.mastraExporter = new IntrospectionMastraExporter({
|
|
19
|
+
token,
|
|
20
|
+
baseUrl,
|
|
21
|
+
additionalHeaders: advanced?.additionalHeaders,
|
|
22
|
+
debug: advanced?.debug,
|
|
23
|
+
advanced: advanced?.spanExporter
|
|
24
|
+
? { spanExporter: advanced.spanExporter }
|
|
25
|
+
: undefined,
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default integration;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Agents SDK integration.
|
|
3
|
+
*
|
|
4
|
+
* Registers an {@link IntrospectionTracingProcessor} with the Agents SDK's
|
|
5
|
+
* global trace pipeline. `addTraceProcessor` appends, preserving any processors
|
|
6
|
+
* other integrations (e.g. a vendor exporter) already registered.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { addTraceProcessor } from "@openai/agents";
|
|
10
|
+
|
|
11
|
+
import { IntrospectionTracingProcessor } from "../tracing-processor.js";
|
|
12
|
+
import type { Integration } from "./base.js";
|
|
13
|
+
|
|
14
|
+
const integration: Integration = {
|
|
15
|
+
identifier: "openai_agents",
|
|
16
|
+
setupOnce({ token, serviceName, baseUrl, advanced }) {
|
|
17
|
+
addTraceProcessor(
|
|
18
|
+
new IntrospectionTracingProcessor({
|
|
19
|
+
token,
|
|
20
|
+
serviceName,
|
|
21
|
+
baseUrl,
|
|
22
|
+
additionalHeaders: advanced?.additionalHeaders,
|
|
23
|
+
advanced: advanced?.spanExporter
|
|
24
|
+
? { spanExporter: advanced.spanExporter }
|
|
25
|
+
: undefined,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default integration;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Agent SDK integration.
|
|
3
|
+
*
|
|
4
|
+
* The Pi instrumentor wraps a specific `Agent` instance, so this integration
|
|
5
|
+
* builds the instrumentor — bound to the shared provider's global tracer — and
|
|
6
|
+
* publishes it via `introspection.instrumentPi(agent, meta)`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Presence gate.
|
|
10
|
+
import "@mariozechner/pi-agent-core";
|
|
11
|
+
|
|
12
|
+
import { IntrospectionPiInstrumentor } from "../pi.js";
|
|
13
|
+
import type { Integration } from "./base.js";
|
|
14
|
+
|
|
15
|
+
const integration: Integration = {
|
|
16
|
+
identifier: "pi",
|
|
17
|
+
setupOnce({ handles }) {
|
|
18
|
+
// The instrumentor emits onto the global tracer, which `init()` has just
|
|
19
|
+
// registered with the shared IntrospectionSpanProcessor.
|
|
20
|
+
handles.piInstrumentor = new IntrospectionPiInstrumentor();
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default integration;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel AI SDK integration.
|
|
3
|
+
*
|
|
4
|
+
* The AI SDK emits `ai.*` / `gen_ai.*` attributes natively via OTel when
|
|
5
|
+
* `experimental_telemetry` is enabled. The shared provider already carries an
|
|
6
|
+
* {@link IntrospectionSpanProcessor}, which converts those `ai.*` attributes to
|
|
7
|
+
* canonical `gen_ai.*` semconv at span end — so there is nothing to patch here.
|
|
8
|
+
* This integration exists so auto-discovery reports the AI SDK as detected and
|
|
9
|
+
* (via its top-level import) is skipped when `ai` is not installed.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Presence gate: a missing `ai` package makes this module's import reject.
|
|
13
|
+
import "ai";
|
|
14
|
+
|
|
15
|
+
import type { Integration } from "./base.js";
|
|
16
|
+
|
|
17
|
+
const integration: Integration = {
|
|
18
|
+
identifier: "vercel",
|
|
19
|
+
setupOnce() {
|
|
20
|
+
// No-op: the shared IntrospectionSpanProcessor converts AI SDK spans.
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default integration;
|
|
@@ -34,6 +34,7 @@ import type { ChainValues } from "@langchain/core/utils/types";
|
|
|
34
34
|
|
|
35
35
|
import {
|
|
36
36
|
context as otelContext,
|
|
37
|
+
propagation,
|
|
37
38
|
ROOT_CONTEXT,
|
|
38
39
|
SpanStatusCode,
|
|
39
40
|
trace as otelTrace,
|
|
@@ -51,8 +52,8 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
51
52
|
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
52
53
|
import { randomUUID } from "crypto";
|
|
53
54
|
|
|
54
|
-
import { logger, withOtlpHttpsProxy } from "
|
|
55
|
-
import { VERSION } from "
|
|
55
|
+
import { logger, withOtlpHttpsProxy } from "../utils.js";
|
|
56
|
+
import { VERSION } from "../version.js";
|
|
56
57
|
import type {
|
|
57
58
|
InputMessage,
|
|
58
59
|
OutputMessage,
|
|
@@ -77,7 +78,7 @@ export interface LangChainHandlerAdvancedOptions {
|
|
|
77
78
|
export interface IntrospectionCallbackHandlerOptions {
|
|
78
79
|
/** Authentication token (env: INTROSPECTION_TOKEN). */
|
|
79
80
|
token?: string;
|
|
80
|
-
/** Base URL for the API (env:
|
|
81
|
+
/** Base URL for the API (env: INTROSPECTION_BASE_OTEL_URL). */
|
|
81
82
|
baseUrl?: string;
|
|
82
83
|
/** Service name for telemetry (env: INTROSPECTION_SERVICE_NAME). */
|
|
83
84
|
serviceName?: string;
|
|
@@ -143,7 +144,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
143
144
|
|
|
144
145
|
const baseUrl =
|
|
145
146
|
options.baseUrl ||
|
|
146
|
-
process.env.
|
|
147
|
+
process.env.INTROSPECTION_BASE_OTEL_URL ||
|
|
147
148
|
"https://otel.introspection.dev";
|
|
148
149
|
|
|
149
150
|
const endpoint = baseUrl.endsWith("/v1/traces")
|
|
@@ -246,11 +247,17 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
246
247
|
this._spanParents.set(runId, parentRunId);
|
|
247
248
|
}
|
|
248
249
|
|
|
249
|
-
//
|
|
250
|
-
|
|
250
|
+
// Baggage wins so per-call agent identity (e.g. via withAgent())
|
|
251
|
+
// overrides the parent-span-name walk used as a default.
|
|
252
|
+
const baggageAgentName = this._readBaggage("gen_ai.agent.name");
|
|
253
|
+
const agentName = baggageAgentName || this._findAgentName(parentRunId);
|
|
251
254
|
if (agentName) {
|
|
252
255
|
span.setAttribute("gen_ai.agent.name", agentName);
|
|
253
256
|
}
|
|
257
|
+
const baggageAgentId = this._readBaggage("gen_ai.agent.id");
|
|
258
|
+
if (baggageAgentId) {
|
|
259
|
+
span.setAttribute("gen_ai.agent.id", baggageAgentId);
|
|
260
|
+
}
|
|
254
261
|
|
|
255
262
|
return span;
|
|
256
263
|
}
|
|
@@ -452,6 +459,31 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
452
459
|
if (typeof outputTokens === "number") {
|
|
453
460
|
otelSpan.setAttribute("gen_ai.usage.output_tokens", outputTokens);
|
|
454
461
|
}
|
|
462
|
+
// Flat field (legacy format) or nested cache_creation object (Claude 4+).
|
|
463
|
+
const cacheCreationObj = tokenUsage["cache_creation"] as
|
|
464
|
+
| Record<string, unknown>
|
|
465
|
+
| undefined;
|
|
466
|
+
const cacheWriteTokens =
|
|
467
|
+
tokenUsage["cache_creation_input_tokens"] ||
|
|
468
|
+
tokenUsage["cacheCreationInputTokens"] ||
|
|
469
|
+
((cacheCreationObj?.["ephemeral_5m_input_tokens"] as number) || 0) +
|
|
470
|
+
((cacheCreationObj?.["ephemeral_1h_input_tokens"] as number) || 0) ||
|
|
471
|
+
undefined;
|
|
472
|
+
if (typeof cacheWriteTokens === "number") {
|
|
473
|
+
otelSpan.setAttribute(
|
|
474
|
+
"gen_ai.usage.cache_creation.input_tokens",
|
|
475
|
+
cacheWriteTokens,
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
const cacheReadTokens =
|
|
479
|
+
tokenUsage["cache_read_input_tokens"] ||
|
|
480
|
+
tokenUsage["cacheReadInputTokens"];
|
|
481
|
+
if (typeof cacheReadTokens === "number") {
|
|
482
|
+
otelSpan.setAttribute(
|
|
483
|
+
"gen_ai.usage.cache_read.input_tokens",
|
|
484
|
+
cacheReadTokens,
|
|
485
|
+
);
|
|
486
|
+
}
|
|
455
487
|
}
|
|
456
488
|
|
|
457
489
|
const model = usage?.["model"] || usage?.["model_name"];
|
|
@@ -659,9 +691,24 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
659
691
|
if (threadId !== undefined && threadId !== null) {
|
|
660
692
|
return String(threadId);
|
|
661
693
|
}
|
|
694
|
+
const baggageConvId = this._readBaggage("gen_ai.conversation.id");
|
|
695
|
+
if (baggageConvId) return baggageConvId;
|
|
662
696
|
return this._conversationId;
|
|
663
697
|
}
|
|
664
698
|
|
|
699
|
+
/**
|
|
700
|
+
* Read a single value from the active OTel baggage. Returns undefined when
|
|
701
|
+
* no propagator is installed or the key is absent.
|
|
702
|
+
*
|
|
703
|
+
* Used so callers can scope LangChain calls with
|
|
704
|
+
* `IntrospectionClient.withAgent()` / `.withConversation()` /
|
|
705
|
+
* `.withGenAi()` without threading metadata through every invoke().
|
|
706
|
+
*/
|
|
707
|
+
private _readBaggage(key: string): string | undefined {
|
|
708
|
+
const baggage = propagation.getBaggage(otelContext.active());
|
|
709
|
+
return baggage?.getEntry(key)?.value;
|
|
710
|
+
}
|
|
711
|
+
|
|
665
712
|
private _convertMessages(messages: BaseMessage[]): {
|
|
666
713
|
inputMessages: InputMessage[];
|
|
667
714
|
systemInstructions: string[];
|