@introspection-sdk/introspection-node 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -8
- package/dist/auth.d.ts +1 -1
- package/dist/client.d.ts +4 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +16 -7
- package/dist/client.js.map +1 -1
- package/dist/dev-target.js +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -6
- package/dist/index.js.map +1 -1
- package/dist/otel/index.d.ts +1 -14
- package/dist/otel/index.d.ts.map +1 -1
- package/dist/otel/index.js +10 -18
- package/dist/otel/index.js.map +1 -1
- package/dist/otel/init.d.ts +19 -21
- package/dist/otel/init.d.ts.map +1 -1
- package/dist/otel/init.js +62 -48
- package/dist/otel/init.js.map +1 -1
- package/dist/otel/integrations/base.d.ts +17 -37
- package/dist/otel/integrations/base.d.ts.map +1 -1
- package/dist/otel/integrations/base.js +6 -13
- package/dist/otel/integrations/base.js.map +1 -1
- package/dist/otel/integrations/index.d.ts +3 -4
- package/dist/otel/integrations/index.d.ts.map +1 -1
- package/dist/otel/integrations/index.js +6 -25
- package/dist/otel/integrations/index.js.map +1 -1
- package/dist/otel/integrations/pi.d.ts.map +1 -1
- package/dist/otel/integrations/pi.js +9 -1
- package/dist/otel/integrations/pi.js.map +1 -1
- package/dist/otel/logs.d.ts +41 -8
- package/dist/otel/logs.d.ts.map +1 -1
- package/dist/otel/logs.js +95 -66
- package/dist/otel/logs.js.map +1 -1
- package/dist/otel/pi.d.ts +18 -5
- package/dist/otel/pi.d.ts.map +1 -1
- package/dist/otel/pi.js +38 -9
- package/dist/otel/pi.js.map +1 -1
- package/dist/otel/register.d.ts +2 -2
- package/dist/otel/register.d.ts.map +1 -1
- package/dist/otel/register.js +7 -9
- package/dist/otel/register.js.map +1 -1
- package/dist/otel/setup.d.ts +2 -2
- package/dist/otel/setup.d.ts.map +1 -1
- package/dist/otel/setup.js +16 -6
- package/dist/otel/setup.js.map +1 -1
- package/dist/otel/span-processor.d.ts +18 -5
- package/dist/otel/span-processor.d.ts.map +1 -1
- package/dist/otel/span-processor.js +50 -65
- package/dist/otel/span-processor.js.map +1 -1
- package/dist/resources/experiments.d.ts +10 -5
- package/dist/resources/experiments.d.ts.map +1 -1
- package/dist/resources/experiments.js +9 -25
- package/dist/resources/experiments.js.map +1 -1
- package/dist/resources/recipes.d.ts +6 -6
- package/dist/resources/recipes.d.ts.map +1 -1
- package/dist/resources/recipes.js +5 -23
- package/dist/resources/recipes.js.map +1 -1
- package/dist/resources/runtimes.d.ts +2 -2
- package/dist/resources/runtimes.d.ts.map +1 -1
- package/dist/resources/runtimes.js +2 -2
- package/dist/resources/runtimes.js.map +1 -1
- package/dist/runner.d.ts +8 -4
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +26 -18
- package/dist/runner.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +45 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +61 -2
- package/dist/utils.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +18 -60
- package/.turbo/turbo-build.log +0 -4
- package/dist/converters/claude.d.ts +0 -150
- package/dist/converters/claude.d.ts.map +0 -1
- package/dist/converters/claude.js +0 -211
- package/dist/converters/claude.js.map +0 -1
- package/dist/converters/gemini.d.ts +0 -90
- package/dist/converters/gemini.d.ts.map +0 -1
- package/dist/converters/gemini.js +0 -171
- package/dist/converters/gemini.js.map +0 -1
- package/dist/converters/index.d.ts +0 -9
- package/dist/converters/index.d.ts.map +0 -1
- package/dist/converters/index.js +0 -9
- package/dist/converters/index.js.map +0 -1
- package/dist/converters/openai.d.ts +0 -51
- package/dist/converters/openai.d.ts.map +0 -1
- package/dist/converters/openai.js +0 -269
- package/dist/converters/openai.js.map +0 -1
- package/dist/converters/openinference.d.ts +0 -107
- package/dist/converters/openinference.d.ts.map +0 -1
- package/dist/converters/openinference.js +0 -553
- package/dist/converters/openinference.js.map +0 -1
- package/dist/converters/vercel.d.ts +0 -21
- package/dist/converters/vercel.d.ts.map +0 -1
- package/dist/converters/vercel.js +0 -236
- package/dist/converters/vercel.js.map +0 -1
- package/dist/otel/anthropic.d.ts +0 -63
- package/dist/otel/anthropic.d.ts.map +0 -1
- package/dist/otel/anthropic.js +0 -475
- package/dist/otel/anthropic.js.map +0 -1
- package/dist/otel/claude-hooks.d.ts +0 -346
- package/dist/otel/claude-hooks.d.ts.map +0 -1
- package/dist/otel/claude-hooks.js +0 -647
- package/dist/otel/claude-hooks.js.map +0 -1
- package/dist/otel/claude-wrapper.d.ts +0 -93
- package/dist/otel/claude-wrapper.d.ts.map +0 -1
- package/dist/otel/claude-wrapper.js +0 -155
- package/dist/otel/claude-wrapper.js.map +0 -1
- package/dist/otel/gemini.d.ts +0 -56
- package/dist/otel/gemini.d.ts.map +0 -1
- package/dist/otel/gemini.js +0 -350
- package/dist/otel/gemini.js.map +0 -1
- package/dist/otel/integrations/anthropic.d.ts +0 -10
- package/dist/otel/integrations/anthropic.d.ts.map +0 -1
- package/dist/otel/integrations/anthropic.js +0 -26
- package/dist/otel/integrations/anthropic.js.map +0 -1
- package/dist/otel/integrations/claude-agent.d.ts +0 -12
- package/dist/otel/integrations/claude-agent.d.ts.map +0 -1
- package/dist/otel/integrations/claude-agent.js +0 -28
- package/dist/otel/integrations/claude-agent.js.map +0 -1
- package/dist/otel/integrations/gemini.d.ts +0 -11
- package/dist/otel/integrations/gemini.d.ts.map +0 -1
- package/dist/otel/integrations/gemini.js +0 -23
- package/dist/otel/integrations/gemini.js.map +0 -1
- package/dist/otel/integrations/langchain.d.ts +0 -15
- package/dist/otel/integrations/langchain.d.ts.map +0 -1
- package/dist/otel/integrations/langchain.js +0 -43
- package/dist/otel/integrations/langchain.js.map +0 -1
- package/dist/otel/integrations/mastra.d.ts +0 -14
- package/dist/otel/integrations/mastra.d.ts.map +0 -1
- package/dist/otel/integrations/mastra.js +0 -31
- package/dist/otel/integrations/mastra.js.map +0 -1
- package/dist/otel/integrations/openai-agents.d.ts +0 -11
- package/dist/otel/integrations/openai-agents.d.ts.map +0 -1
- package/dist/otel/integrations/openai-agents.js +0 -30
- package/dist/otel/integrations/openai-agents.js.map +0 -1
- package/dist/otel/integrations/vercel.d.ts +0 -14
- package/dist/otel/integrations/vercel.d.ts.map +0 -1
- package/dist/otel/integrations/vercel.js +0 -20
- package/dist/otel/integrations/vercel.js.map +0 -1
- package/dist/otel/langchain-handler.d.ts +0 -112
- package/dist/otel/langchain-handler.d.ts.map +0 -1
- package/dist/otel/langchain-handler.js +0 -561
- package/dist/otel/langchain-handler.js.map +0 -1
- package/dist/otel/mastra-exporter.d.ts +0 -87
- package/dist/otel/mastra-exporter.d.ts.map +0 -1
- package/dist/otel/mastra-exporter.js +0 -530
- package/dist/otel/mastra-exporter.js.map +0 -1
- package/dist/otel/openai.d.ts +0 -20
- package/dist/otel/openai.d.ts.map +0 -1
- package/dist/otel/openai.js +0 -55
- package/dist/otel/openai.js.map +0 -1
- package/dist/otel/tracing-processor.d.ts +0 -139
- package/dist/otel/tracing-processor.d.ts.map +0 -1
- package/dist/otel/tracing-processor.js +0 -434
- package/dist/otel/tracing-processor.js.map +0 -1
- package/eslint.config.mjs +0 -4
- package/src/auth.ts +0 -236
- package/src/client.ts +0 -163
- package/src/converters/claude.ts +0 -343
- package/src/converters/gemini.ts +0 -243
- package/src/converters/index.ts +0 -50
- package/src/converters/openai.ts +0 -300
- package/src/converters/openinference.ts +0 -665
- package/src/converters/vercel.ts +0 -302
- package/src/dev-target.ts +0 -79
- package/src/http.ts +0 -43
- package/src/index.ts +0 -277
- package/src/otel/anthropic.ts +0 -619
- package/src/otel/claude-hooks.ts +0 -1116
- package/src/otel/claude-wrapper.ts +0 -239
- package/src/otel/gemini.ts +0 -483
- package/src/otel/index.ts +0 -128
- package/src/otel/init.ts +0 -411
- package/src/otel/integrations/anthropic.ts +0 -36
- package/src/otel/integrations/base.ts +0 -158
- package/src/otel/integrations/claude-agent.ts +0 -36
- package/src/otel/integrations/gemini.ts +0 -30
- package/src/otel/integrations/index.ts +0 -152
- package/src/otel/integrations/langchain.ts +0 -60
- package/src/otel/integrations/mastra.ts +0 -48
- package/src/otel/integrations/openai-agents.ts +0 -47
- package/src/otel/integrations/pi.ts +0 -28
- package/src/otel/integrations/vercel.ts +0 -26
- package/src/otel/langchain-handler.ts +0 -804
- package/src/otel/logs.ts +0 -395
- package/src/otel/mastra-exporter.ts +0 -714
- package/src/otel/openai.ts +0 -93
- package/src/otel/pi.ts +0 -94
- package/src/otel/register.ts +0 -50
- package/src/otel/setup.ts +0 -215
- package/src/otel/span-processor.ts +0 -512
- package/src/otel/tracing-processor.ts +0 -637
- package/src/pagination.ts +0 -10
- package/src/proxy-from-env.d.ts +0 -7
- package/src/resources/experiments.ts +0 -176
- package/src/resources/recipes.ts +0 -74
- package/src/resources/runtimes.ts +0 -31
- package/src/runner.ts +0 -213
- package/src/types.ts +0 -13
- package/src/utils.ts +0 -95
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -8
package/dist/otel/logs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/otel/logs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/otel/logs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AAiBjC,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,UAAU,EAGhB,MAAM,a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,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAS7C,WAAW,CAAC,CAAC,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC;IAKP,SAAS,CAAC,CAAC,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC;IAMP,gBAAgB,CAAC,CAAC,EACtB,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,kBAAkB,EAAE,MAAM,GAAG,SAAS,EACtC,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC;IAQP,UAAU,CAAC,CAAC,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC;IAOP,eAAe,CAAC,CAAC,EACrB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC;IAOb,kEAAkE;IAClE,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B,uEAAuE;IACvE,cAAc,IAAI,MAAM,GAAG,SAAS;IAI9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAIhC"}
|
package/dist/otel/logs.js
CHANGED
|
@@ -33,20 +33,17 @@ import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
|
|
|
33
33
|
import { resourceFromAttributes, defaultResource, } from "@opentelemetry/resources";
|
|
34
34
|
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
35
35
|
import { propagation, context } from "@opentelemetry/api";
|
|
36
|
-
import { logger as sdkLogger, withOtlpHttpsProxy } from "../utils.js";
|
|
36
|
+
import { DEFAULT_SERVICE_NAME, exporterHeaders, logger as sdkLogger, otlpUserAgent, withOtlpHttpsProxy, } from "../utils.js";
|
|
37
37
|
import { VERSION } from "../version.js";
|
|
38
|
-
import { generateEventId, } from "../types.js";
|
|
38
|
+
import { generateEventId, toAttributeValue, } from "../types.js";
|
|
39
39
|
export class IntrospectionLogs {
|
|
40
40
|
loggerProvider;
|
|
41
41
|
otelLogger;
|
|
42
|
-
userId;
|
|
43
|
-
anonymousId;
|
|
44
|
-
traits = {};
|
|
45
42
|
constructor(options = {}) {
|
|
46
43
|
const token = options.token || process.env.INTROSPECTION_TOKEN || "";
|
|
47
44
|
const serviceName = options.serviceName ||
|
|
48
45
|
process.env.INTROSPECTION_SERVICE_NAME ||
|
|
49
|
-
|
|
46
|
+
DEFAULT_SERVICE_NAME;
|
|
50
47
|
const baseOtelUrl = options.baseOtelUrl ||
|
|
51
48
|
process.env.INTROSPECTION_BASE_OTEL_URL ||
|
|
52
49
|
"https://otel.introspection.dev";
|
|
@@ -57,18 +54,29 @@ export class IntrospectionLogs {
|
|
|
57
54
|
const endpoint = baseOtelUrl.endsWith("/v1/logs")
|
|
58
55
|
? baseOtelUrl
|
|
59
56
|
: `${baseOtelUrl.replace(/\/$/, "")}/v1/logs`;
|
|
60
|
-
const headers =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}));
|
|
57
|
+
const headers = exporterHeaders(token, options.additionalHeaders);
|
|
58
|
+
const exporter = options.logExporter ??
|
|
59
|
+
new OTLPLogExporter(withOtlpHttpsProxy({
|
|
60
|
+
url: endpoint,
|
|
61
|
+
headers,
|
|
62
|
+
...otlpUserAgent,
|
|
63
|
+
}));
|
|
68
64
|
const processor = new BatchLogRecordProcessor({
|
|
69
65
|
exporter,
|
|
70
|
-
|
|
66
|
+
// maxBatchSize is the export batch size, not the queue bound. Wiring it
|
|
67
|
+
// to maxQueueSize left the queue at 100 while the batch size kept its
|
|
68
|
+
// default of 512, which the OTel processor warns about and clamps on
|
|
69
|
+
// every construction.
|
|
70
|
+
maxExportBatchSize: options.maxBatchSize ?? 100,
|
|
71
71
|
scheduledDelayMillis: options.flushInterval ?? 5000,
|
|
72
|
+
// Passed only when set, so an unset option leaves the OTel SDK's own
|
|
73
|
+
// default (and its env-var override) in charge.
|
|
74
|
+
...(options.maxQueueSize != null
|
|
75
|
+
? { maxQueueSize: options.maxQueueSize }
|
|
76
|
+
: {}),
|
|
77
|
+
...(options.exportTimeoutMillis != null
|
|
78
|
+
? { exportTimeoutMillis: options.exportTimeoutMillis }
|
|
79
|
+
: {}),
|
|
72
80
|
});
|
|
73
81
|
const baseResource = defaultResource();
|
|
74
82
|
const introspectionResource = resourceFromAttributes({
|
|
@@ -79,7 +87,11 @@ export class IntrospectionLogs {
|
|
|
79
87
|
resource,
|
|
80
88
|
processors: [processor],
|
|
81
89
|
});
|
|
82
|
-
|
|
90
|
+
// The dist name, per the OTel convention that the scope names the
|
|
91
|
+
// instrumentation library. Deliberately not platform-tagged: the SDK
|
|
92
|
+
// language already rides the resource as `telemetry.sdk.language`, which
|
|
93
|
+
// is the semconv-designated place for it.
|
|
94
|
+
this.otelLogger = this.loggerProvider.getLogger("introspection-sdk", VERSION);
|
|
83
95
|
sdkLogger.info(`IntrospectionLogs initialized: service=${serviceName}, otlp=${endpoint}`);
|
|
84
96
|
}
|
|
85
97
|
/** Get gen_ai context from baggage */
|
|
@@ -92,20 +104,30 @@ export class IntrospectionLogs {
|
|
|
92
104
|
agentId: baggage?.getEntry("gen_ai.agent.id")?.value,
|
|
93
105
|
};
|
|
94
106
|
}
|
|
95
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Get identity from baggage.
|
|
109
|
+
*
|
|
110
|
+
* Baggage only, deliberately. This used to fall back to `userId` /
|
|
111
|
+
* `anonymousId` held on the instance, but `init()` builds one instance per
|
|
112
|
+
* process: under any concurrency, the identity of whichever request called
|
|
113
|
+
* `identify()` last attached itself to every other request's events. Scope
|
|
114
|
+
* identity with {@link withUserId} / {@link withAnonymousId} instead, which
|
|
115
|
+
* carry it on the async context where it belongs.
|
|
116
|
+
*/
|
|
96
117
|
getIdentityFromContext() {
|
|
97
118
|
const baggage = propagation.getBaggage(context.active());
|
|
98
119
|
return {
|
|
99
|
-
userId: baggage?.getEntry("identity.user_id")?.value
|
|
100
|
-
anonymousId: baggage?.getEntry("identity.anonymous_id")?.value
|
|
120
|
+
userId: baggage?.getEntry("identity.user_id")?.value,
|
|
121
|
+
anonymousId: baggage?.getEntry("identity.anonymous_id")?.value,
|
|
101
122
|
};
|
|
102
123
|
}
|
|
103
124
|
getTimestamp() {
|
|
104
|
-
|
|
125
|
+
// Wall-clock only. An earlier version subtracted one `process.hrtime`
|
|
126
|
+
// reading from another taken microseconds later, which looked like an
|
|
127
|
+
// hrtime/epoch correlation but only ever removed the elapsed call time.
|
|
105
128
|
const epochNs = BigInt(Date.now()) * BigInt(1_000_000);
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
const nanos = Number(offsetNs % BigInt(1_000_000_000));
|
|
129
|
+
const seconds = Number(epochNs / BigInt(1_000_000_000));
|
|
130
|
+
const nanos = Number(epochNs % BigInt(1_000_000_000));
|
|
109
131
|
return [seconds, nanos];
|
|
110
132
|
}
|
|
111
133
|
buildAttributes(eventName, options = {}) {
|
|
@@ -114,7 +136,7 @@ export class IntrospectionLogs {
|
|
|
114
136
|
"event.name": eventName,
|
|
115
137
|
"event.id": eventId || generateEventId(),
|
|
116
138
|
};
|
|
117
|
-
const identity = this.getIdentityFromContext();
|
|
139
|
+
const identity = options.identity ?? this.getIdentityFromContext();
|
|
118
140
|
if (identity.userId)
|
|
119
141
|
attributes["identity.user.id"] = identity.userId;
|
|
120
142
|
if (identity.anonymousId)
|
|
@@ -135,14 +157,7 @@ export class IntrospectionLogs {
|
|
|
135
157
|
for (const [key, value] of Object.entries(properties)) {
|
|
136
158
|
if (value != null) {
|
|
137
159
|
const attrKey = `properties.${key}`;
|
|
138
|
-
|
|
139
|
-
attributes[attrKey] = JSON.stringify(value);
|
|
140
|
-
}
|
|
141
|
-
else if (typeof value === "string" ||
|
|
142
|
-
typeof value === "number" ||
|
|
143
|
-
typeof value === "boolean") {
|
|
144
|
-
attributes[attrKey] = value;
|
|
145
|
-
}
|
|
160
|
+
attributes[attrKey] = toAttributeValue(value);
|
|
146
161
|
}
|
|
147
162
|
}
|
|
148
163
|
}
|
|
@@ -150,14 +165,7 @@ export class IntrospectionLogs {
|
|
|
150
165
|
for (const [key, value] of Object.entries(traits)) {
|
|
151
166
|
if (value != null) {
|
|
152
167
|
const attrKey = `context.traits.${key}`;
|
|
153
|
-
|
|
154
|
-
attributes[attrKey] = JSON.stringify(value);
|
|
155
|
-
}
|
|
156
|
-
else if (typeof value === "string" ||
|
|
157
|
-
typeof value === "number" ||
|
|
158
|
-
typeof value === "boolean") {
|
|
159
|
-
attributes[attrKey] = value;
|
|
160
|
-
}
|
|
168
|
+
attributes[attrKey] = toAttributeValue(value);
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
}
|
|
@@ -179,8 +187,14 @@ export class IntrospectionLogs {
|
|
|
179
187
|
}
|
|
180
188
|
feedback(name, options = {}) {
|
|
181
189
|
const { comments, conversationId, previousResponseId, eventId, ...extra } = options;
|
|
182
|
-
|
|
183
|
-
|
|
190
|
+
// `name` last: it is the positional argument, so an `extra` key that
|
|
191
|
+
// happens to be called `name` must not silently replace the feedback
|
|
192
|
+
// name the caller passed.
|
|
193
|
+
const properties = { ...extra, name };
|
|
194
|
+
// `!= null`, not truthiness: `comments: ""` is a comment the caller
|
|
195
|
+
// supplied. Dropping it here
|
|
196
|
+
// made the same call produce a different event shape per SDK.
|
|
197
|
+
if (comments != null)
|
|
184
198
|
properties.comments = comments;
|
|
185
199
|
const attributes = this.buildAttributes("introspection.feedback", {
|
|
186
200
|
properties,
|
|
@@ -197,19 +211,41 @@ export class IntrospectionLogs {
|
|
|
197
211
|
});
|
|
198
212
|
sdkLogger.debug(`Feedback: ${name}`);
|
|
199
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Emit an `identify` event associating `userId` with `traits`.
|
|
216
|
+
*
|
|
217
|
+
* The identity lands on this event only. It does not persist onto later
|
|
218
|
+
* `track` / `feedback` calls — wrap those in {@link withUserId} (or set the
|
|
219
|
+
* baggage yourself) to scope identity across several events.
|
|
220
|
+
*/
|
|
200
221
|
identify(userId, traits, anonymousId, eventId) {
|
|
201
|
-
|
|
222
|
+
const identity = { "identity.user_id": userId };
|
|
202
223
|
if (anonymousId)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
224
|
+
identity["identity.anonymous_id"] = anonymousId;
|
|
225
|
+
// The ids are passed straight through rather than round-tripped via
|
|
226
|
+
// baggage. Reading them back off the context made the identify event
|
|
227
|
+
// depend on a globally registered context manager: `init()` registers
|
|
228
|
+
// one, but a standalone `new IntrospectionLogs()` -- the form the README
|
|
229
|
+
// shows -- gets the API's no-op manager, where `context.with()` runs the
|
|
230
|
+
// callback and `context.active()` still returns ROOT. The event then went
|
|
231
|
+
// out with no identity on it at all, silently.
|
|
232
|
+
//
|
|
233
|
+
// The scope is still entered, so anything the emit touches (a span, a
|
|
234
|
+
// downstream propagator) sees the same identity when a real manager is
|
|
235
|
+
// installed.
|
|
236
|
+
context.with(this.createBaggageContext(identity), () => {
|
|
237
|
+
const attributes = this.buildAttributes("identify", {
|
|
238
|
+
traits,
|
|
239
|
+
eventId,
|
|
240
|
+
identity: { userId, anonymousId },
|
|
241
|
+
});
|
|
242
|
+
this.otelLogger.emit({
|
|
243
|
+
timestamp: this.getTimestamp(),
|
|
244
|
+
context: context.active(),
|
|
245
|
+
severityNumber: SeverityNumber.INFO,
|
|
246
|
+
severityText: "INFO",
|
|
247
|
+
attributes,
|
|
248
|
+
});
|
|
213
249
|
});
|
|
214
250
|
sdkLogger.debug(`Identified: ${userId}`);
|
|
215
251
|
}
|
|
@@ -239,26 +275,19 @@ export class IntrospectionLogs {
|
|
|
239
275
|
values["gen_ai.request.previous_response_id"] = previousResponseId;
|
|
240
276
|
return await context.with(this.createBaggageContext(values), callback);
|
|
241
277
|
}
|
|
242
|
-
setUserId(userId) {
|
|
243
|
-
this.userId = userId;
|
|
244
|
-
}
|
|
245
|
-
setAnonymousId(anonymousId) {
|
|
246
|
-
this.anonymousId = anonymousId;
|
|
247
|
-
}
|
|
248
278
|
async withUserId(userId, callback) {
|
|
249
279
|
return await context.with(this.createBaggageContext({ "identity.user_id": userId }), callback);
|
|
250
280
|
}
|
|
251
281
|
async withAnonymousId(anonymousId, callback) {
|
|
252
282
|
return await context.with(this.createBaggageContext({ "identity.anonymous_id": anonymousId }), callback);
|
|
253
283
|
}
|
|
254
|
-
|
|
255
|
-
|
|
284
|
+
/** The user id on the current async context, if one is scoped. */
|
|
285
|
+
getUserId() {
|
|
286
|
+
return this.getIdentityFromContext().userId;
|
|
256
287
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
this.anonymousId
|
|
260
|
-
this.traits = {};
|
|
261
|
-
sdkLogger.debug("IntrospectionLogs state reset");
|
|
288
|
+
/** The anonymous id on the current async context, if one is scoped. */
|
|
289
|
+
getAnonymousId() {
|
|
290
|
+
return this.getIdentityFromContext().anonymousId;
|
|
262
291
|
}
|
|
263
292
|
async flush() {
|
|
264
293
|
await this.loggerProvider.forceFlush();
|
package/dist/otel/logs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.js","sourceRoot":"","sources":["../../src/otel/logs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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AAK;QACT,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;QACvC,SAAS,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QACrC,SAAS,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;CACF"}
|
package/dist/otel/pi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
-
* import { IntrospectionPiInstrumentor, setupTracing } from "@introspection-sdk/introspection-node";
|
|
9
|
+
* import { IntrospectionPiInstrumentor, setupTracing } from "@introspection-sdk/introspection-node/otel";
|
|
10
10
|
* import { Agent } from "@earendil-works/pi-agent-core";
|
|
11
11
|
*
|
|
12
12
|
* setupTracing({ serviceName: "my-app" });
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import type { Agent } from "@earendil-works/pi-agent-core";
|
|
27
27
|
import { type AgentMeta } from "@introspection-sdk/introspection-pi";
|
|
28
|
-
export type { AgentMeta } from "@introspection-sdk/introspection-pi";
|
|
28
|
+
export type { AgentMeta, AgentMeta as PiAgentMeta, } from "@introspection-sdk/introspection-pi";
|
|
29
29
|
export interface IntrospectionPiInstrumentorOptions {
|
|
30
30
|
/** Tracer name used for all spans produced by this instrumentor. */
|
|
31
31
|
tracerName?: string;
|
|
@@ -39,22 +39,35 @@ export interface IntrospectionPiInstrumentorOptions {
|
|
|
39
39
|
*/
|
|
40
40
|
export declare class IntrospectionPiInstrumentor {
|
|
41
41
|
private _tracer;
|
|
42
|
-
|
|
42
|
+
/** Per instrumented agent: its loop subscription and how to unwrap it. */
|
|
43
|
+
private _active;
|
|
43
44
|
constructor(opts?: IntrospectionPiInstrumentorOptions);
|
|
44
45
|
/**
|
|
45
46
|
* Instrument a pi {@link Agent}:
|
|
46
|
-
* - Wraps the agent stream function to emit a `chat ${
|
|
47
|
+
* - Wraps the agent stream function to emit a `chat ${model}` span per
|
|
47
48
|
* LLM call.
|
|
48
49
|
* - Subscribes to the agent loop to emit an `execute_tool ${name}` span per
|
|
49
50
|
* tool execution.
|
|
50
51
|
*
|
|
52
|
+
* Re-instrumenting an agent replaces its previous instrumentation rather
|
|
53
|
+
* than stacking on top. `AgentMeta` carries the conversation id, so a host
|
|
54
|
+
* reusing one `Agent` across conversations calls this again by design;
|
|
55
|
+
* without the replace, the stream was wrapped twice and `subscribe` fired
|
|
56
|
+
* twice, so every call produced two `chat` spans and two `execute_tool`
|
|
57
|
+
* spans, the inner pair stamped with the previous conversation.
|
|
58
|
+
*
|
|
51
59
|
* @param agent - The pi Agent instance to instrument.
|
|
52
60
|
* @param meta - Identity metadata stamped on every span produced by this agent.
|
|
53
61
|
*/
|
|
54
62
|
instrument(agent: Agent, meta: AgentMeta): void;
|
|
55
63
|
/**
|
|
56
|
-
* Unsubscribe all active tool instrumentations
|
|
64
|
+
* Unsubscribe all active tool instrumentations, finalize any open spans, and
|
|
65
|
+
* put each agent's original stream function back.
|
|
66
|
+
*
|
|
67
|
+
* Restoring matters: without it a stopped instrumentor's agents kept
|
|
68
|
+
* emitting `chat` spans onto a provider that had already been shut down.
|
|
57
69
|
*/
|
|
58
70
|
stop(): void;
|
|
71
|
+
private _detach;
|
|
59
72
|
}
|
|
60
73
|
//# sourceMappingURL=pi.d.ts.map
|
package/dist/otel/pi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi.d.ts","sourceRoot":"","sources":["../../src/otel/pi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAY,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,qCAAqC,CAAC;AAG7C,YAAY,
|
|
1
|
+
{"version":3,"file":"pi.d.ts","sourceRoot":"","sources":["../../src/otel/pi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAY,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,qCAAqC,CAAC;AAG7C,YAAY,EACV,SAAS,EAET,SAAS,IAAI,WAAW,GACzB,MAAM,qCAAqC,CAAC;AAE7C,MAAM,WAAW,kCAAkC;IACjD,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,qBAAa,2BAA2B;IACtC,OAAO,CAAC,OAAO,CAAqC;IACpD,0EAA0E;IAC1E,OAAO,CAAC,OAAO,CAGX;gBAEQ,IAAI,GAAE,kCAAuC;IAOzD;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAwB/C;;;;;;OAMG;IACH,IAAI,IAAI,IAAI;IAIZ,OAAO,CAAC,OAAO;CAOhB"}
|
package/dist/otel/pi.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
-
* import { IntrospectionPiInstrumentor, setupTracing } from "@introspection-sdk/introspection-node";
|
|
9
|
+
* import { IntrospectionPiInstrumentor, setupTracing } from "@introspection-sdk/introspection-node/otel";
|
|
10
10
|
* import { Agent } from "@earendil-works/pi-agent-core";
|
|
11
11
|
*
|
|
12
12
|
* setupTracing({ serviceName: "my-app" });
|
|
@@ -35,36 +35,65 @@ import { VERSION } from "../version.js";
|
|
|
35
35
|
*/
|
|
36
36
|
export class IntrospectionPiInstrumentor {
|
|
37
37
|
_tracer;
|
|
38
|
-
|
|
38
|
+
/** Per instrumented agent: its loop subscription and how to unwrap it. */
|
|
39
|
+
_active = new Map();
|
|
39
40
|
constructor(opts = {}) {
|
|
40
41
|
this._tracer = trace.getTracer(opts.tracerName ?? "introspection-pi", VERSION);
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* Instrument a pi {@link Agent}:
|
|
44
|
-
* - Wraps the agent stream function to emit a `chat ${
|
|
45
|
+
* - Wraps the agent stream function to emit a `chat ${model}` span per
|
|
45
46
|
* LLM call.
|
|
46
47
|
* - Subscribes to the agent loop to emit an `execute_tool ${name}` span per
|
|
47
48
|
* tool execution.
|
|
48
49
|
*
|
|
50
|
+
* Re-instrumenting an agent replaces its previous instrumentation rather
|
|
51
|
+
* than stacking on top. `AgentMeta` carries the conversation id, so a host
|
|
52
|
+
* reusing one `Agent` across conversations calls this again by design;
|
|
53
|
+
* without the replace, the stream was wrapped twice and `subscribe` fired
|
|
54
|
+
* twice, so every call produced two `chat` spans and two `execute_tool`
|
|
55
|
+
* spans, the inner pair stamped with the previous conversation.
|
|
56
|
+
*
|
|
49
57
|
* @param agent - The pi Agent instance to instrument.
|
|
50
58
|
* @param meta - Identity metadata stamped on every span produced by this agent.
|
|
51
59
|
*/
|
|
52
60
|
instrument(agent, meta) {
|
|
61
|
+
this._detach(agent);
|
|
53
62
|
const key = "streamFunction" in agent ? "streamFunction" : "streamFn";
|
|
54
63
|
const instrumentable = agent;
|
|
55
|
-
|
|
64
|
+
const original = instrumentable[key];
|
|
65
|
+
instrumentable[key] = instrumentStream(original, {
|
|
56
66
|
tracer: this._tracer,
|
|
57
67
|
meta,
|
|
58
68
|
});
|
|
59
|
-
this.
|
|
69
|
+
this._active.set(agent, {
|
|
70
|
+
instrumentation: instrumentAgent(agent, {
|
|
71
|
+
tracer: this._tracer,
|
|
72
|
+
meta,
|
|
73
|
+
}),
|
|
74
|
+
restore: () => {
|
|
75
|
+
instrumentable[key] = original;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
60
78
|
}
|
|
61
79
|
/**
|
|
62
|
-
* Unsubscribe all active tool instrumentations
|
|
80
|
+
* Unsubscribe all active tool instrumentations, finalize any open spans, and
|
|
81
|
+
* put each agent's original stream function back.
|
|
82
|
+
*
|
|
83
|
+
* Restoring matters: without it a stopped instrumentor's agents kept
|
|
84
|
+
* emitting `chat` spans onto a provider that had already been shut down.
|
|
63
85
|
*/
|
|
64
86
|
stop() {
|
|
65
|
-
for (const
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
for (const agent of [...this._active.keys()])
|
|
88
|
+
this._detach(agent);
|
|
89
|
+
}
|
|
90
|
+
_detach(agent) {
|
|
91
|
+
const active = this._active.get(agent);
|
|
92
|
+
if (!active)
|
|
93
|
+
return;
|
|
94
|
+
active.instrumentation.stop();
|
|
95
|
+
active.restore();
|
|
96
|
+
this._active.delete(agent);
|
|
68
97
|
}
|
|
69
98
|
}
|
|
70
99
|
//# sourceMappingURL=pi.js.map
|
package/dist/otel/pi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi.js","sourceRoot":"","sources":["../../src/otel/pi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EACL,gBAAgB,EAChB,eAAe,GAGhB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"pi.js","sourceRoot":"","sources":["../../src/otel/pi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EACL,gBAAgB,EAChB,eAAe,GAGhB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAaxC;;;;;;GAMG;AACH,MAAM,OAAO,2BAA2B;IAC9B,OAAO,CAAqC;IACpD,0EAA0E;IAClE,OAAO,GAAG,IAAI,GAAG,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;QAC9B,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF"}
|
package/dist/otel/register.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Run `init()` if a token is configured. Exported (and awaited at module load)
|
|
3
3
|
* so tests can invoke it deterministically; the module-level `await` below
|
|
4
|
-
* guarantees the preload finishes — including framework auto-discovery
|
|
5
|
-
*
|
|
4
|
+
* guarantees the preload finishes — including framework auto-discovery —
|
|
5
|
+
* before Node evaluates the application entry point.
|
|
6
6
|
*/
|
|
7
7
|
export declare function registerFromEnv(): Promise<void>;
|
|
8
8
|
//# sourceMappingURL=register.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/otel/register.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/otel/register.ts"],"names":[],"mappings":"AAyBA;;;;;GAKG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAcrD"}
|
package/dist/otel/register.js
CHANGED
|
@@ -8,27 +8,25 @@
|
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
10
10
|
* Runs `introspection.init()` from the environment **before** the app's module
|
|
11
|
-
* graph executes, so no `init()` call is needed in application source
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* this preload is traced with zero code changes.
|
|
11
|
+
* graph executes, so no `init()` call is needed in application source —
|
|
12
|
+
* framework auto-discovery (Pi) runs before
|
|
13
|
+
* the application entry point evaluates.
|
|
15
14
|
*
|
|
16
15
|
* Configuration is read from the usual environment variables
|
|
17
16
|
* (`INTROSPECTION_TOKEN`, `INTROSPECTION_SERVICE_NAME`,
|
|
18
17
|
* `INTROSPECTION_BASE_OTEL_URL`). If no token is configured the preload logs a
|
|
19
18
|
* warning and does nothing, so it never crashes the host application.
|
|
20
19
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* import-in-the-middle loader hook (the prototype-patch path does not need one).
|
|
20
|
+
* It drives the existing `init()` rather than registering an
|
|
21
|
+
* import-in-the-middle loader hook.
|
|
24
22
|
*/
|
|
25
23
|
import { logger } from "../utils.js";
|
|
26
24
|
import { init } from "./init.js";
|
|
27
25
|
/**
|
|
28
26
|
* Run `init()` if a token is configured. Exported (and awaited at module load)
|
|
29
27
|
* so tests can invoke it deterministically; the module-level `await` below
|
|
30
|
-
* guarantees the preload finishes — including framework auto-discovery
|
|
31
|
-
*
|
|
28
|
+
* guarantees the preload finishes — including framework auto-discovery —
|
|
29
|
+
* before Node evaluates the application entry point.
|
|
32
30
|
*/
|
|
33
31
|
export async function registerFromEnv() {
|
|
34
32
|
if (!process.env.INTROSPECTION_TOKEN) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/otel/register.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/otel/register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,CACT,iFAAiF,CAClF,CAAC;QACF,OAAO;IACT,CAAC;IACD,IAAI,CAAC;QACH,MAAM,IAAI,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAC9E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,8DAA8D;QAC9D,MAAM,CAAC,IAAI,CAAC,0CAA0C,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC;AAED,MAAM,eAAe,EAAE,CAAC"}
|
package/dist/otel/setup.d.ts
CHANGED
|
@@ -18,13 +18,13 @@ export interface SetupTracingOptions extends IntrospectionSpanProcessorOptions {
|
|
|
18
18
|
onConflict?: ConflictBehavior;
|
|
19
19
|
/**
|
|
20
20
|
* Extra span processors attached to the same `NodeTracerProvider`, so a
|
|
21
|
-
* single set of spans fans out to other
|
|
21
|
+
* single set of spans fans out to any other OTLP-compatible backend.
|
|
22
22
|
* This is the low-level dual-export hook:
|
|
23
23
|
*
|
|
24
24
|
* ```ts
|
|
25
25
|
* setupTracing({
|
|
26
26
|
* serviceName: "my-app",
|
|
27
|
-
* additionalSpanProcessors: [new BatchSpanProcessor(
|
|
27
|
+
* additionalSpanProcessors: [new BatchSpanProcessor(otherBackendExporter)],
|
|
28
28
|
* });
|
|
29
29
|
* ```
|
|
30
30
|
*
|
package/dist/otel/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/otel/setup.ts"],"names":[],"mappings":"AA8DA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAEL,KAAK,iCAAiC,EACvC,MAAM,qBAAqB,CAAC;AAI7B,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAE5D,MAAM,WAAW,mBAAoB,SAAQ,iCAAiC;IAC5E;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAE9B;;;;;;;;;;;;;;;;;OAiBG;IACH,wBAAwB,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5C;AA8DD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAIrE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/otel/setup.ts"],"names":[],"mappings":"AA8DA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAEL,KAAK,iCAAiC,EACvC,MAAM,qBAAqB,CAAC;AAI7B,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAE5D,MAAM,WAAW,mBAAoB,SAAQ,iCAAiC;IAC5E;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAE9B;;;;;;;;;;;;;;;;;OAiBG;IACH,wBAAwB,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5C;AA8DD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAIrE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,kBAAkB,CAmCpB"}
|
package/dist/otel/setup.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* 1. `AsyncLocalStorageContextManager` — without this, `context.with()` is a
|
|
8
8
|
* no-op (the default `NOOP_CONTEXT_MANAGER` silently drops the context),
|
|
9
|
-
* which makes `
|
|
9
|
+
* which makes `IntrospectionLogs.withAgent()`, `.withConversation()`,
|
|
10
10
|
* etc. dead code.
|
|
11
11
|
* 2. `W3CBaggagePropagator` — so baggage is carried across HTTP boundaries
|
|
12
12
|
* via the `baggage` header (alongside W3C trace-context).
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
42
|
* ```ts
|
|
43
|
-
* import { setupTracing,
|
|
43
|
+
* import { setupTracing, IntrospectionLogs } from "@introspection-sdk/introspection-node/otel";
|
|
44
44
|
*
|
|
45
45
|
* setupTracing();
|
|
46
46
|
*
|
|
47
|
-
* const
|
|
47
|
+
* const logs = new IntrospectionLogs();
|
|
48
48
|
*
|
|
49
|
-
* await
|
|
50
|
-
*
|
|
51
|
-
*
|
|
49
|
+
* await logs.withAgent("researcher", "researcher-1", () =>
|
|
50
|
+
* logs.withConversation(conversationId, undefined, () =>
|
|
51
|
+
* runTheAgentTurn(),
|
|
52
52
|
* ),
|
|
53
53
|
* );
|
|
54
54
|
* ```
|
|
@@ -140,6 +140,16 @@ export function setupTracing(options) {
|
|
|
140
140
|
],
|
|
141
141
|
});
|
|
142
142
|
provider.register();
|
|
143
|
+
// Release the cache when the caller tears the provider down. Without this,
|
|
144
|
+
// `setupTracing()` after a `provider.shutdown()` returns the dead provider
|
|
145
|
+
// and every subsequent span is silently dropped.
|
|
146
|
+
const shutdown = provider.shutdown.bind(provider);
|
|
147
|
+
provider.shutdown = async () => {
|
|
148
|
+
if (registeredProvider === provider) {
|
|
149
|
+
registeredProvider = undefined;
|
|
150
|
+
}
|
|
151
|
+
return shutdown();
|
|
152
|
+
};
|
|
143
153
|
registeredProvider = provider;
|
|
144
154
|
return provider;
|
|
145
155
|
}
|
package/dist/otel/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/otel/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,+BAA+B,EAAE,MAAM,oCAAoC,CAAC;AACrF,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,qBAAqB,CAA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