@agentmark-ai/shared-utils 0.6.1 → 0.7.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/dist/index.d.mts +163 -1
- package/dist/index.d.ts +163 -1
- package/dist/index.js +529 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +522 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -448,6 +448,92 @@ declare function extractCustomMetadata(attributes: Record<string, any>, prefix?:
|
|
|
448
448
|
*/
|
|
449
449
|
declare function parseAgentMarkAttributes(attributes: Record<string, any>, prefix?: string): Partial<NormalizedSpan>;
|
|
450
450
|
|
|
451
|
+
/**
|
|
452
|
+
* Shared parser for the "flattened indexed message" attribute shape used by
|
|
453
|
+
* both OpenInference and OpenLLMetry/Traceloop. Neither emits a single JSON
|
|
454
|
+
* messages array (the way OTel GenAI v1.37+ does with `gen_ai.input.messages`);
|
|
455
|
+
* instead they explode each message into one attribute per field, indexed by
|
|
456
|
+
* position:
|
|
457
|
+
*
|
|
458
|
+
* OpenInference:
|
|
459
|
+
* llm.input_messages.0.message.role = "user"
|
|
460
|
+
* llm.input_messages.0.message.content = "hello"
|
|
461
|
+
* llm.output_messages.0.message.tool_calls.0.tool_call.function.name = "search"
|
|
462
|
+
* llm.output_messages.0.message.tool_calls.0.tool_call.function.arguments = "{...}"
|
|
463
|
+
*
|
|
464
|
+
* OpenLLMetry / Traceloop:
|
|
465
|
+
* gen_ai.prompt.0.role = "user"
|
|
466
|
+
* gen_ai.prompt.0.content = "hello"
|
|
467
|
+
* gen_ai.completion.0.tool_calls.0.name = "search"
|
|
468
|
+
* gen_ai.completion.0.tool_calls.0.arguments = "{...}"
|
|
469
|
+
*
|
|
470
|
+
* The two differ only in path fragments (a `message.` infix, a `tool_call.`
|
|
471
|
+
* infix, `function.name` vs `name`), so one config-driven parser serves both.
|
|
472
|
+
*/
|
|
473
|
+
interface IndexedMessageConfig {
|
|
474
|
+
/** Attribute prefix that precedes the integer index, e.g. "llm.input_messages". */
|
|
475
|
+
prefix: string;
|
|
476
|
+
/** Path fragment between the index and the per-message fields. OpenInference uses
|
|
477
|
+
* "message." (so keys read `…0.message.role`); OpenLLMetry uses "" (`…0.role`). */
|
|
478
|
+
messageInfix: string;
|
|
479
|
+
/** Field name for the role. Default "role". */
|
|
480
|
+
roleKey?: string;
|
|
481
|
+
/** Field name for scalar text content. Default "content". */
|
|
482
|
+
contentKey?: string;
|
|
483
|
+
/** Multi-part content list field (OpenInference `contents`), read when the scalar
|
|
484
|
+
* content field is absent. Each part lives at
|
|
485
|
+
* `${base}${contentsKey}.${j}.${contentsPartInfix}text`. Omit to disable. */
|
|
486
|
+
contentsKey?: string;
|
|
487
|
+
/** Path fragment after the contents index, e.g. "message_content." for OpenInference. */
|
|
488
|
+
contentsPartInfix?: string;
|
|
489
|
+
/** Tool-call sub-shape. Omit if the source never carries tool calls. */
|
|
490
|
+
toolCalls?: {
|
|
491
|
+
/** Array field name under a message, e.g. "tool_calls". */
|
|
492
|
+
arrayKey: string;
|
|
493
|
+
/** Fragment between the tool-call index and its fields. OpenInference uses
|
|
494
|
+
* "tool_call." ; OpenLLMetry uses "". */
|
|
495
|
+
infix: string;
|
|
496
|
+
/** Relative key to the call id, e.g. "id". */
|
|
497
|
+
idKey: string;
|
|
498
|
+
/** Relative key to the tool name. OpenInference "function.name"; OpenLLMetry "name". */
|
|
499
|
+
nameKey: string;
|
|
500
|
+
/** Relative key to the JSON-string arguments. OpenInference "function.arguments";
|
|
501
|
+
* OpenLLMetry "arguments". */
|
|
502
|
+
argsKey: string;
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Collect the distinct, ascending integer indices that appear immediately after
|
|
507
|
+
* `prefix.` across the attribute keys. Tolerant of gaps and arbitrary key order
|
|
508
|
+
* (a span may emit message 2 before message 0); we never assume a dense 0..n.
|
|
509
|
+
* Exported so transformers can reuse it for non-message indexed groups
|
|
510
|
+
* (e.g. OpenInference `retrieval.documents.{i}.*`).
|
|
511
|
+
*/
|
|
512
|
+
declare function collectIndices(attributes: Record<string, any>, prefix: string): number[];
|
|
513
|
+
/**
|
|
514
|
+
* Parse the flattened indexed messages under `config.prefix` into normalized
|
|
515
|
+
* Messages. A message that carries tool calls gets an array content of a text
|
|
516
|
+
* part (when present) followed by `tool-call` parts, so conversation history is
|
|
517
|
+
* preserved with full fidelity; a text-only message gets a plain string content.
|
|
518
|
+
* Returns `undefined` when no messages are present (lets callers fall through to
|
|
519
|
+
* other extraction paths).
|
|
520
|
+
*/
|
|
521
|
+
declare function parseIndexedMessages(attributes: Record<string, any>, config: IndexedMessageConfig): Message[] | undefined;
|
|
522
|
+
/**
|
|
523
|
+
* Flatten every tool call across the indexed messages under `config.prefix` into
|
|
524
|
+
* a span-level ToolCall[]. Used for the response side, where OpenInference and
|
|
525
|
+
* OpenLLMetry place the assistant's tool calls inside `output_messages` /
|
|
526
|
+
* `gen_ai.completion` and AgentMark surfaces them as `span.toolCalls`.
|
|
527
|
+
*/
|
|
528
|
+
declare function extractIndexedToolCalls(attributes: Record<string, any>, config: IndexedMessageConfig): ToolCall[] | undefined;
|
|
529
|
+
/**
|
|
530
|
+
* Collapse normalized messages into a single plain-text string (text parts only,
|
|
531
|
+
* newline-joined). Tool-call parts are intentionally dropped — they travel
|
|
532
|
+
* separately via `extractIndexedToolCalls`. Returns `undefined` when there is no
|
|
533
|
+
* text to show.
|
|
534
|
+
*/
|
|
535
|
+
declare function messagesToPlainText(messages: Message[] | undefined): string | undefined;
|
|
536
|
+
|
|
451
537
|
/** Valid semantic kind values. */
|
|
452
538
|
declare const SEMANTIC_KINDS: readonly ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
453
539
|
type SemanticKind = typeof SEMANTIC_KINDS[number];
|
|
@@ -557,6 +643,82 @@ declare class OtelGenAiTransformer implements ScopeTransformer {
|
|
|
557
643
|
static readonly SCOPE_NAME = "pydantic-ai";
|
|
558
644
|
}
|
|
559
645
|
|
|
646
|
+
/**
|
|
647
|
+
* Transformer for the OpenInference semantic conventions — the instrumentation
|
|
648
|
+
* standard maintained by Arize and used by ~30 auto-instrumentors (LangChain,
|
|
649
|
+
* LlamaIndex, OpenAI Agents SDK, CrewAI, DSPy, Haystack, smolagents, Bedrock,
|
|
650
|
+
* Anthropic, Google ADK, Instructor, MCP, Guardrails, …). Those instrumentors
|
|
651
|
+
* each set their own OTel scope name, so this transformer is reached via the
|
|
652
|
+
* attribute-signature dispatcher rather than a scope registration (see the
|
|
653
|
+
* DispatchingTransformer).
|
|
654
|
+
*
|
|
655
|
+
* Span *classification* (openinference.span.kind → SpanKind) is already handled
|
|
656
|
+
* by resolveSemanticKind; this transformer fills the gap that left the IO,
|
|
657
|
+
* model, and token fields empty, because the default OTel-GenAI transformer only
|
|
658
|
+
* reads `gen_ai.*` keys and OpenInference uses an entirely different shape.
|
|
659
|
+
*
|
|
660
|
+
* @see https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md
|
|
661
|
+
*/
|
|
662
|
+
|
|
663
|
+
declare class OpenInferenceTransformer implements ScopeTransformer {
|
|
664
|
+
classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
665
|
+
transform(_span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Transformer for the OpenLLMetry / Traceloop conventions (which OpenLIT also
|
|
670
|
+
* largely follows). These instrumentors back the AutoGen, Semantic Kernel, and
|
|
671
|
+
* Agno integrations, among others. Like OpenInference, each emits its own OTel
|
|
672
|
+
* scope name, so this transformer is reached via the attribute-signature
|
|
673
|
+
* dispatcher rather than a scope registration.
|
|
674
|
+
*
|
|
675
|
+
* Tokens and model already partly resolve through the default OTel-GenAI
|
|
676
|
+
* transformer's legacy `gen_ai.usage.prompt_tokens` fallbacks; the gap this
|
|
677
|
+
* closes is the IO, which OpenLLMetry flattens into indexed
|
|
678
|
+
* `gen_ai.prompt.{i}.*` / `gen_ai.completion.{i}.*` attributes (and, for
|
|
679
|
+
* workflow/task spans, `traceloop.entity.input/output`) rather than the
|
|
680
|
+
* `gen_ai.input.messages` JSON array the default transformer expects.
|
|
681
|
+
*
|
|
682
|
+
* @see https://www.traceloop.com/docs/openllmetry/privacy/traces
|
|
683
|
+
*/
|
|
684
|
+
|
|
685
|
+
declare class OpenLLMetryTransformer implements ScopeTransformer {
|
|
686
|
+
classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
687
|
+
transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Default transformer that routes a span to the right extractor by sniffing its
|
|
692
|
+
* attribute signature, instead of by OTel scope name.
|
|
693
|
+
*
|
|
694
|
+
* The registry dispatches scope → transformer by exact match, which works for
|
|
695
|
+
* SDKs that emit one stable scope (Vercel AI SDK = "ai", Mastra =
|
|
696
|
+
* "default-tracer", …). But the OpenInference and OpenLLMetry ecosystems each
|
|
697
|
+
* span dozens of instrumentor scope names
|
|
698
|
+
* (`openinference.instrumentation.langchain`,
|
|
699
|
+
* `@arizeai/openinference-instrumentation-openai`, `opentelemetry.instrumentation.openai`, …),
|
|
700
|
+
* so per-scope registration doesn't scale. This transformer is registered as the
|
|
701
|
+
* registry *default* (replacing the bare OTel-GenAI default) and picks the
|
|
702
|
+
* extractor from unambiguous attribute markers, falling back to the OTel GenAI
|
|
703
|
+
* semantic conventions when nothing framework-specific is present.
|
|
704
|
+
*
|
|
705
|
+
* classify() and transform() must agree on the chosen extractor, so both call
|
|
706
|
+
* the single `select()` method.
|
|
707
|
+
*/
|
|
708
|
+
|
|
709
|
+
declare class DispatchingTransformer implements ScopeTransformer {
|
|
710
|
+
private readonly openInference;
|
|
711
|
+
private readonly openLLMetry;
|
|
712
|
+
private readonly otelGenAi;
|
|
713
|
+
/** Choose the extractor for a span from its attribute signature. OpenInference
|
|
714
|
+
* is checked before OpenLLMetry because its markers (`llm.*`,
|
|
715
|
+
* `openinference.span.kind`) are more specific; the bare OTel GenAI
|
|
716
|
+
* transformer is the catch-all. */
|
|
717
|
+
select(attributes: Record<string, any>): ScopeTransformer;
|
|
718
|
+
classify(span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
719
|
+
transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
720
|
+
}
|
|
721
|
+
|
|
560
722
|
declare function normalizeOtlpStatusCode(raw: string | number | undefined | null): string;
|
|
561
723
|
declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: OtelSpan): NormalizedSpan;
|
|
562
724
|
/**
|
|
@@ -565,4 +727,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
|
|
|
565
727
|
*/
|
|
566
728
|
declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
|
|
567
729
|
|
|
568
|
-
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
|
|
730
|
+
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, DispatchingTransformer, type GenerateTypesLanguage, type IndexedMessageConfig, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, OpenInferenceTransformer, OpenLLMetryTransformer, type OtelEvent, OtelGenAiTransformer, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, collectIndices, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractIndexedToolCalls, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, messagesToPlainText, normalizeOtlpSpans, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, parseIndexedMessages, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -448,6 +448,92 @@ declare function extractCustomMetadata(attributes: Record<string, any>, prefix?:
|
|
|
448
448
|
*/
|
|
449
449
|
declare function parseAgentMarkAttributes(attributes: Record<string, any>, prefix?: string): Partial<NormalizedSpan>;
|
|
450
450
|
|
|
451
|
+
/**
|
|
452
|
+
* Shared parser for the "flattened indexed message" attribute shape used by
|
|
453
|
+
* both OpenInference and OpenLLMetry/Traceloop. Neither emits a single JSON
|
|
454
|
+
* messages array (the way OTel GenAI v1.37+ does with `gen_ai.input.messages`);
|
|
455
|
+
* instead they explode each message into one attribute per field, indexed by
|
|
456
|
+
* position:
|
|
457
|
+
*
|
|
458
|
+
* OpenInference:
|
|
459
|
+
* llm.input_messages.0.message.role = "user"
|
|
460
|
+
* llm.input_messages.0.message.content = "hello"
|
|
461
|
+
* llm.output_messages.0.message.tool_calls.0.tool_call.function.name = "search"
|
|
462
|
+
* llm.output_messages.0.message.tool_calls.0.tool_call.function.arguments = "{...}"
|
|
463
|
+
*
|
|
464
|
+
* OpenLLMetry / Traceloop:
|
|
465
|
+
* gen_ai.prompt.0.role = "user"
|
|
466
|
+
* gen_ai.prompt.0.content = "hello"
|
|
467
|
+
* gen_ai.completion.0.tool_calls.0.name = "search"
|
|
468
|
+
* gen_ai.completion.0.tool_calls.0.arguments = "{...}"
|
|
469
|
+
*
|
|
470
|
+
* The two differ only in path fragments (a `message.` infix, a `tool_call.`
|
|
471
|
+
* infix, `function.name` vs `name`), so one config-driven parser serves both.
|
|
472
|
+
*/
|
|
473
|
+
interface IndexedMessageConfig {
|
|
474
|
+
/** Attribute prefix that precedes the integer index, e.g. "llm.input_messages". */
|
|
475
|
+
prefix: string;
|
|
476
|
+
/** Path fragment between the index and the per-message fields. OpenInference uses
|
|
477
|
+
* "message." (so keys read `…0.message.role`); OpenLLMetry uses "" (`…0.role`). */
|
|
478
|
+
messageInfix: string;
|
|
479
|
+
/** Field name for the role. Default "role". */
|
|
480
|
+
roleKey?: string;
|
|
481
|
+
/** Field name for scalar text content. Default "content". */
|
|
482
|
+
contentKey?: string;
|
|
483
|
+
/** Multi-part content list field (OpenInference `contents`), read when the scalar
|
|
484
|
+
* content field is absent. Each part lives at
|
|
485
|
+
* `${base}${contentsKey}.${j}.${contentsPartInfix}text`. Omit to disable. */
|
|
486
|
+
contentsKey?: string;
|
|
487
|
+
/** Path fragment after the contents index, e.g. "message_content." for OpenInference. */
|
|
488
|
+
contentsPartInfix?: string;
|
|
489
|
+
/** Tool-call sub-shape. Omit if the source never carries tool calls. */
|
|
490
|
+
toolCalls?: {
|
|
491
|
+
/** Array field name under a message, e.g. "tool_calls". */
|
|
492
|
+
arrayKey: string;
|
|
493
|
+
/** Fragment between the tool-call index and its fields. OpenInference uses
|
|
494
|
+
* "tool_call." ; OpenLLMetry uses "". */
|
|
495
|
+
infix: string;
|
|
496
|
+
/** Relative key to the call id, e.g. "id". */
|
|
497
|
+
idKey: string;
|
|
498
|
+
/** Relative key to the tool name. OpenInference "function.name"; OpenLLMetry "name". */
|
|
499
|
+
nameKey: string;
|
|
500
|
+
/** Relative key to the JSON-string arguments. OpenInference "function.arguments";
|
|
501
|
+
* OpenLLMetry "arguments". */
|
|
502
|
+
argsKey: string;
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Collect the distinct, ascending integer indices that appear immediately after
|
|
507
|
+
* `prefix.` across the attribute keys. Tolerant of gaps and arbitrary key order
|
|
508
|
+
* (a span may emit message 2 before message 0); we never assume a dense 0..n.
|
|
509
|
+
* Exported so transformers can reuse it for non-message indexed groups
|
|
510
|
+
* (e.g. OpenInference `retrieval.documents.{i}.*`).
|
|
511
|
+
*/
|
|
512
|
+
declare function collectIndices(attributes: Record<string, any>, prefix: string): number[];
|
|
513
|
+
/**
|
|
514
|
+
* Parse the flattened indexed messages under `config.prefix` into normalized
|
|
515
|
+
* Messages. A message that carries tool calls gets an array content of a text
|
|
516
|
+
* part (when present) followed by `tool-call` parts, so conversation history is
|
|
517
|
+
* preserved with full fidelity; a text-only message gets a plain string content.
|
|
518
|
+
* Returns `undefined` when no messages are present (lets callers fall through to
|
|
519
|
+
* other extraction paths).
|
|
520
|
+
*/
|
|
521
|
+
declare function parseIndexedMessages(attributes: Record<string, any>, config: IndexedMessageConfig): Message[] | undefined;
|
|
522
|
+
/**
|
|
523
|
+
* Flatten every tool call across the indexed messages under `config.prefix` into
|
|
524
|
+
* a span-level ToolCall[]. Used for the response side, where OpenInference and
|
|
525
|
+
* OpenLLMetry place the assistant's tool calls inside `output_messages` /
|
|
526
|
+
* `gen_ai.completion` and AgentMark surfaces them as `span.toolCalls`.
|
|
527
|
+
*/
|
|
528
|
+
declare function extractIndexedToolCalls(attributes: Record<string, any>, config: IndexedMessageConfig): ToolCall[] | undefined;
|
|
529
|
+
/**
|
|
530
|
+
* Collapse normalized messages into a single plain-text string (text parts only,
|
|
531
|
+
* newline-joined). Tool-call parts are intentionally dropped — they travel
|
|
532
|
+
* separately via `extractIndexedToolCalls`. Returns `undefined` when there is no
|
|
533
|
+
* text to show.
|
|
534
|
+
*/
|
|
535
|
+
declare function messagesToPlainText(messages: Message[] | undefined): string | undefined;
|
|
536
|
+
|
|
451
537
|
/** Valid semantic kind values. */
|
|
452
538
|
declare const SEMANTIC_KINDS: readonly ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
453
539
|
type SemanticKind = typeof SEMANTIC_KINDS[number];
|
|
@@ -557,6 +643,82 @@ declare class OtelGenAiTransformer implements ScopeTransformer {
|
|
|
557
643
|
static readonly SCOPE_NAME = "pydantic-ai";
|
|
558
644
|
}
|
|
559
645
|
|
|
646
|
+
/**
|
|
647
|
+
* Transformer for the OpenInference semantic conventions — the instrumentation
|
|
648
|
+
* standard maintained by Arize and used by ~30 auto-instrumentors (LangChain,
|
|
649
|
+
* LlamaIndex, OpenAI Agents SDK, CrewAI, DSPy, Haystack, smolagents, Bedrock,
|
|
650
|
+
* Anthropic, Google ADK, Instructor, MCP, Guardrails, …). Those instrumentors
|
|
651
|
+
* each set their own OTel scope name, so this transformer is reached via the
|
|
652
|
+
* attribute-signature dispatcher rather than a scope registration (see the
|
|
653
|
+
* DispatchingTransformer).
|
|
654
|
+
*
|
|
655
|
+
* Span *classification* (openinference.span.kind → SpanKind) is already handled
|
|
656
|
+
* by resolveSemanticKind; this transformer fills the gap that left the IO,
|
|
657
|
+
* model, and token fields empty, because the default OTel-GenAI transformer only
|
|
658
|
+
* reads `gen_ai.*` keys and OpenInference uses an entirely different shape.
|
|
659
|
+
*
|
|
660
|
+
* @see https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md
|
|
661
|
+
*/
|
|
662
|
+
|
|
663
|
+
declare class OpenInferenceTransformer implements ScopeTransformer {
|
|
664
|
+
classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
665
|
+
transform(_span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Transformer for the OpenLLMetry / Traceloop conventions (which OpenLIT also
|
|
670
|
+
* largely follows). These instrumentors back the AutoGen, Semantic Kernel, and
|
|
671
|
+
* Agno integrations, among others. Like OpenInference, each emits its own OTel
|
|
672
|
+
* scope name, so this transformer is reached via the attribute-signature
|
|
673
|
+
* dispatcher rather than a scope registration.
|
|
674
|
+
*
|
|
675
|
+
* Tokens and model already partly resolve through the default OTel-GenAI
|
|
676
|
+
* transformer's legacy `gen_ai.usage.prompt_tokens` fallbacks; the gap this
|
|
677
|
+
* closes is the IO, which OpenLLMetry flattens into indexed
|
|
678
|
+
* `gen_ai.prompt.{i}.*` / `gen_ai.completion.{i}.*` attributes (and, for
|
|
679
|
+
* workflow/task spans, `traceloop.entity.input/output`) rather than the
|
|
680
|
+
* `gen_ai.input.messages` JSON array the default transformer expects.
|
|
681
|
+
*
|
|
682
|
+
* @see https://www.traceloop.com/docs/openllmetry/privacy/traces
|
|
683
|
+
*/
|
|
684
|
+
|
|
685
|
+
declare class OpenLLMetryTransformer implements ScopeTransformer {
|
|
686
|
+
classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
687
|
+
transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Default transformer that routes a span to the right extractor by sniffing its
|
|
692
|
+
* attribute signature, instead of by OTel scope name.
|
|
693
|
+
*
|
|
694
|
+
* The registry dispatches scope → transformer by exact match, which works for
|
|
695
|
+
* SDKs that emit one stable scope (Vercel AI SDK = "ai", Mastra =
|
|
696
|
+
* "default-tracer", …). But the OpenInference and OpenLLMetry ecosystems each
|
|
697
|
+
* span dozens of instrumentor scope names
|
|
698
|
+
* (`openinference.instrumentation.langchain`,
|
|
699
|
+
* `@arizeai/openinference-instrumentation-openai`, `opentelemetry.instrumentation.openai`, …),
|
|
700
|
+
* so per-scope registration doesn't scale. This transformer is registered as the
|
|
701
|
+
* registry *default* (replacing the bare OTel-GenAI default) and picks the
|
|
702
|
+
* extractor from unambiguous attribute markers, falling back to the OTel GenAI
|
|
703
|
+
* semantic conventions when nothing framework-specific is present.
|
|
704
|
+
*
|
|
705
|
+
* classify() and transform() must agree on the chosen extractor, so both call
|
|
706
|
+
* the single `select()` method.
|
|
707
|
+
*/
|
|
708
|
+
|
|
709
|
+
declare class DispatchingTransformer implements ScopeTransformer {
|
|
710
|
+
private readonly openInference;
|
|
711
|
+
private readonly openLLMetry;
|
|
712
|
+
private readonly otelGenAi;
|
|
713
|
+
/** Choose the extractor for a span from its attribute signature. OpenInference
|
|
714
|
+
* is checked before OpenLLMetry because its markers (`llm.*`,
|
|
715
|
+
* `openinference.span.kind`) are more specific; the bare OTel GenAI
|
|
716
|
+
* transformer is the catch-all. */
|
|
717
|
+
select(attributes: Record<string, any>): ScopeTransformer;
|
|
718
|
+
classify(span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
719
|
+
transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
720
|
+
}
|
|
721
|
+
|
|
560
722
|
declare function normalizeOtlpStatusCode(raw: string | number | undefined | null): string;
|
|
561
723
|
declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: OtelSpan): NormalizedSpan;
|
|
562
724
|
/**
|
|
@@ -565,4 +727,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
|
|
|
565
727
|
*/
|
|
566
728
|
declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
|
|
567
729
|
|
|
568
|
-
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
|
|
730
|
+
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, DispatchingTransformer, type GenerateTypesLanguage, type IndexedMessageConfig, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, OpenInferenceTransformer, OpenLLMetryTransformer, type OtelEvent, OtelGenAiTransformer, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, collectIndices, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractIndexedToolCalls, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, messagesToPlainText, normalizeOtlpSpans, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, parseIndexedMessages, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
|