@introspection-sdk/introspection-node 0.4.0 → 0.4.2
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/LICENSE +191 -0
- package/dist/ai-sdk-integration.d.ts.map +1 -1
- package/dist/ai-sdk-integration.js +2 -2
- package/dist/claude-hooks.d.ts.map +1 -1
- package/dist/claude-hooks.js +3 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -3
- package/dist/converters/ai-sdk.d.ts +1 -1
- package/dist/converters/ai-sdk.d.ts.map +1 -1
- package/dist/converters/ai-sdk.js +24 -1
- package/dist/converters/claude.d.ts +2 -2
- package/dist/converters/claude.d.ts.map +1 -1
- package/dist/converters/claude.js +1 -1
- package/dist/converters/openai.d.ts +1 -1
- package/dist/converters/openai.d.ts.map +1 -1
- package/dist/converters/openinference.d.ts +1 -1
- package/dist/converters/openinference.d.ts.map +1 -1
- package/dist/converters/openinference.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/langchain-handler.d.ts +7 -5
- package/dist/langchain-handler.d.ts.map +1 -1
- package/dist/langchain-handler.js +57 -28
- package/dist/mastra-exporter.d.ts.map +1 -1
- package/dist/mastra-exporter.js +2 -2
- package/dist/span-processor.d.ts.map +1 -1
- package/dist/span-processor.js +6 -3
- package/dist/tracing-processor.d.ts.map +1 -1
- package/dist/tracing-processor.js +3 -3
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -0
- package/package.json +19 -16
- package/src/ai-sdk-integration.ts +5 -3
- package/src/anthropic.ts +1 -1
- package/src/claude-hooks.ts +7 -5
- package/src/client.ts +7 -5
- package/src/converters/ai-sdk.ts +27 -2
- package/src/converters/claude.ts +3 -3
- package/src/converters/openai.ts +1 -1
- package/src/converters/openinference.ts +2 -2
- package/src/index.ts +2 -2
- package/src/langchain-handler.ts +68 -35
- package/src/mastra-exporter.ts +5 -3
- package/src/span-processor.ts +10 -5
- package/src/tracing-processor.ts +7 -5
- package/src/utils.ts +15 -0
- package/.turbo/turbo-check-types.log +0 -5
- package/.turbo/turbo-lint.log +0 -5
- 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/types/genai.d.ts +0 -165
- package/dist/types/genai.d.ts.map +0 -1
- package/dist/types/genai.js +0 -82
- package/src/types/genai.ts +0 -264
package/src/langchain-handler.ts
CHANGED
|
@@ -34,6 +34,8 @@ import type { ChainValues } from "@langchain/core/utils/types";
|
|
|
34
34
|
|
|
35
35
|
import {
|
|
36
36
|
context as otelContext,
|
|
37
|
+
ROOT_CONTEXT,
|
|
38
|
+
SpanStatusCode,
|
|
37
39
|
trace as otelTrace,
|
|
38
40
|
type Span as OtelSpan,
|
|
39
41
|
} from "@opentelemetry/api";
|
|
@@ -49,13 +51,13 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
49
51
|
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
50
52
|
import { randomUUID } from "crypto";
|
|
51
53
|
|
|
52
|
-
import { logger } from "./utils.js";
|
|
54
|
+
import { logger, withOtlpHttpsProxy } from "./utils.js";
|
|
53
55
|
import { VERSION } from "./version.js";
|
|
54
56
|
import type {
|
|
55
57
|
InputMessage,
|
|
56
58
|
OutputMessage,
|
|
57
59
|
MessagePart,
|
|
58
|
-
} from "
|
|
60
|
+
} from "@introspection-sdk/types";
|
|
59
61
|
|
|
60
62
|
// ---------------------------------------------------------------------------
|
|
61
63
|
// Configuration
|
|
@@ -102,11 +104,11 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
102
104
|
private _tracerProvider: BasicTracerProvider;
|
|
103
105
|
private _tracer: ReturnType<BasicTracerProvider["getTracer"]>;
|
|
104
106
|
private _spans: Map<string, OtelSpan> = new Map();
|
|
105
|
-
private _rootSpan: OtelSpan | null = null;
|
|
106
107
|
private _conversationId: string;
|
|
107
108
|
// Track span names and parents so children can resolve gen_ai.agent.name
|
|
108
109
|
private _spanNames: Map<string, string> = new Map();
|
|
109
110
|
private _spanParents: Map<string, string> = new Map();
|
|
111
|
+
private _runRoots: Map<string, string> = new Map();
|
|
110
112
|
// LangChain wrapper names to skip when resolving agent names
|
|
111
113
|
private static _wrapperNames = new Set([
|
|
112
114
|
"RunnableSequence",
|
|
@@ -158,7 +160,9 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
158
160
|
`IntrospectionCallbackHandler initialized: endpoint=${endpoint}`,
|
|
159
161
|
);
|
|
160
162
|
|
|
161
|
-
const spanExporter = new OTLPTraceExporter(
|
|
163
|
+
const spanExporter = new OTLPTraceExporter(
|
|
164
|
+
withOtlpHttpsProxy({ url: endpoint, headers }),
|
|
165
|
+
);
|
|
162
166
|
|
|
163
167
|
const effectiveBatchSize =
|
|
164
168
|
token.startsWith("intro_dev") || token.startsWith("intro_staging")
|
|
@@ -203,29 +207,39 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
203
207
|
this._conversationId = `intro_conv_${randomUUID().replace(/-/g, "")}`;
|
|
204
208
|
}
|
|
205
209
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
210
|
+
private _rootRunId(runId: string, parentRunId?: string): string {
|
|
211
|
+
if (!parentRunId) return runId;
|
|
212
|
+
return this._runRoots.get(parentRunId) || parentRunId;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Keep the top-level run span aligned with child conversation IDs. */
|
|
216
|
+
private _setRootConversationId(
|
|
217
|
+
conversationId: string,
|
|
218
|
+
runId: string,
|
|
219
|
+
parentRunId?: string,
|
|
220
|
+
): void {
|
|
221
|
+
const root = this._spans.get(this._rootRunId(runId, parentRunId));
|
|
222
|
+
root?.setAttribute("gen_ai.conversation.id", conversationId);
|
|
216
223
|
}
|
|
217
224
|
|
|
218
|
-
|
|
225
|
+
private _endRootIfComplete(runId: string): void {
|
|
226
|
+
this._runRoots.delete(runId);
|
|
227
|
+
this._spanNames.delete(runId);
|
|
228
|
+
this._spanParents.delete(runId);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Create a span under a LangChain parent when one exists.
|
|
219
232
|
* Sets gen_ai.agent.name to the parent span's name for hierarchy. */
|
|
220
233
|
private _createChildSpan(
|
|
221
234
|
name: string,
|
|
222
235
|
runId: string,
|
|
223
236
|
parentRunId?: string,
|
|
224
237
|
): OtelSpan {
|
|
225
|
-
const parent =
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
238
|
+
const parent = parentRunId ? this._spans.get(parentRunId) : undefined;
|
|
239
|
+
this._runRoots.set(runId, this._rootRunId(runId, parentRunId));
|
|
240
|
+
const ctx = parent
|
|
241
|
+
? otelTrace.setSpan(otelContext.active(), parent)
|
|
242
|
+
: ROOT_CONTEXT;
|
|
229
243
|
const span = this._tracer.startSpan(name, {}, ctx);
|
|
230
244
|
this._spanNames.set(runId, name);
|
|
231
245
|
if (parentRunId) {
|
|
@@ -262,6 +276,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
262
276
|
this._spans.set(runId, otelSpan);
|
|
263
277
|
|
|
264
278
|
const conversationId = this._getConversationId(metadata);
|
|
279
|
+
this._setRootConversationId(conversationId, runId, parentRunId);
|
|
265
280
|
|
|
266
281
|
otelSpan.setAttribute("gen_ai.operation.name", "chat");
|
|
267
282
|
otelSpan.setAttribute("gen_ai.conversation.id", conversationId);
|
|
@@ -346,6 +361,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
346
361
|
this._spans.set(runId, otelSpan);
|
|
347
362
|
|
|
348
363
|
const conversationId = this._getConversationId(metadata);
|
|
364
|
+
this._setRootConversationId(conversationId, runId, parentRunId);
|
|
349
365
|
|
|
350
366
|
otelSpan.setAttribute("gen_ai.operation.name", "chat");
|
|
351
367
|
otelSpan.setAttribute("gen_ai.conversation.id", conversationId);
|
|
@@ -375,6 +391,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
375
391
|
this._spans.delete(runId);
|
|
376
392
|
this._spanNames.delete(runId);
|
|
377
393
|
this._llmInputs.delete(runId);
|
|
394
|
+
this._endRootIfComplete(runId);
|
|
378
395
|
|
|
379
396
|
const generations = output.generations?.[0];
|
|
380
397
|
if (generations && generations.length > 0) {
|
|
@@ -458,8 +475,10 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
458
475
|
this._spans.delete(runId);
|
|
459
476
|
this._spanNames.delete(runId);
|
|
460
477
|
this._llmInputs.delete(runId);
|
|
461
|
-
|
|
462
|
-
otelSpan.
|
|
478
|
+
this._endRootIfComplete(runId);
|
|
479
|
+
otelSpan.recordException(err);
|
|
480
|
+
otelSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
481
|
+
otelSpan.setAttribute("exception.message", err.message);
|
|
463
482
|
otelSpan.end();
|
|
464
483
|
}
|
|
465
484
|
|
|
@@ -484,6 +503,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
484
503
|
this._spans.set(runId, otelSpan);
|
|
485
504
|
|
|
486
505
|
const conversationId = this._getConversationId(metadata);
|
|
506
|
+
this._setRootConversationId(conversationId, runId, parentRunId);
|
|
487
507
|
otelSpan.setAttribute("gen_ai.conversation.id", conversationId);
|
|
488
508
|
}
|
|
489
509
|
|
|
@@ -491,6 +511,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
491
511
|
const otelSpan = this._spans.get(runId);
|
|
492
512
|
if (!otelSpan) return;
|
|
493
513
|
this._spans.delete(runId);
|
|
514
|
+
this._endRootIfComplete(runId);
|
|
494
515
|
otelSpan.end();
|
|
495
516
|
}
|
|
496
517
|
|
|
@@ -498,8 +519,10 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
498
519
|
const otelSpan = this._spans.get(runId);
|
|
499
520
|
if (!otelSpan) return;
|
|
500
521
|
this._spans.delete(runId);
|
|
501
|
-
|
|
502
|
-
otelSpan.
|
|
522
|
+
this._endRootIfComplete(runId);
|
|
523
|
+
otelSpan.recordException(err);
|
|
524
|
+
otelSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
525
|
+
otelSpan.setAttribute("exception.message", err.message);
|
|
503
526
|
otelSpan.end();
|
|
504
527
|
}
|
|
505
528
|
|
|
@@ -513,7 +536,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
513
536
|
runId: string,
|
|
514
537
|
parentRunId?: string,
|
|
515
538
|
_tags?: string[],
|
|
516
|
-
|
|
539
|
+
metadata?: Record<string, unknown>,
|
|
517
540
|
runName?: string,
|
|
518
541
|
): void {
|
|
519
542
|
const toolName =
|
|
@@ -522,16 +545,20 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
522
545
|
const otelSpan = this._createChildSpan(toolName, runId, parentRunId);
|
|
523
546
|
this._spans.set(runId, otelSpan);
|
|
524
547
|
|
|
548
|
+
const conversationId = this._getConversationId(metadata);
|
|
549
|
+
this._setRootConversationId(conversationId, runId, parentRunId);
|
|
550
|
+
|
|
525
551
|
otelSpan.setAttribute("gen_ai.tool.name", toolName);
|
|
526
552
|
otelSpan.setAttribute("openinference.span.kind", "TOOL");
|
|
527
553
|
otelSpan.setAttribute("gen_ai.tool.input", input);
|
|
528
|
-
otelSpan.setAttribute("gen_ai.conversation.id",
|
|
554
|
+
otelSpan.setAttribute("gen_ai.conversation.id", conversationId);
|
|
529
555
|
}
|
|
530
556
|
|
|
531
557
|
handleToolEnd(output: unknown, runId: string): void {
|
|
532
558
|
const otelSpan = this._spans.get(runId);
|
|
533
559
|
if (!otelSpan) return;
|
|
534
560
|
this._spans.delete(runId);
|
|
561
|
+
this._endRootIfComplete(runId);
|
|
535
562
|
|
|
536
563
|
if (output != null) {
|
|
537
564
|
otelSpan.setAttribute(
|
|
@@ -547,8 +574,10 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
547
574
|
const otelSpan = this._spans.get(runId);
|
|
548
575
|
if (!otelSpan) return;
|
|
549
576
|
this._spans.delete(runId);
|
|
550
|
-
|
|
551
|
-
otelSpan.
|
|
577
|
+
this._endRootIfComplete(runId);
|
|
578
|
+
otelSpan.recordException(err);
|
|
579
|
+
otelSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
580
|
+
otelSpan.setAttribute("exception.message", err.message);
|
|
552
581
|
otelSpan.end();
|
|
553
582
|
}
|
|
554
583
|
|
|
@@ -559,10 +588,9 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
559
588
|
async shutdown(): Promise<void> {
|
|
560
589
|
for (const span of this._spans.values()) span.end();
|
|
561
590
|
this._spans.clear();
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
591
|
+
this._spanNames.clear();
|
|
592
|
+
this._spanParents.clear();
|
|
593
|
+
this._runRoots.clear();
|
|
566
594
|
await this._tracerProvider.shutdown();
|
|
567
595
|
}
|
|
568
596
|
|
|
@@ -623,10 +651,15 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
623
651
|
}
|
|
624
652
|
|
|
625
653
|
private _getConversationId(metadata?: Record<string, unknown>): string {
|
|
626
|
-
const metaConvId = metadata?.["gen_ai.conversation.id"]
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
654
|
+
const metaConvId = metadata?.["gen_ai.conversation.id"];
|
|
655
|
+
if (metaConvId !== undefined && metaConvId !== null) {
|
|
656
|
+
return String(metaConvId);
|
|
657
|
+
}
|
|
658
|
+
const threadId = metadata?.["thread_id"];
|
|
659
|
+
if (threadId !== undefined && threadId !== null) {
|
|
660
|
+
return String(threadId);
|
|
661
|
+
}
|
|
662
|
+
return this._conversationId;
|
|
630
663
|
}
|
|
631
664
|
|
|
632
665
|
private _convertMessages(messages: BaseMessage[]): {
|
package/src/mastra-exporter.ts
CHANGED
|
@@ -51,13 +51,13 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
51
51
|
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
52
52
|
import { randomUUID } from "crypto";
|
|
53
53
|
|
|
54
|
-
import { logger } from "./utils.js";
|
|
54
|
+
import { logger, withOtlpHttpsProxy } from "./utils.js";
|
|
55
55
|
import { VERSION } from "./version.js";
|
|
56
56
|
import type {
|
|
57
57
|
InputMessage,
|
|
58
58
|
OutputMessage,
|
|
59
59
|
MessagePart,
|
|
60
|
-
} from "
|
|
60
|
+
} from "@introspection-sdk/types";
|
|
61
61
|
|
|
62
62
|
// ---------------------------------------------------------------------------
|
|
63
63
|
// Configuration
|
|
@@ -164,7 +164,9 @@ export class IntrospectionMastraExporter extends BaseExporter {
|
|
|
164
164
|
...opts.additionalHeaders,
|
|
165
165
|
};
|
|
166
166
|
|
|
167
|
-
const spanExporter = new OTLPTraceExporter(
|
|
167
|
+
const spanExporter = new OTLPTraceExporter(
|
|
168
|
+
withOtlpHttpsProxy({ url: endpoint, headers }),
|
|
169
|
+
);
|
|
168
170
|
const effectiveBatchSize =
|
|
169
171
|
token.startsWith("intro_dev") || token.startsWith("intro_staging")
|
|
170
172
|
? 1
|
package/src/span-processor.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
|
17
17
|
import { ExportResult, ExportResultCode } from "@opentelemetry/core";
|
|
18
18
|
import { randomUUID } from "crypto";
|
|
19
19
|
import type { AdvancedOptions } from "./types.js";
|
|
20
|
-
import { logger } from "./utils.js";
|
|
20
|
+
import { logger, withOtlpHttpsProxy } from "./utils.js";
|
|
21
21
|
import {
|
|
22
22
|
isOpenInferenceSpan,
|
|
23
23
|
replaceOpenInferenceWithGenAI,
|
|
@@ -65,6 +65,9 @@ class ConvertedReadableSpan implements ReadableSpan {
|
|
|
65
65
|
spanContext() {
|
|
66
66
|
return this._original.spanContext();
|
|
67
67
|
}
|
|
68
|
+
get parentSpanContext() {
|
|
69
|
+
return this._original.parentSpanContext;
|
|
70
|
+
}
|
|
68
71
|
get startTime() {
|
|
69
72
|
return this._original.startTime;
|
|
70
73
|
}
|
|
@@ -177,10 +180,12 @@ export class IntrospectionSpanProcessor implements SpanProcessor {
|
|
|
177
180
|
// Use custom spanExporter if provided (for testing), otherwise create OTLP exporter
|
|
178
181
|
const baseExporter: SpanExporter =
|
|
179
182
|
advanced.spanExporter ||
|
|
180
|
-
new OTLPTraceExporter(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
183
|
+
new OTLPTraceExporter(
|
|
184
|
+
withOtlpHttpsProxy({
|
|
185
|
+
url: endpoint,
|
|
186
|
+
headers,
|
|
187
|
+
}),
|
|
188
|
+
);
|
|
184
189
|
|
|
185
190
|
// Wrap exporter to add v1/v2 compatibility and basic validation
|
|
186
191
|
const exporter: SpanExporter = {
|
package/src/tracing-processor.ts
CHANGED
|
@@ -32,7 +32,7 @@ import type {
|
|
|
32
32
|
Response as OpenAIResponse,
|
|
33
33
|
ResponseInputItem,
|
|
34
34
|
} from "./converters/openai.js";
|
|
35
|
-
import { logger } from "./utils.js";
|
|
35
|
+
import { logger, withOtlpHttpsProxy } from "./utils.js";
|
|
36
36
|
import { VERSION } from "./version.js";
|
|
37
37
|
|
|
38
38
|
// Type imports from @openai/agents
|
|
@@ -150,10 +150,12 @@ export class IntrospectionTracingProcessor implements TracingProcessor {
|
|
|
150
150
|
);
|
|
151
151
|
|
|
152
152
|
// Setup OTLP exporter
|
|
153
|
-
const spanExporter = new OTLPTraceExporter(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
const spanExporter = new OTLPTraceExporter(
|
|
154
|
+
withOtlpHttpsProxy({
|
|
155
|
+
url: endpoint,
|
|
156
|
+
headers,
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
157
159
|
|
|
158
160
|
// Use SimpleSpanProcessor for maxExportBatchSize=1 (sequential export),
|
|
159
161
|
// otherwise BatchSpanProcessor with configurable batch size.
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { DiagLogLevel, DiagLogger } from "@opentelemetry/api";
|
|
2
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
3
|
+
|
|
4
|
+
function getHttpsProxyUrl(): string | undefined {
|
|
5
|
+
return process.env.HTTPS_PROXY || undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function withOtlpHttpsProxy<T extends object>(options: T): T {
|
|
9
|
+
const proxyUrl = getHttpsProxyUrl();
|
|
10
|
+
if (!proxyUrl) return options;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
...options,
|
|
14
|
+
httpAgentOptions: () => new HttpsProxyAgent(proxyUrl),
|
|
15
|
+
} as T;
|
|
16
|
+
}
|
|
2
17
|
|
|
3
18
|
/**
|
|
4
19
|
* Logger for introspection-sdk package.
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @introspection-sdk/introspection-node@0.1.0 lint /Users/julian/projects/introspection-org/introspection-js-sdk/packages/introspection-node
|
|
3
|
-
> eslint . --max-warnings 0
|
|
4
|
-
|
|
5
|
-
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Attributes } from "@opentelemetry/api";
|
|
2
|
-
/**
|
|
3
|
-
* Detect openclaw spans by the presence of openclaw.* attributes.
|
|
4
|
-
* openclaw does not set a distinguishing instrumentation scope, so we
|
|
5
|
-
* use attribute-key presence instead.
|
|
6
|
-
*/
|
|
7
|
-
export declare function isOpenClawSpan(attrs?: Attributes): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Replace mapped openclaw.* attributes with gen_ai semantic conventions.
|
|
10
|
-
* Unmapped openclaw.* attributes (e.g. openclaw.channel, openclaw.sessionId)
|
|
11
|
-
* are preserved unchanged.
|
|
12
|
-
*/
|
|
13
|
-
export declare function replaceOpenClawWithGenAI(
|
|
14
|
-
attrs?: Attributes,
|
|
15
|
-
): Attributes;
|
|
16
|
-
//# sourceMappingURL=openclaw.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openclaw.d.ts","sourceRoot":"","sources":["../../src/converters/openclaw.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAiBrD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAG1D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,UAAU,CAyBvE"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenClaw attribute keys that have gen_ai semantic convention equivalents.
|
|
3
|
-
* Other openclaw.* attributes (channel, sessionId, lane, etc.) are preserved as-is.
|
|
4
|
-
*
|
|
5
|
-
* @see https://github.com/openclaw/openclaw/tree/main/extensions/diagnostics-otel
|
|
6
|
-
*/
|
|
7
|
-
const OC = {
|
|
8
|
-
MODEL: "openclaw.model",
|
|
9
|
-
PROVIDER: "openclaw.provider",
|
|
10
|
-
TOKENS_INPUT: "openclaw.tokens.input",
|
|
11
|
-
TOKENS_OUTPUT: "openclaw.tokens.output",
|
|
12
|
-
};
|
|
13
|
-
const MAPPED_KEYS = new Set(Object.values(OC));
|
|
14
|
-
/**
|
|
15
|
-
* Detect openclaw spans by the presence of openclaw.* attributes.
|
|
16
|
-
* openclaw does not set a distinguishing instrumentation scope, so we
|
|
17
|
-
* use attribute-key presence instead.
|
|
18
|
-
*/
|
|
19
|
-
export function isOpenClawSpan(attrs) {
|
|
20
|
-
if (!attrs) return false;
|
|
21
|
-
return Object.keys(attrs).some((key) => key.startsWith("openclaw."));
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Replace mapped openclaw.* attributes with gen_ai semantic conventions.
|
|
25
|
-
* Unmapped openclaw.* attributes (e.g. openclaw.channel, openclaw.sessionId)
|
|
26
|
-
* are preserved unchanged.
|
|
27
|
-
*/
|
|
28
|
-
export function replaceOpenClawWithGenAI(attrs) {
|
|
29
|
-
if (!attrs) return {};
|
|
30
|
-
const result = {};
|
|
31
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
32
|
-
if (!MAPPED_KEYS.has(key)) {
|
|
33
|
-
result[key] = value;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (attrs[OC.MODEL] !== undefined) {
|
|
37
|
-
result["gen_ai.request.model"] = attrs[OC.MODEL];
|
|
38
|
-
}
|
|
39
|
-
if (attrs[OC.PROVIDER] !== undefined) {
|
|
40
|
-
result["gen_ai.system"] = attrs[OC.PROVIDER];
|
|
41
|
-
}
|
|
42
|
-
if (attrs[OC.TOKENS_INPUT] !== undefined) {
|
|
43
|
-
result["gen_ai.usage.input_tokens"] = attrs[OC.TOKENS_INPUT];
|
|
44
|
-
}
|
|
45
|
-
if (attrs[OC.TOKENS_OUTPUT] !== undefined) {
|
|
46
|
-
result["gen_ai.usage.output_tokens"] = attrs[OC.TOKENS_OUTPUT];
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
package/dist/types/genai.d.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OTel Gen AI Semantic Convention types.
|
|
3
|
-
*
|
|
4
|
-
* These types represent the standardized format for gen_ai.input.messages
|
|
5
|
-
* and gen_ai.output.messages attributes as per OpenTelemetry Gen AI semantic conventions.
|
|
6
|
-
*
|
|
7
|
-
* @see https://opentelemetry.io/docs/specs/semconv/gen-ai/
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* A text content part in a message.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const part: TextPart = { type: "text", content: "Hello" };
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export interface TextPart {
|
|
18
|
-
/** Discriminator — always `"text"`. */
|
|
19
|
-
type: "text";
|
|
20
|
-
/** The text body of this part. */
|
|
21
|
-
content: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A tool / function-call request part in a message.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const part: ToolCallRequestPart = { type: "tool_call", name: "get_weather", arguments: { city: "SF" } };
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export interface ToolCallRequestPart {
|
|
32
|
-
/** Discriminator — always `"tool_call"`. */
|
|
33
|
-
type: "tool_call";
|
|
34
|
-
/** Function / tool name. */
|
|
35
|
-
name: string;
|
|
36
|
-
/** Correlation ID linking request to response. */
|
|
37
|
-
id?: string;
|
|
38
|
-
/** Arguments passed to the tool. */
|
|
39
|
-
arguments?: unknown;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A tool / function-call response part in a message.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* const part: ToolCallResponsePart = { type: "tool_call_response", response: "72°F" };
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export interface ToolCallResponsePart {
|
|
50
|
-
/** Discriminator — always `"tool_call_response"`. */
|
|
51
|
-
type: "tool_call_response";
|
|
52
|
-
/** The value returned by the tool. */
|
|
53
|
-
response: unknown;
|
|
54
|
-
/** Correlation ID linking response to request. */
|
|
55
|
-
id?: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* A reasoning / thinking content part in a message.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```ts
|
|
62
|
-
* const part: ReasoningPart = { type: "thinking", content: "Let me think through this..." };
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export interface ReasoningPart {
|
|
66
|
-
/** Discriminator — always `"thinking"`. */
|
|
67
|
-
type: "thinking";
|
|
68
|
-
/** The reasoning / thinking summary content. */
|
|
69
|
-
content?: string;
|
|
70
|
-
/** Encrypted reasoning signature (maps to OpenAI encrypted_content, Anthropic signature/redacted_thinking data). */
|
|
71
|
-
signature?: string;
|
|
72
|
-
/** Provider that produced this thinking block (e.g. `"anthropic"`, `"openai"`). Used to reconstruct the correct wire format on replay. */
|
|
73
|
-
provider_name?: string;
|
|
74
|
-
}
|
|
75
|
-
/** Union of all possible message-part shapes. */
|
|
76
|
-
export type MessagePart = TextPart | ToolCallRequestPart | ToolCallResponsePart | ReasoningPart;
|
|
77
|
-
/**
|
|
78
|
-
* A system instruction entry for `gen_ai.system_instructions`.
|
|
79
|
-
*/
|
|
80
|
-
export interface SystemInstruction {
|
|
81
|
-
/** Part type — always `"text"`. */
|
|
82
|
-
type: "text";
|
|
83
|
-
/** The instruction text content. */
|
|
84
|
-
content: string;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* An input message in OTel Gen AI semantic convention format.
|
|
88
|
-
*
|
|
89
|
-
* Used for the `gen_ai.input.messages` span attribute.
|
|
90
|
-
*/
|
|
91
|
-
export interface InputMessage {
|
|
92
|
-
/** The role of the message sender. */
|
|
93
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
94
|
-
/** Ordered content parts that compose this message. */
|
|
95
|
-
parts: MessagePart[];
|
|
96
|
-
/** Optional tool name when `role` is `"tool"`. */
|
|
97
|
-
name?: string;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* An output message in OTel Gen AI semantic convention format.
|
|
101
|
-
*
|
|
102
|
-
* Used for the `gen_ai.output.messages` span attribute.
|
|
103
|
-
*/
|
|
104
|
-
export interface OutputMessage {
|
|
105
|
-
/** The role of the message sender. */
|
|
106
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
107
|
-
/** Ordered content parts that compose this message. */
|
|
108
|
-
parts: MessagePart[];
|
|
109
|
-
/** Model-reported finish reason (e.g. `"stop"`, `"end_turn"`). */
|
|
110
|
-
finish_reason?: string;
|
|
111
|
-
/** Optional tool name when `role` is `"tool"`. */
|
|
112
|
-
name?: string;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* A tool definition for the `gen_ai.tool.definitions` attribute.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* const def: ToolDefinition = { name: "get_weather", description: "Get current weather" };
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
export interface ToolDefinition {
|
|
123
|
-
/** Tool / function name. */
|
|
124
|
-
name: string;
|
|
125
|
-
/** Human-readable description of what the tool does. */
|
|
126
|
-
description?: string;
|
|
127
|
-
/** JSON Schema describing the tool's parameters. */
|
|
128
|
-
parameters?: Record<string, unknown>;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* GenAI semantic convention attributes.
|
|
132
|
-
*
|
|
133
|
-
* This interface represents the standardized GenAI attributes that can be
|
|
134
|
-
* converted to OpenTelemetry semantic convention format (gen_ai.* with dots).
|
|
135
|
-
*
|
|
136
|
-
* All properties use camelCase following TypeScript conventions.
|
|
137
|
-
*/
|
|
138
|
-
export interface GenAiAttributes {
|
|
139
|
-
/** Model name (gen_ai.request.model) */
|
|
140
|
-
requestModel?: string;
|
|
141
|
-
/** System prompt (gen_ai.system) */
|
|
142
|
-
system?: string;
|
|
143
|
-
/** Operation name (gen_ai.operation.name) */
|
|
144
|
-
operationName?: string;
|
|
145
|
-
/** Tool definitions (gen_ai.tool.definitions) — serialized to JSON by {@link toAttributes}. */
|
|
146
|
-
toolDefinitions?: ToolDefinition[];
|
|
147
|
-
/** Input messages (gen_ai.input.messages) — serialized to JSON by {@link toAttributes}. */
|
|
148
|
-
inputMessages?: InputMessage[];
|
|
149
|
-
/** Output messages (gen_ai.output.messages) — serialized to JSON by {@link toAttributes}. */
|
|
150
|
-
outputMessages?: OutputMessage[];
|
|
151
|
-
/** System instructions (gen_ai.system_instructions) — serialized to JSON by {@link toAttributes}. */
|
|
152
|
-
systemInstructions?: SystemInstruction[];
|
|
153
|
-
/** Response ID (gen_ai.response.id) */
|
|
154
|
-
responseId?: string;
|
|
155
|
-
/** Input token count (gen_ai.usage.input_tokens) */
|
|
156
|
-
inputTokens?: number;
|
|
157
|
-
/** Output token count (gen_ai.usage.output_tokens) */
|
|
158
|
-
outputTokens?: number;
|
|
159
|
-
/** Cache creation input tokens (gen_ai.usage.cache_creation_input_tokens) */
|
|
160
|
-
cacheCreationInputTokens?: number;
|
|
161
|
-
/** Cache read input tokens (gen_ai.usage.cache_read_input_tokens) */
|
|
162
|
-
cacheReadInputTokens?: number;
|
|
163
|
-
}
|
|
164
|
-
export declare function toAttributes(attrs: GenAiAttributes): Record<string, string | number>;
|
|
165
|
-
//# sourceMappingURL=genai.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"genai.d.ts","sourceRoot":"","sources":["../../src/types/genai.ts"],"names":[],"mappings":"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"}
|