@cloudbase/agent-observability 1.0.1-alpha.21 → 1.0.1-alpha.24
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 +4 -4
- package/dist/{chunk-3MVJN6UI.mjs → chunk-DUKIGNZF.mjs} +24 -14
- package/dist/chunk-DUKIGNZF.mjs.map +1 -0
- package/dist/index.d.mts +23 -4
- package/dist/index.d.ts +23 -4
- package/dist/index.js +23 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -1
- package/dist/langchain.d.mts +4 -4
- package/dist/langchain.d.ts +4 -4
- package/dist/langchain.js +20 -13
- package/dist/langchain.js.map +1 -1
- package/dist/langchain.mjs +1 -1
- package/dist/langchain.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js.map +1 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +2 -2
- package/src/core/attributes.ts +14 -10
- package/src/core/constants.ts +14 -16
- package/src/core/spanWrapper.ts +1 -1
- package/src/core/tracerProvider.ts +1 -4
- package/src/index.ts +14 -2
- package/src/langchain/CallbackHandler.ts +4 -4
- package/src/server/config.ts +1 -1
- package/src/server/index.ts +1 -1
- package/src/server/setup.ts +1 -1
- package/src/types.ts +1 -1
- package/dist/chunk-3MVJN6UI.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TypeScript Observability
|
|
2
2
|
|
|
3
|
-
OpenTelemetry-based observability for
|
|
3
|
+
OpenTelemetry-based observability for the TypeScript SDK with OpenInference semantic conventions.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ This package provides a callback-based observability system that integrates with
|
|
|
20
20
|
|
|
21
21
|
```
|
|
22
22
|
┌─────────────────────────────────────────────────────────────────┐
|
|
23
|
-
│
|
|
23
|
+
│ Application │
|
|
24
24
|
├─────────────────────────────────────────────────────────────────┤
|
|
25
25
|
│ │
|
|
26
26
|
│ ┌──────────────────────────────────────────────────────────┐ │
|
|
@@ -134,7 +134,7 @@ const agent = new LangGraphAgent({ graph: workflow });
|
|
|
134
134
|
|
|
135
135
|
## Span Hierarchy Example
|
|
136
136
|
|
|
137
|
-
When using LangGraph with
|
|
137
|
+
When using LangGraph with the server:
|
|
138
138
|
|
|
139
139
|
```
|
|
140
140
|
AG-UI.Server (Request entry point)
|
|
@@ -9,38 +9,41 @@ import {
|
|
|
9
9
|
SemanticConventions,
|
|
10
10
|
OpenInferenceSpanKind
|
|
11
11
|
} from "@arizeai/openinference-semantic-conventions";
|
|
12
|
-
var OtelSpanAttributes;
|
|
12
|
+
var OBSERVABILITY_TRACER_NAME, OBSERVABILITY_SDK_NAME, OBSERVABILITY_SDK_VERSION, OtelSpanAttributes;
|
|
13
13
|
var init_constants = __esm({
|
|
14
14
|
"src/core/constants.ts"() {
|
|
15
15
|
"use strict";
|
|
16
|
+
OBSERVABILITY_TRACER_NAME = "agui-tracer";
|
|
17
|
+
OBSERVABILITY_SDK_NAME = "observability";
|
|
18
|
+
OBSERVABILITY_SDK_VERSION = "0.1.0";
|
|
16
19
|
OtelSpanAttributes = {
|
|
17
20
|
// OpenInference - re-export all standard conventions
|
|
18
21
|
...SemanticConventions,
|
|
19
|
-
//
|
|
22
|
+
// Trace attributes (non-standard)
|
|
20
23
|
TRACE_NAME: "trace.name",
|
|
21
24
|
TRACE_TAGS: "trace.tags",
|
|
22
25
|
TRACE_PUBLIC: "trace.public",
|
|
23
26
|
TRACE_METADATA: "trace.metadata",
|
|
24
27
|
TRACE_INPUT: "trace.input",
|
|
25
28
|
TRACE_OUTPUT: "trace.output",
|
|
26
|
-
//
|
|
29
|
+
// Observation attributes (non-standard)
|
|
27
30
|
OBSERVATION_TYPE: "observation.type",
|
|
28
31
|
OBSERVATION_LEVEL: "observation.level",
|
|
29
32
|
OBSERVATION_STATUS_MESSAGE: "observation.status_message",
|
|
30
33
|
OBSERVATION_INPUT: "observation.input",
|
|
31
34
|
OBSERVATION_OUTPUT: "observation.output",
|
|
32
35
|
OBSERVATION_METADATA: "observation.metadata",
|
|
33
|
-
//
|
|
36
|
+
// LLM-specific (non-standard)
|
|
34
37
|
LLM_COMPLETION_START_TIME: "llm.completion_start_time",
|
|
35
38
|
LLM_MODEL_PARAMETERS: "llm.model_parameters",
|
|
36
39
|
LLM_USAGE_DETAILS: "llm.usage_details",
|
|
37
40
|
LLM_COST_DETAILS: "llm.cost_details",
|
|
38
|
-
//
|
|
41
|
+
// Retriever-specific (non-standard)
|
|
39
42
|
RETRIEVER_NAME: "retriever.name",
|
|
40
43
|
RETRIEVER_QUERY: "retriever.query",
|
|
41
44
|
RETRIEVER_INDEX_ID: "retriever.index_id",
|
|
42
45
|
RETRIEVER_TOP_K: "retriever.top_k",
|
|
43
|
-
//
|
|
46
|
+
// General (non-standard)
|
|
44
47
|
ENVIRONMENT: "environment",
|
|
45
48
|
RELEASE: "release",
|
|
46
49
|
VERSION: "version"
|
|
@@ -94,19 +97,20 @@ function createObservationAttributes(type, attributes) {
|
|
|
94
97
|
modelParameters,
|
|
95
98
|
usageDetails
|
|
96
99
|
} = attributes;
|
|
100
|
+
const spanKind = OpenInferenceSpanKind[type.toUpperCase()] || "UNKNOWN";
|
|
97
101
|
const otelAttributes = {
|
|
98
|
-
[SemanticConventions2.OPENINFERENCE_SPAN_KIND]:
|
|
102
|
+
[SemanticConventions2.OPENINFERENCE_SPAN_KIND]: spanKind,
|
|
99
103
|
[OtelSpanAttributes.OBSERVATION_TYPE]: type,
|
|
100
104
|
[OtelSpanAttributes.OBSERVATION_LEVEL]: level,
|
|
101
105
|
[OtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]: statusMessage,
|
|
102
106
|
[OtelSpanAttributes.VERSION]: version,
|
|
103
107
|
// Use OpenInference input.value convention
|
|
104
108
|
[SemanticConventions2.INPUT_VALUE]: _serialize(input),
|
|
105
|
-
// Also set
|
|
109
|
+
// Also set observation.input for compatibility
|
|
106
110
|
[OtelSpanAttributes.OBSERVATION_INPUT]: _serialize(input),
|
|
107
111
|
// Use OpenInference output.value convention
|
|
108
112
|
[SemanticConventions2.OUTPUT_VALUE]: _serialize(output),
|
|
109
|
-
// Also set
|
|
113
|
+
// Also set observation.output for compatibility
|
|
110
114
|
[OtelSpanAttributes.OBSERVATION_OUTPUT]: _serialize(output)
|
|
111
115
|
};
|
|
112
116
|
if (type === "llm") {
|
|
@@ -398,13 +402,12 @@ function getTracer() {
|
|
|
398
402
|
OBSERVABILITY_SDK_VERSION
|
|
399
403
|
);
|
|
400
404
|
}
|
|
401
|
-
var OBSERVABILITY_GLOBAL_SYMBOL
|
|
405
|
+
var OBSERVABILITY_GLOBAL_SYMBOL;
|
|
402
406
|
var init_tracerProvider = __esm({
|
|
403
407
|
"src/core/tracerProvider.ts"() {
|
|
404
408
|
"use strict";
|
|
409
|
+
init_constants();
|
|
405
410
|
OBSERVABILITY_GLOBAL_SYMBOL = /* @__PURE__ */ Symbol.for("observability");
|
|
406
|
-
OBSERVABILITY_SDK_NAME = "ag-kit-observability";
|
|
407
|
-
OBSERVABILITY_SDK_VERSION = "0.1.0";
|
|
408
411
|
}
|
|
409
412
|
});
|
|
410
413
|
|
|
@@ -436,7 +439,7 @@ var init_spanWrapper = __esm({
|
|
|
436
439
|
);
|
|
437
440
|
}
|
|
438
441
|
}
|
|
439
|
-
/** Gets the
|
|
442
|
+
/** Gets the OpenTelemetry tracer instance */
|
|
440
443
|
get tracer() {
|
|
441
444
|
return getTracer();
|
|
442
445
|
}
|
|
@@ -595,6 +598,9 @@ var init_spanWrapper = __esm({
|
|
|
595
598
|
// src/index.ts
|
|
596
599
|
var src_exports = {};
|
|
597
600
|
__export(src_exports, {
|
|
601
|
+
OBSERVABILITY_SDK_NAME: () => OBSERVABILITY_SDK_NAME,
|
|
602
|
+
OBSERVABILITY_SDK_VERSION: () => OBSERVABILITY_SDK_VERSION,
|
|
603
|
+
OBSERVABILITY_TRACER_NAME: () => OBSERVABILITY_TRACER_NAME,
|
|
598
604
|
ObservationAgent: () => ObservationAgent,
|
|
599
605
|
ObservationChain: () => ObservationChain,
|
|
600
606
|
ObservationEmbedding: () => ObservationEmbedding,
|
|
@@ -864,10 +870,14 @@ var init_src = __esm({
|
|
|
864
870
|
init_tracerProvider();
|
|
865
871
|
init_attributes();
|
|
866
872
|
init_tracerProvider();
|
|
873
|
+
init_constants();
|
|
867
874
|
}
|
|
868
875
|
});
|
|
869
876
|
|
|
870
877
|
export {
|
|
878
|
+
OBSERVABILITY_TRACER_NAME,
|
|
879
|
+
OBSERVABILITY_SDK_NAME,
|
|
880
|
+
OBSERVABILITY_SDK_VERSION,
|
|
871
881
|
createTraceAttributes,
|
|
872
882
|
createObservationAttributes,
|
|
873
883
|
setTracerProvider,
|
|
@@ -892,4 +902,4 @@ export {
|
|
|
892
902
|
observe,
|
|
893
903
|
init_src
|
|
894
904
|
};
|
|
895
|
-
//# sourceMappingURL=chunk-
|
|
905
|
+
//# sourceMappingURL=chunk-DUKIGNZF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/constants.ts","../src/core/attributes.ts","../src/core/tracerProvider.ts","../src/core/spanWrapper.ts","../src/index.ts"],"sourcesContent":["/**\n * OTEL attribute constants for observability.\n *\n * Uses OpenInference semantic conventions where applicable:\n * https://github.com/Arize-ai/openinference/tree/main/spec\n *\n * Falls back to non-standard attributes where OpenInference\n * doesn't define a standard.\n *\n * @module\n */\n\nimport {\n SemanticConventions,\n OpenInferenceSpanKind,\n} from \"@arizeai/openinference-semantic-conventions\";\n\n// Re-export OpenInference types for convenience\nexport { OpenInferenceSpanKind };\n\n/**\n * SDK information\n */\n// Brandless defaults: avoid emitting project-specific identifiers into traces.\n// Users can still override service.name via OTEL_SERVICE_NAME.\nexport const OBSERVABILITY_TRACER_NAME = \"agui-tracer\";\nexport const OBSERVABILITY_SDK_NAME = \"observability\";\nexport const OBSERVABILITY_SDK_VERSION = \"0.1.0\";\n\n/**\n * Combined attribute namespace for internal use\n * Provides a single namespace for all OTEL attributes used internally.\n *\n * Combines OpenInference SemanticConventions with non-standard attributes\n */\nexport const OtelSpanAttributes = {\n // OpenInference - re-export all standard conventions\n ...SemanticConventions,\n\n // Trace attributes (non-standard)\n TRACE_NAME: \"trace.name\",\n TRACE_TAGS: \"trace.tags\",\n TRACE_PUBLIC: \"trace.public\",\n TRACE_METADATA: \"trace.metadata\",\n TRACE_INPUT: \"trace.input\",\n TRACE_OUTPUT: \"trace.output\",\n\n // Observation attributes (non-standard)\n OBSERVATION_TYPE: \"observation.type\",\n OBSERVATION_LEVEL: \"observation.level\",\n OBSERVATION_STATUS_MESSAGE: \"observation.status_message\",\n OBSERVATION_INPUT: \"observation.input\",\n OBSERVATION_OUTPUT: \"observation.output\",\n OBSERVATION_METADATA: \"observation.metadata\",\n\n // LLM-specific (non-standard)\n LLM_COMPLETION_START_TIME: \"llm.completion_start_time\",\n LLM_MODEL_PARAMETERS: \"llm.model_parameters\",\n LLM_USAGE_DETAILS: \"llm.usage_details\",\n LLM_COST_DETAILS: \"llm.cost_details\",\n\n // Retriever-specific (non-standard)\n RETRIEVER_NAME: \"retriever.name\",\n RETRIEVER_QUERY: \"retriever.query\",\n RETRIEVER_INDEX_ID: \"retriever.index_id\",\n RETRIEVER_TOP_K: \"retriever.top_k\",\n\n // General (non-standard)\n ENVIRONMENT: \"environment\",\n RELEASE: \"release\",\n VERSION: \"version\",\n} as const;\n\n","import { OBSERVABILITY_TRACER_NAME, OtelSpanAttributes, OpenInferenceSpanKind } from \"./constants\";\nimport { SemanticConventions } from \"@arizeai/openinference-semantic-conventions\";\nimport { ObservationAttributes, TraceAttributes, ObservationType, LLMMessage, Document, ToolCall } from \"../types\";\nimport { type Attributes } from \"@opentelemetry/api\";\n\n/**\n * Creates OpenTelemetry attributes from trace attributes.\n *\n * Converts user-friendly trace attributes into OpenTelemetry attribute format\n * using OpenInference semantic conventions where applicable.\n *\n * @param attributes - Trace attributes to convert\n * @returns OpenTelemetry attributes object\n *\n * @example\n * ```typescript\n * const otelAttributes = createTraceAttributes({\n * name: 'user-workflow',\n * userId: 'user-123',\n * sessionId: 'session-456',\n * tags: ['checkout', 'payment']\n * });\n * ```\n *\n * @public\n */\nexport function createTraceAttributes({\n name,\n userId,\n sessionId,\n version,\n release,\n input,\n output,\n metadata,\n tags,\n environment,\n public: isPublic,\n}: TraceAttributes = {}): Attributes {\n const attributes = {\n [OtelSpanAttributes.TRACE_NAME]: name,\n // Use OpenInference standard attributes for user and session\n [OtelSpanAttributes.USER_ID]: userId,\n [OtelSpanAttributes.SESSION_ID]: sessionId,\n [OtelSpanAttributes.VERSION]: version,\n [OtelSpanAttributes.RELEASE]: release,\n [OtelSpanAttributes.TRACE_INPUT]: _serialize(input),\n [OtelSpanAttributes.TRACE_OUTPUT]: _serialize(output),\n [OtelSpanAttributes.TRACE_TAGS]: tags,\n [OtelSpanAttributes.ENVIRONMENT]: environment,\n [OtelSpanAttributes.TRACE_PUBLIC]: isPublic,\n ..._flattenAndSerializeMetadata(metadata, OtelSpanAttributes.TRACE_METADATA),\n };\n\n return Object.fromEntries(\n Object.entries(attributes).filter(([_, v]) => v != null),\n );\n}\n\n/**\n * Creates OpenTelemetry attributes from observation attributes.\n *\n * Maps observation attributes to OpenInference semantic conventions:\n * - Uses `openinference.span.kind` for span type\n * - Uses `llm.*` for LLM-specific attributes\n * - Uses `tool.*` for tool-specific attributes\n * - Uses `observation.*` for non-standard attributes\n *\n * @param type - Observation type (llm, tool, chain, etc.)\n * @param attributes - Observation attributes to convert\n * @returns OpenTelemetry attributes object\n *\n * @public\n */\nexport function createObservationAttributes(\n type: ObservationType,\n attributes: ObservationAttributes,\n): Attributes {\n const {\n metadata,\n input,\n output,\n level,\n statusMessage,\n version,\n completionStartTime,\n model,\n modelParameters,\n usageDetails,\n } = attributes;\n\n // Map observation type to OpenInference span kind\n // Falls back to UNKNOWN for unknown types (consistent with Python SDK)\n const spanKind = (OpenInferenceSpanKind as Record<string, string>)[type.toUpperCase()] || \"UNKNOWN\";\n\n // Base attributes for all observation types\n const otelAttributes: Attributes = {\n [SemanticConventions.OPENINFERENCE_SPAN_KIND]: spanKind,\n [OtelSpanAttributes.OBSERVATION_TYPE]: type,\n [OtelSpanAttributes.OBSERVATION_LEVEL]: level,\n [OtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]: statusMessage,\n [OtelSpanAttributes.VERSION]: version,\n // Use OpenInference input.value convention\n [SemanticConventions.INPUT_VALUE]: _serialize(input),\n // Also set observation.input for compatibility\n [OtelSpanAttributes.OBSERVATION_INPUT]: _serialize(input),\n // Use OpenInference output.value convention\n [SemanticConventions.OUTPUT_VALUE]: _serialize(output),\n // Also set observation.output for compatibility\n [OtelSpanAttributes.OBSERVATION_OUTPUT]: _serialize(output),\n };\n\n // LLM-specific attributes\n if (type === \"llm\") {\n if (model) {\n otelAttributes[SemanticConventions.LLM_MODEL_NAME] = model;\n }\n // Extract system and provider safely\n const system = (attributes as Record<string, unknown>)?.system;\n const provider = (attributes as Record<string, unknown>)?.provider;\n const inputMessages = (attributes as Record<string, unknown>)?.inputMessages;\n const outputMessages = (attributes as Record<string, unknown>)?.outputMessages;\n const inputMimeType = (attributes as Record<string, unknown>)?.inputMimeType;\n const outputMimeType = (attributes as Record<string, unknown>)?.outputMimeType;\n\n if (system !== undefined) {\n otelAttributes[SemanticConventions.LLM_SYSTEM] = String(system);\n }\n if (provider !== undefined) {\n otelAttributes[SemanticConventions.LLM_PROVIDER] = String(provider);\n }\n if (modelParameters) {\n otelAttributes[SemanticConventions.LLM_INVOCATION_PARAMETERS] =\n _serialize(modelParameters);\n // Also set llm.model_parameters for compatibility\n otelAttributes[OtelSpanAttributes.LLM_MODEL_PARAMETERS] =\n _serialize(modelParameters);\n }\n if (usageDetails) {\n // Map to OpenInference llm.token_count.* attributes\n if (typeof usageDetails === \"object\") {\n const usage = usageDetails as Record<string, number>;\n if (usage.promptTokens !== undefined) {\n otelAttributes[SemanticConventions.LLM_TOKEN_COUNT_PROMPT] =\n usage.promptTokens;\n }\n if (usage.completionTokens !== undefined) {\n otelAttributes[SemanticConventions.LLM_TOKEN_COUNT_COMPLETION] =\n usage.completionTokens;\n }\n if (usage.totalTokens !== undefined) {\n otelAttributes[SemanticConventions.LLM_TOKEN_COUNT_TOTAL] =\n usage.totalTokens;\n }\n }\n // Also set llm.usage_details for compatibility\n otelAttributes[OtelSpanAttributes.LLM_USAGE_DETAILS] =\n _serialize(usageDetails);\n }\n if (completionStartTime) {\n otelAttributes[OtelSpanAttributes.LLM_COMPLETION_START_TIME] =\n _serialize(completionStartTime);\n }\n // Flatten LLM messages\n if (inputMessages !== undefined && Array.isArray(inputMessages)) {\n const messageAttrs = _flattenLLMMessages(inputMessages as LLMMessage[], \"llm.input_messages\");\n Object.assign(otelAttributes, messageAttrs);\n }\n if (outputMessages !== undefined && Array.isArray(outputMessages)) {\n const messageAttrs = _flattenLLMMessages(outputMessages as LLMMessage[], \"llm.output_messages\");\n Object.assign(otelAttributes, messageAttrs);\n }\n // Add MIME types\n if (inputMimeType !== undefined) {\n otelAttributes[SemanticConventions.INPUT_MIME_TYPE] = String(inputMimeType);\n }\n if (outputMimeType !== undefined) {\n otelAttributes[SemanticConventions.OUTPUT_MIME_TYPE] = String(outputMimeType);\n }\n }\n\n // Embedding-specific attributes\n if (type === \"embedding\") {\n if (model) {\n otelAttributes[SemanticConventions.EMBEDDING_MODEL_NAME] = model;\n }\n if (modelParameters) {\n otelAttributes[SemanticConventions.LLM_INVOCATION_PARAMETERS] =\n _serialize(modelParameters);\n }\n }\n\n // Tool-specific attributes\n if (type === \"tool\") {\n const toolName = (attributes as Record<string, unknown>)?.toolName ?? (attributes as Record<string, unknown>)?.tool_name;\n const toolDescription = (attributes as Record<string, unknown>)?.toolDescription;\n const toolParameters = (attributes as Record<string, unknown>)?.toolParameters;\n const toolCall = (attributes as Record<string, unknown>)?.toolCall;\n\n if (toolName !== undefined) {\n otelAttributes[SemanticConventions.TOOL_NAME] = String(toolName);\n }\n if (toolDescription !== undefined) {\n otelAttributes[SemanticConventions.TOOL_DESCRIPTION] = String(toolDescription);\n }\n if (toolParameters !== undefined) {\n otelAttributes[SemanticConventions.TOOL_PARAMETERS] = _serialize(toolParameters);\n }\n // Flatten tool call if present\n if (toolCall !== undefined && typeof toolCall === \"object\") {\n const toolCallAttrs = _flattenToolCall(toolCall as ToolCall);\n Object.assign(otelAttributes, toolCallAttrs);\n }\n }\n\n // Agent-specific attributes\n if (type === \"agent\") {\n const agentName = (attributes as Record<string, unknown>)?.agentName;\n if (agentName !== undefined) {\n otelAttributes[SemanticConventions.AGENT_NAME] = String(agentName);\n }\n }\n\n // Retriever-specific attributes\n if (type === \"retriever\") {\n const documents = (attributes as Record<string, unknown>)?.documents;\n const query = (attributes as Record<string, unknown>)?.query;\n\n if (documents !== undefined && Array.isArray(documents)) {\n const docAttrs = _flattenDocuments(documents as Document[]);\n Object.assign(otelAttributes, docAttrs);\n }\n if (query !== undefined) {\n otelAttributes[\"retriever.query\"] = String(query);\n }\n }\n\n // Add metadata (use OpenInference metadata convention)\n const metadataAttrs = _flattenAndSerializeMetadata(\n metadata,\n SemanticConventions.METADATA,\n );\n Object.assign(otelAttributes, metadataAttrs);\n\n // Also add observation.metadata for compatibility\n const obsetvabilityMetadataAttrs = _flattenAndSerializeMetadata(\n metadata,\n OtelSpanAttributes.OBSERVATION_METADATA\n );\n Object.assign(otelAttributes, obsetvabilityMetadataAttrs);\n\n // Pass through any additional custom attributes (e.g., agui.thread_id, agui.run_id)\n // Only pass through attributes that haven't been set yet to avoid overwriting internal ones\n for (const [key, value] of Object.entries(attributes)) {\n if (!(key in otelAttributes) && value !== undefined && value !== null) {\n otelAttributes[key] = typeof value === 'string' ? value : _serialize(value);\n }\n }\n\n // Filter out null/undefined values\n return Object.fromEntries(\n Object.entries(otelAttributes).filter(([_, v]) => v != null),\n );\n}\n\n/**\n * Safely serializes an object to JSON string.\n *\n * @param obj - Object to serialize\n * @returns JSON string or undefined if null/undefined\n * @internal\n */\nfunction _serialize(obj: unknown): string | undefined {\n try {\n if (typeof obj === \"string\") return obj;\n if (obj instanceof Date) return obj.toISOString();\n return obj != null ? JSON.stringify(obj) : undefined;\n } catch {\n return \"<failed to serialize>\";\n }\n}\n\n/**\n * Flattens and serializes metadata into OpenTelemetry attribute format.\n *\n * Converts nested metadata objects into dot-notation attribute keys.\n * For example, `{ database: { host: 'localhost' } }` becomes\n * `{ 'metadata.database.host': 'localhost' }` (or 'observation.metadata.database.host').\n *\n * @param metadata - Metadata object to flatten\n * @param prefix - Attribute prefix (e.g., 'metadata' or 'observation.metadata')\n * @returns Flattened metadata attributes\n * @internal\n */\nfunction _flattenAndSerializeMetadata(\n metadata: unknown,\n prefix: string,\n): Record<string, string> {\n const metadataAttributes: Record<string, string> = {};\n\n if (metadata === undefined || metadata === null) {\n return metadataAttributes;\n }\n\n if (typeof metadata !== \"object\" || Array.isArray(metadata)) {\n const serialized = _serialize(metadata);\n if (serialized) {\n metadataAttributes[prefix] = serialized;\n }\n } else {\n for (const [key, value] of Object.entries(metadata)) {\n const serialized = typeof value === \"string\" ? value : _serialize(value);\n if (serialized) {\n metadataAttributes[`${prefix}.${key}`] = serialized;\n }\n }\n }\n\n return metadataAttributes;\n}\n\n/**\n * Flattens LLM messages into OpenTelemetry attributes.\n *\n * Follows OpenInference convention:\n * - llm.input_messages.{i}.message.role\n * - llm.input_messages.{i}.message.content\n * - llm.input_messages.{i}.message.tool_calls\n *\n * @param messages - Array of LLM messages\n * @param prefix - Attribute prefix ('llm.input_messages' or 'llm.output_messages')\n * @returns Flattened message attributes\n * @internal\n */\nfunction _flattenLLMMessages(\n messages: LLMMessage[] | undefined,\n prefix: string,\n): Record<string, string> {\n const attributes: Record<string, string> = {};\n\n if (!messages || !Array.isArray(messages)) {\n return attributes;\n }\n\n try {\n messages.forEach((msg, index) => {\n if (!msg || typeof msg !== \"object\") return;\n\n const baseKey = `${prefix}.${index}.message`;\n\n if (msg.role !== undefined) {\n attributes[`${baseKey}.role`] = String(msg.role);\n }\n if (msg.content !== undefined) {\n attributes[`${baseKey}.content`] = String(msg.content);\n }\n if (msg.toolCallId !== undefined) {\n attributes[`${baseKey}.tool_call_id`] = String(msg.toolCallId);\n }\n\n // Flatten tool calls if present\n if (msg.toolCalls && Array.isArray(msg.toolCalls)) {\n msg.toolCalls.forEach((toolCall, tcIndex) => {\n if (!toolCall || typeof toolCall !== \"object\") return;\n\n const tcKey = `${baseKey}.tool_calls.${tcIndex}`;\n\n if (toolCall.id !== undefined) {\n attributes[`${tcKey}.id`] = String(toolCall.id);\n }\n if (toolCall.function !== undefined) {\n if (toolCall.function.name !== undefined) {\n attributes[`${tcKey}.function.name`] = String(toolCall.function.name);\n }\n if (toolCall.function.arguments !== undefined) {\n attributes[`${tcKey}.function.arguments`] = String(toolCall.function.arguments);\n }\n }\n });\n }\n });\n } catch (e) {\n // Silent fail - don't block business logic for observability\n }\n\n return attributes;\n}\n\n/**\n * Flattens documents into OpenTelemetry attributes.\n *\n * Follows OpenInference convention:\n * - retrieval.documents.{i}.document.id\n * - retrieval.documents.{i}.document.content\n * - retrieval.documents.{i}.document.score\n * - retrieval.documents.{i}.document.metadata\n *\n * @param documents - Array of documents\n * @returns Flattened document attributes\n * @internal\n */\nfunction _flattenDocuments(\n documents: Document[] | undefined,\n): Record<string, string> {\n const attributes: Record<string, string> = {};\n\n if (!documents || !Array.isArray(documents)) {\n return attributes;\n }\n\n try {\n documents.forEach((doc, index) => {\n if (!doc || typeof doc !== \"object\") return;\n\n const baseKey = `retrieval.documents.${index}.document`;\n\n if (doc.id !== undefined) {\n attributes[`${baseKey}.id`] = String(doc.id);\n }\n if (doc.content !== undefined) {\n attributes[`${baseKey}.content`] = String(doc.content);\n }\n if (doc.score !== undefined) {\n attributes[`${baseKey}.score`] = String(doc.score);\n }\n if (doc.metadata !== undefined && typeof doc.metadata === \"object\") {\n const metadataSerialized = _serialize(doc.metadata);\n if (metadataSerialized) {\n attributes[`${baseKey}.metadata`] = metadataSerialized;\n }\n }\n });\n } catch (e) {\n // Silent fail - don't block business logic for observability\n }\n\n return attributes;\n}\n\n/**\n * Flattens tool call into OpenTelemetry attributes.\n *\n * Follows OpenInference convention:\n * - tool_call.id\n * - tool_call.function.name\n * - tool_call.function.arguments\n *\n * @param toolCall - Tool call object\n * @returns Flattened tool call attributes\n * @internal\n */\nfunction _flattenToolCall(\n toolCall: ToolCall | undefined,\n): Record<string, string> {\n const attributes: Record<string, string> = {};\n\n if (!toolCall || typeof toolCall !== \"object\") {\n return attributes;\n }\n\n try {\n if (toolCall.id !== undefined) {\n attributes[\"tool_call.id\"] = String(toolCall.id);\n }\n if (toolCall.function !== undefined) {\n if (toolCall.function.name !== undefined) {\n attributes[\"tool_call.function.name\"] = String(toolCall.function.name);\n }\n if (toolCall.function.arguments !== undefined) {\n attributes[\"tool_call.function.arguments\"] = String(toolCall.function.arguments);\n }\n }\n } catch (e) {\n // Silent fail - don't block business logic for observability\n }\n\n return attributes;\n}\n","import { TracerProvider, trace, context } from \"@opentelemetry/api\";\nimport { OBSERVABILITY_SDK_NAME, OBSERVABILITY_SDK_VERSION } from \"./constants\";\n\nconst OBSERVABILITY_GLOBAL_SYMBOL = Symbol.for(\"observability\");\n\ntype ObservabilityGlobalState = {\n isolatedTracerProvider: TracerProvider | null;\n};\n\nfunction createState(): ObservabilityGlobalState {\n return {\n isolatedTracerProvider: null,\n };\n}\n\ninterface GlobalThis {\n [OBSERVABILITY_GLOBAL_SYMBOL]?: ObservabilityGlobalState;\n}\n\n/**\n * Gets the global state for tracing observability.\n *\n * @returns The global state object\n * @internal\n */\nfunction getObservabilityGlobalState(): ObservabilityGlobalState {\n const initialState = createState();\n\n try {\n const g = globalThis as typeof globalThis & GlobalThis;\n\n if (typeof g !== \"object\" || g === null) {\n console.warn(\n \"[Observability] globalThis is not available, using fallback state\",\n );\n return initialState;\n }\n\n if (!g[OBSERVABILITY_GLOBAL_SYMBOL]) {\n Object.defineProperty(g, OBSERVABILITY_GLOBAL_SYMBOL, {\n value: initialState,\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return g[OBSERVABILITY_GLOBAL_SYMBOL]!;\n } catch (err) {\n console.error(\n `[Observability] Failed to access global state: ${err instanceof Error ? err.message : String(err)}`,\n );\n return initialState;\n }\n}\n\n/**\n * Sets an isolated TracerProvider for tracing tracing operations.\n *\n * This allows tracing to use its own TracerProvider instance, separate from\n * the global OpenTelemetry TracerProvider.\n *\n * Note: While this isolates span processing and export, it does NOT provide\n * complete trace isolation. OpenTelemetry context (trace IDs, parent spans)\n * is still shared between the global and isolated providers.\n *\n * @param provider - The TracerProvider instance to use, or null to clear\n *\n * @example\n * ```typescript\n * import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';\n * import { setTracerProvider } from './observability';\n *\n * const provider = new NodeTracerProvider();\n * setTracerProvider(provider);\n * ```\n *\n * @public\n */\nexport function setTracerProvider(provider: TracerProvider | null) {\n getObservabilityGlobalState().isolatedTracerProvider = provider;\n}\n\n/**\n * Gets the TracerProvider for tracing tracing operations.\n *\n * Returns the isolated TracerProvider if one has been set via setTracerProvider(),\n * otherwise falls back to the global OpenTelemetry TracerProvider.\n *\n * @returns The TracerProvider instance to use for tracing tracing\n *\n * @example\n * ```typescript\n * import { getTracerProvider } from './observability';\n *\n * const provider = getTracerProvider();\n * const tracer = provider.getTracer('my-tracer', '1.0.0');\n * ```\n *\n * @public\n */\nexport function getTracerProvider(): TracerProvider {\n const { isolatedTracerProvider } = getObservabilityGlobalState();\n\n if (isolatedTracerProvider) return isolatedTracerProvider;\n\n return trace.getTracerProvider();\n}\n\n/**\n * Gets the OpenTelemetry tracer instance for tracing.\n *\n * Returns a tracer specifically configured for tracing with the correct\n * tracer name and version.\n *\n * @returns The tracing OpenTelemetry tracer instance\n *\n * @example\n * ```typescript\n * import { getTracer } from './observability';\n *\n * const tracer = getTracer();\n * const span = tracer.startSpan('my-operation');\n * ```\n *\n * @public\n */\nexport function getTracer() {\n return getTracerProvider().getTracer(\n OBSERVABILITY_SDK_NAME,\n OBSERVABILITY_SDK_VERSION\n );\n}\n","import { Span, TimeInput, SpanStatus, SpanStatusCode } from \"@opentelemetry/api\";\n\nimport { createObservationAttributes, createTraceAttributes } from \"./attributes\";\nimport { getTracer } from \"./tracerProvider\";\nimport {\n BaseSpanAttributes,\n LLMAttributes,\n TraceAttributes,\n ObservationType,\n} from \"../types\";\nimport type {\n ToolAttributes,\n AgentAttributes,\n ChainAttributes,\n RetrieverAttributes,\n RerankerAttributes,\n EvaluatorAttributes,\n GuardrailAttributes,\n EmbeddingAttributes,\n ObservationAttributes,\n} from \"../types\";\n\n/**\n * Union type representing any observation wrapper.\n *\n * @public\n */\nexport type Observation =\n | ObservationSpan\n | ObservationLLM\n | ObservationEmbedding\n | ObservationAgent\n | ObservationTool\n | ObservationChain\n | ObservationRetriever\n | ObservationReranker\n | ObservationEvaluator\n | ObservationGuardrail;\n\n/**\n * Parameters for creating an observation wrapper.\n *\n * @internal\n */\ntype ObservationParams = {\n otelSpan: Span;\n type: ObservationType;\n attributes?: BaseSpanAttributes | LLMAttributes;\n};\n\n/**\n * Base class for all observation wrappers.\n *\n * Provides common functionality for all observation types including:\n * - OpenTelemetry span integration\n * - Unique identification (span ID, trace ID)\n * - Lifecycle management (update, end)\n * - Trace context management\n * - Child observation creation\n *\n * @internal\n */\nabstract class BaseObservation {\n /** The underlying OpenTelemetry span */\n public readonly otelSpan: Span;\n /** The observation type */\n public readonly type: ObservationType;\n /** The span ID from the OpenTelemetry span context */\n public id: string;\n /** The trace ID from the OpenTelemetry span context */\n public traceId: string;\n\n constructor(params: ObservationParams) {\n this.otelSpan = params.otelSpan;\n this.id = params.otelSpan.spanContext().spanId;\n this.traceId = params.otelSpan.spanContext().traceId;\n this.type = params.type;\n\n if (params.attributes) {\n this.otelSpan.setAttributes(\n createObservationAttributes(params.type, params.attributes),\n );\n }\n }\n\n /** Gets the OpenTelemetry tracer instance */\n protected get tracer() {\n return getTracer();\n }\n\n /**\n * Ends the observation, marking it as complete.\n *\n * @param endTime - Optional end time, defaults to current time\n */\n public end(endTime?: TimeInput) {\n this.otelSpan.end(endTime);\n }\n\n /**\n * Sets the span status.\n *\n * @param status - The status to set on the span\n */\n public setStatus(status: SpanStatus) {\n this.otelSpan.setStatus(status);\n }\n\n /**\n * Sets the span status to ERROR.\n *\n * Convenience method for marking the span as failed.\n *\n * @param message - Error description message\n */\n public setErrorStatus(message: string) {\n this.otelSpan.setStatus({\n code: SpanStatusCode.ERROR,\n message,\n });\n }\n\n /**\n * Updates the OTEL span attributes.\n *\n * @param attributes - Attributes to update\n * @internal\n */\n updateOtelSpanAttributes(attributes: ObservationAttributes) {\n this.otelSpan.setAttributes(\n createObservationAttributes(this.type, attributes),\n );\n }\n\n /**\n * Updates the parent trace with new attributes.\n *\n * @param attributes - Trace attributes to set\n * @returns This observation for method chaining\n */\n public updateTrace(attributes: TraceAttributes) {\n this.otelSpan.setAttributes(createTraceAttributes(attributes));\n return this;\n }\n\n /**\n * Creates a new child observation within this observation's context.\n *\n * @param name - Name for the child observation\n * @param attributes - Type-specific attributes\n * @param options - Configuration including observation type\n * @returns Child observation instance\n */\n public startObservation(\n name: string,\n attributes: LLMAttributes,\n options: { asType: \"llm\" },\n ): ObservationLLM;\n public startObservation(\n name: string,\n attributes: EmbeddingAttributes,\n options: { asType: \"embedding\" },\n ): ObservationEmbedding;\n public startObservation(\n name: string,\n attributes: AgentAttributes,\n options: { asType: \"agent\" },\n ): ObservationAgent;\n public startObservation(\n name: string,\n attributes: ToolAttributes,\n options: { asType: \"tool\" },\n ): ObservationTool;\n public startObservation(\n name: string,\n attributes: ChainAttributes,\n options: { asType: \"chain\" },\n ): ObservationChain;\n public startObservation(\n name: string,\n attributes: RetrieverAttributes,\n options: { asType: \"retriever\" },\n ): ObservationRetriever;\n public startObservation(\n name: string,\n attributes: RerankerAttributes,\n options: { asType: \"reranker\" },\n ): ObservationReranker;\n public startObservation(\n name: string,\n attributes: EvaluatorAttributes,\n options: { asType: \"evaluator\" },\n ): ObservationEvaluator;\n public startObservation(\n name: string,\n attributes: GuardrailAttributes,\n options: { asType: \"guardrail\" },\n ): ObservationGuardrail;\n public startObservation(\n name: string,\n attributes?: BaseSpanAttributes,\n options?: { asType?: \"span\" },\n ): ObservationSpan;\n public startObservation(\n name: string,\n attributes?:\n | BaseSpanAttributes\n | LLMAttributes\n | ToolAttributes\n | AgentAttributes\n | ChainAttributes\n | RetrieverAttributes\n | RerankerAttributes\n | EvaluatorAttributes\n | GuardrailAttributes\n | EmbeddingAttributes,\n options?: { asType?: ObservationType },\n ): Observation {\n // Import here to avoid circular dependency\n const { startObservation: startObs } = require(\"../index\");\n const { asType = \"span\" } = options || {};\n\n return startObs(name, attributes, {\n asType: asType as \"span\",\n parentSpanContext: this.otelSpan.spanContext(),\n });\n }\n}\n\n// Type-specific observation classes\n\ntype ObservationSpanParams = {\n otelSpan: Span;\n attributes?: BaseSpanAttributes;\n};\n\n/**\n * General-purpose observation for tracking operations.\n *\n * @public\n */\nexport class ObservationSpan extends BaseObservation {\n constructor(params: ObservationSpanParams) {\n super({ ...params, type: \"span\" });\n }\n\n public update(attributes: BaseSpanAttributes): ObservationSpan {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationLLMParams = {\n otelSpan: Span;\n attributes?: LLMAttributes;\n};\n\n/**\n * LLM observation for tracking language model calls.\n *\n * @public\n */\nexport class ObservationLLM extends BaseObservation {\n constructor(params: ObservationLLMParams) {\n super({ ...params, type: \"llm\" });\n }\n\n public update(attributes: LLMAttributes): ObservationLLM {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationEmbeddingParams = {\n otelSpan: Span;\n attributes?: EmbeddingAttributes;\n};\n\n/**\n * Embedding observation for tracking embedding operations.\n *\n * @public\n */\nexport class ObservationEmbedding extends BaseObservation {\n constructor(params: ObservationEmbeddingParams) {\n super({ ...params, type: \"embedding\" });\n }\n\n public update(attributes: EmbeddingAttributes): ObservationEmbedding {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationAgentParams = {\n otelSpan: Span;\n attributes?: AgentAttributes;\n};\n\n/**\n * Agent observation for tracking AI agent workflows.\n *\n * @public\n */\nexport class ObservationAgent extends BaseObservation {\n constructor(params: ObservationAgentParams) {\n super({ ...params, type: \"agent\" });\n }\n\n public update(attributes: AgentAttributes): ObservationAgent {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationToolParams = {\n otelSpan: Span;\n attributes?: ToolAttributes;\n};\n\n/**\n * Tool observation for tracking tool calls.\n *\n * @public\n */\nexport class ObservationTool extends BaseObservation {\n constructor(params: ObservationToolParams) {\n super({ ...params, type: \"tool\" });\n }\n\n public update(attributes: ToolAttributes): ObservationTool {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationChainParams = {\n otelSpan: Span;\n attributes?: ChainAttributes;\n};\n\n/**\n * Chain observation for tracking multi-step workflows.\n *\n * @public\n */\nexport class ObservationChain extends BaseObservation {\n constructor(params: ObservationChainParams) {\n super({ ...params, type: \"chain\" });\n }\n\n public update(attributes: ChainAttributes): ObservationChain {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationRetrieverParams = {\n otelSpan: Span;\n attributes?: RetrieverAttributes;\n};\n\n/**\n * Retriever observation for tracking document retrieval.\n *\n * @public\n */\nexport class ObservationRetriever extends BaseObservation {\n constructor(params: ObservationRetrieverParams) {\n super({ ...params, type: \"retriever\" });\n }\n\n public update(attributes: RetrieverAttributes): ObservationRetriever {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationRerankerParams = {\n otelSpan: Span;\n attributes?: RerankerAttributes;\n};\n\n/**\n * Reranker observation for tracking reranking operations.\n *\n * @public\n */\nexport class ObservationReranker extends BaseObservation {\n constructor(params: ObservationRerankerParams) {\n super({ ...params, type: \"reranker\" });\n }\n\n public update(attributes: RerankerAttributes): ObservationReranker {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationEvaluatorParams = {\n otelSpan: Span;\n attributes?: EvaluatorAttributes;\n};\n\n/**\n * Evaluator observation for tracking evaluation operations.\n *\n * @public\n */\nexport class ObservationEvaluator extends BaseObservation {\n constructor(params: ObservationEvaluatorParams) {\n super({ ...params, type: \"evaluator\" });\n }\n\n public update(attributes: EvaluatorAttributes): ObservationEvaluator {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n\ntype ObservationGuardrailParams = {\n otelSpan: Span;\n attributes?: GuardrailAttributes;\n};\n\n/**\n * Guardrail observation for tracking safety checks.\n *\n * @public\n */\nexport class ObservationGuardrail extends BaseObservation {\n constructor(params: ObservationGuardrailParams) {\n super({ ...params, type: \"guardrail\" });\n }\n\n public update(attributes: GuardrailAttributes): ObservationGuardrail {\n super.updateOtelSpanAttributes(attributes);\n return this;\n }\n}\n","/**\n * Observability - OpenTelemetry-based tracing with OpenInference semantic conventions\n *\n * @packageDocumentation\n */\n\nimport { trace, context, TimeInput, SpanStatusCode, Span, SpanContext } from \"@opentelemetry/api\";\n\nimport {\n createObservationAttributes,\n createTraceAttributes,\n} from \"./core/attributes\";\nimport {\n ObservationSpan,\n ObservationLLM,\n ObservationEmbedding,\n ObservationAgent,\n ObservationTool,\n ObservationChain,\n ObservationRetriever,\n ObservationReranker,\n ObservationEvaluator,\n ObservationGuardrail,\n type Observation,\n} from \"./core/spanWrapper\";\nimport { getTracer } from \"./core/tracerProvider\";\nimport {\n OBSERVABILITY_TRACER_NAME,\n OBSERVABILITY_SDK_NAME,\n OBSERVABILITY_SDK_VERSION,\n} from \"./core/constants\";\nimport {\n ObservationType,\n ObservationLevel,\n BaseSpanAttributes,\n LLMAttributes,\n ToolAttributes,\n AgentAttributes,\n ChainAttributes,\n RetrieverAttributes,\n RerankerAttributes,\n EvaluatorAttributes,\n GuardrailAttributes,\n EmbeddingAttributes,\n ObservationAttributes,\n TraceAttributes,\n LLMMessage,\n ToolCall,\n Document,\n} from \"./types\";\n\n// Export types\nexport type {\n ObservationType,\n ObservationLevel,\n BaseSpanAttributes,\n LLMAttributes,\n ToolAttributes,\n AgentAttributes,\n ChainAttributes,\n RetrieverAttributes,\n RerankerAttributes,\n EvaluatorAttributes,\n GuardrailAttributes,\n EmbeddingAttributes,\n ObservationAttributes,\n TraceAttributes,\n LLMMessage,\n ToolCall,\n Document,\n};\n\n// Export observation classes\nexport {\n ObservationSpan,\n ObservationLLM,\n ObservationEmbedding,\n ObservationAgent,\n ObservationTool,\n ObservationChain,\n ObservationRetriever,\n ObservationReranker,\n ObservationEvaluator,\n ObservationGuardrail,\n};\n\n// Export observation union type\nexport type { Observation };\n\n// Export core functions\nexport {\n createTraceAttributes,\n createObservationAttributes,\n} from \"./core/attributes\";\nexport {\n setTracerProvider,\n getTracerProvider,\n getTracer,\n} from \"./core/tracerProvider\";\n\n// Export constants\nexport {\n OBSERVABILITY_TRACER_NAME,\n OBSERVABILITY_SDK_NAME,\n OBSERVABILITY_SDK_VERSION,\n} from \"./core/constants\";\n\n/**\n * Options for starting observations (spans).\n *\n * @public\n */\nexport type StartObservationOptions = {\n /** Custom start time for the observation */\n startTime?: Date;\n /** Parent span context to attach this observation to */\n parentSpanContext?: SpanContext;\n};\n\n/**\n * Options for startObservation function.\n *\n * @public\n */\nexport type StartObservationOpts = StartObservationOptions & {\n /** Type of observation to create. Defaults to 'span' */\n asType?: ObservationType;\n};\n\n/**\n * Creates an OpenTelemetry span with the tracer.\n *\n * @param params - Parameters for span creation\n * @returns The created OpenTelemetry span\n * @internal\n */\nfunction createOtelSpan(params: {\n name: string;\n startTime?: TimeInput;\n parentSpanContext?: SpanContext;\n}): Span {\n return getTracer().startSpan(\n params.name,\n { startTime: params.startTime },\n createParentContext(params.parentSpanContext),\n );\n}\n\n/**\n * Creates a parent context from a span context.\n *\n * @param parentSpanContext - The span context to use as parent\n * @returns The created context or undefined if no parent provided\n * @internal\n */\nfunction createParentContext(\n parentSpanContext?: SpanContext,\n): ReturnType<typeof trace.setSpanContext> | undefined {\n if (!parentSpanContext) return;\n return trace.setSpanContext(context.active(), parentSpanContext);\n}\n\n// Function overloads for proper type inference\n// Generic overload for dynamic asType (returns Observation union)\nexport function startObservation(\n name: string,\n attributes?: BaseSpanAttributes,\n options?: StartObservationOpts & { asType?: ObservationType },\n): Observation;\n\n// Type-specific overloads for precise type inference\nexport function startObservation(\n name: string,\n attributes: LLMAttributes,\n options: StartObservationOpts & { asType: \"llm\" },\n): ObservationLLM;\nexport function startObservation(\n name: string,\n attributes: EmbeddingAttributes,\n options: StartObservationOpts & { asType: \"embedding\" },\n): ObservationEmbedding;\nexport function startObservation(\n name: string,\n attributes: AgentAttributes,\n options: StartObservationOpts & { asType: \"agent\" },\n): ObservationAgent;\nexport function startObservation(\n name: string,\n attributes: ToolAttributes,\n options: StartObservationOpts & { asType: \"tool\" },\n): ObservationTool;\nexport function startObservation(\n name: string,\n attributes: ChainAttributes,\n options: StartObservationOpts & { asType: \"chain\" },\n): ObservationChain;\nexport function startObservation(\n name: string,\n attributes: RetrieverAttributes,\n options: StartObservationOpts & { asType: \"retriever\" },\n): ObservationRetriever;\nexport function startObservation(\n name: string,\n attributes: RerankerAttributes,\n options: StartObservationOpts & { asType: \"reranker\" },\n): ObservationReranker;\nexport function startObservation(\n name: string,\n attributes: EvaluatorAttributes,\n options: StartObservationOpts & { asType: \"evaluator\" },\n): ObservationEvaluator;\nexport function startObservation(\n name: string,\n attributes: GuardrailAttributes,\n options: StartObservationOpts & { asType: \"guardrail\" },\n): ObservationGuardrail;\nexport function startObservation(\n name: string,\n attributes?: BaseSpanAttributes,\n options?: StartObservationOpts & { asType?: \"span\" },\n): ObservationSpan;\n\n/**\n * Creates and starts a new observation.\n *\n * Supports multiple observation types with full TypeScript type safety:\n * - **span**: General-purpose operations (default)\n * - **llm**: LLM calls and AI model interactions\n * - **embedding**: Text embedding and vector operations\n * - **agent**: AI agent workflows\n * - **tool**: Individual tool calls\n * - **chain**: Multi-step processes\n * - **retriever**: Document retrieval\n * - **reranker**: Result reranking\n * - **evaluator**: Quality assessment\n * - **guardrail**: Safety checks\n *\n * @param name - Descriptive name for the observation\n * @param attributes - Type-specific attributes\n * @param options - Configuration options\n * @returns Strongly-typed observation object\n *\n * @example\n * ```typescript\n * import { startObservation } from './observability';\n *\n * // LLM observation\n * const llm = startObservation('openai-gpt-4', {\n * input: [{ role: 'user', content: 'Hello' }],\n * model: 'gpt-4',\n * modelParameters: { temperature: 0.7 }\n * }, { asType: 'llm' });\n *\n * // Tool observation\n * const tool = startObservation('weather-api', {\n * input: { location: 'SF' }\n * }, { asType: 'tool' });\n *\n * // Chain observation\n * const chain = startObservation('rag-pipeline', {\n * input: { question: 'What is AI?' }\n * }, { asType: 'chain' });\n * ```\n *\n * @public\n */\nexport function startObservation(\n name: string,\n attributes?:\n | BaseSpanAttributes\n | LLMAttributes\n | EmbeddingAttributes\n | AgentAttributes\n | ToolAttributes\n | ChainAttributes\n | RetrieverAttributes\n | RerankerAttributes\n | EvaluatorAttributes\n | GuardrailAttributes,\n options?: StartObservationOpts,\n): Observation {\n const { asType = \"span\", ...observationOptions } = options || {};\n\n const otelSpan = createOtelSpan({\n name,\n ...observationOptions,\n });\n\n switch (asType) {\n case \"llm\":\n return new ObservationLLM({\n otelSpan,\n attributes: attributes as LLMAttributes,\n });\n\n case \"embedding\":\n return new ObservationEmbedding({\n otelSpan,\n attributes: attributes as EmbeddingAttributes,\n });\n\n case \"agent\":\n return new ObservationAgent({\n otelSpan,\n attributes: attributes as AgentAttributes,\n });\n\n case \"tool\":\n return new ObservationTool({\n otelSpan,\n attributes: attributes as ToolAttributes,\n });\n\n case \"chain\":\n return new ObservationChain({\n otelSpan,\n attributes: attributes as ChainAttributes,\n });\n\n case \"retriever\":\n return new ObservationRetriever({\n otelSpan,\n attributes: attributes as RetrieverAttributes,\n });\n\n case \"reranker\":\n return new ObservationReranker({\n otelSpan,\n attributes: attributes as RerankerAttributes,\n });\n\n case \"evaluator\":\n return new ObservationEvaluator({\n otelSpan,\n attributes: attributes as EvaluatorAttributes,\n });\n\n case \"guardrail\":\n return new ObservationGuardrail({\n otelSpan,\n attributes: attributes as GuardrailAttributes,\n });\n\n case \"span\":\n default:\n return new ObservationSpan({\n otelSpan,\n attributes: attributes as BaseSpanAttributes,\n });\n }\n}\n\n/**\n * Updates the currently active trace with new attributes.\n *\n * @param attributes - Trace attributes to set\n *\n * @example\n * ```typescript\n * import { updateActiveTrace } from './observability';\n *\n * updateActiveTrace({\n * name: 'user-workflow',\n * userId: 'user-123',\n * tags: ['production']\n * });\n * ```\n *\n * @public\n */\nexport function updateActiveTrace(attributes: TraceAttributes) {\n const span = trace.getActiveSpan();\n\n if (!span) {\n console.warn(\n \"[Observability] No active OTEL span in context. Skipping trace update.\",\n );\n return;\n }\n\n span.setAttributes(createTraceAttributes(attributes));\n}\n\n/**\n * Gets the current active trace ID.\n *\n * @returns The trace ID of the currently active span, or undefined\n *\n * @public\n */\nexport function getActiveTraceId(): string | undefined {\n return trace.getActiveSpan()?.spanContext().traceId;\n}\n\n/**\n * Gets the current active observation ID.\n *\n * @returns The span ID of the currently active span, or undefined\n *\n * @public\n */\nexport function getActiveSpanId(): string | undefined {\n return trace.getActiveSpan()?.spanContext().spanId;\n}\n\n// ============================================================================\n// Active Observation Functions\n// ============================================================================\n\n/**\n * Options for startActiveObservation.\n *\n * @public\n */\nexport type StartActiveObservationOpts = StartObservationOpts & {\n /** Whether to automatically end the observation when the function exits. Default: true */\n endOnExit?: boolean;\n};\n\n/**\n * Wraps a Promise to automatically end the span when it resolves/rejects.\n *\n * @param promise - The promise to wrap\n * @param span - The OpenTelemetry span\n * @param endOnExit - Whether to end the span on exit\n * @returns The wrapped promise\n * @internal\n */\nfunction wrapPromise<T>(\n promise: Promise<T>,\n span: Span,\n endOnExit: boolean | undefined,\n): Promise<T> {\n return promise.then(\n (value) => {\n if (endOnExit !== false) {\n span.end();\n }\n return value;\n },\n (err: unknown) => {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err instanceof Error ? err.message : \"Unknown error\",\n });\n if (endOnExit !== false) {\n span.end();\n }\n throw err;\n },\n );\n}\n\n// Function overloads for startActiveObservation\nexport function startActiveObservation<\n F extends (observation: ObservationSpan) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationLLM) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationEmbedding) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationAgent) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationTool) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationChain) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationRetriever) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationReranker) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationEvaluator) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\nexport function startActiveObservation<\n F extends (observation: ObservationGuardrail) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;\n\n/**\n * Creates an observation with automatic lifecycle management.\n *\n * This function creates an observation and executes a function with that observation\n * as a parameter. The observation is automatically ended when the function completes\n * (unless `endOnExit` is set to `false`).\n *\n * Supports both synchronous and asynchronous functions, with automatic error handling.\n *\n * @param name - Descriptive name for the observation\n * @param fn - Function to execute with the observation\n * @param options - Configuration options\n * @returns The result of the function\n *\n * @example\n * ```typescript\n * import { startActiveObservation } from './observability';\n *\n * // Synchronous function\n * const result = startActiveObservation('data-processing', (span) => {\n * span.update({ input: { data: [1, 2, 3] } });\n * const processed = data.map(x => x * 2);\n * span.update({ output: { result: processed } });\n * return processed;\n * }, { asType: 'span' });\n *\n * // Asynchronous function\n * const embeddings = await startActiveObservation(\n * 'text-embeddings',\n * async (embedding) => {\n * embedding.update({\n * input: { texts: ['Hello', 'World'] },\n * model: 'text-embedding-ada-002'\n * });\n *\n * const vectors = await generateEmbeddings(texts);\n *\n * embedding.update({ output: { embeddings: vectors } });\n * return vectors;\n * },\n * { asType: 'embedding' }\n * );\n *\n * // Disable automatic ending (for long-running operations)\n * startActiveObservation(\n * 'background-task',\n * (span) => {\n * span.update({ input: { taskId: '123' } });\n * startBackgroundProcess(span);\n * return 'started';\n * },\n * { asType: 'span', endOnExit: false }\n * );\n * ```\n *\n * @see {@link startObservation} for manual observation lifecycle management\n * @see {@link observe} for decorator-style function wrapping\n *\n * @public\n */\nexport function startActiveObservation<\n F extends (observation: Observation) => unknown,\n>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F> {\n const { asType = \"span\", endOnExit, ...observationOptions } = options || {};\n\n return getTracer().startActiveSpan(\n name,\n { startTime: observationOptions?.startTime },\n createParentContext(observationOptions?.parentSpanContext) ??\n context.active(),\n (span) => {\n try {\n let observation: Observation;\n\n switch (asType) {\n case \"llm\":\n observation = new ObservationLLM({ otelSpan: span });\n break;\n case \"embedding\":\n observation = new ObservationEmbedding({ otelSpan: span });\n break;\n case \"agent\":\n observation = new ObservationAgent({ otelSpan: span });\n break;\n case \"tool\":\n observation = new ObservationTool({ otelSpan: span });\n break;\n case \"chain\":\n observation = new ObservationChain({ otelSpan: span });\n break;\n case \"retriever\":\n observation = new ObservationRetriever({ otelSpan: span });\n break;\n case \"reranker\":\n observation = new ObservationReranker({ otelSpan: span });\n break;\n case \"evaluator\":\n observation = new ObservationEvaluator({ otelSpan: span });\n break;\n case \"guardrail\":\n observation = new ObservationGuardrail({ otelSpan: span });\n break;\n case \"span\":\n default:\n observation = new ObservationSpan({ otelSpan: span });\n }\n\n const result = fn(observation as Parameters<F>[0]);\n\n if (result instanceof Promise) {\n return wrapPromise(\n result,\n span,\n endOnExit,\n ) as ReturnType<F>;\n } else {\n if (endOnExit !== false) {\n span.end();\n }\n return result as ReturnType<F>;\n }\n } catch (err) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err instanceof Error ? err.message : \"Unknown error\",\n });\n if (endOnExit !== false) {\n span.end();\n }\n throw err;\n }\n },\n );\n}\n\n/**\n * Updates the currently active observation with new attributes.\n *\n * @param attributes - Observation attributes to set\n *\n * @example\n * ```typescript\n * import { updateActiveObservation } from './observability';\n *\n * // Within an active observation context\n * updateActiveObservation({\n * metadata: { stage: 'processing' }\n * });\n * ```\n *\n * @public\n */\nexport function updateActiveObservation(\n attributes: BaseSpanAttributes,\n): void {\n const span = trace.getActiveSpan();\n\n if (!span) {\n console.warn(\n \"[Observability] No active OTEL span in context. Skipping observation update.\",\n );\n return;\n }\n\n span.setAttributes(createObservationAttributes(\"span\", attributes));\n}\n\n// ============================================================================\n// Decorator Function\n// ============================================================================\n\n/**\n * Options for the observe decorator.\n *\n * @public\n */\nexport type ObserveOptions = Omit<StartObservationOpts, \"name\"> & {\n /** Whether to capture function arguments as input. Default: true */\n captureInput?: boolean;\n /** Whether to capture return value as output. Default: true */\n captureOutput?: boolean;\n};\n\n/**\n * Captures function arguments for observability input.\n *\n * @param args - Function arguments to capture\n * @returns Serialized arguments\n * @internal\n */\nfunction _captureArguments(args: unknown[]): Record<string, unknown> {\n if (args.length === 0) return {};\n if (args.length === 1) return { arg: args[0] };\n return { args };\n}\n\n/**\n * Decorator function to add observability to any function.\n *\n * Wraps a function with automatic observation creation, input/output capture,\n * and lifecycle management. The observation is automatically ended when the\n * function completes.\n *\n * @param fn - Function to wrap\n * @param options - Configuration options\n * @returns Wrapped function with observability\n *\n * @example\n * ```typescript\n * import { observe } from './observability';\n *\n * // Wrap an existing function\n * const fetchData = observe(async (url: string) => {\n * const response = await fetch(url);\n * return response.json();\n * }, { asType: 'tool' });\n *\n * // Wrap with custom name\n * const processPayment = observe(\n * async (amount: number, currency: string) => {\n * return await paymentGateway.charge(amount, currency);\n * },\n * { name: 'payment-gateway-call', asType: 'tool' }\n * );\n *\n * // Class method decoration\n * class UserService {\n * @observe({ asType: 'chain' })\n * async getUser(id: string) {\n * return await db.users.find(id);\n * }\n * }\n * ```\n *\n * @public\n */\nexport function observe<T extends (...args: any[]) => any>(\n fn: T,\n options: ObserveOptions = {},\n): T {\n const {\n asType = \"span\",\n captureInput = true,\n captureOutput = true,\n ...observationOptions\n } = options;\n\n const wrappedFunction = function (\n this: any,\n ...args: Parameters<T>\n ): ReturnType<T> {\n const name = fn.name || \"anonymous-function\";\n\n // Prepare input data\n const inputData = captureInput ? _captureArguments(args) : undefined;\n\n // Create the observation\n const observation = startObservation(\n name,\n inputData ? { input: inputData } : {},\n {\n ...observationOptions,\n asType: asType as \"span\",\n },\n );\n\n // Set the observation span as active in the context\n const activeContext = trace.setSpan(context.active(), observation.otelSpan);\n\n // Execute the function within the observation context\n const result = context.with(activeContext, () => fn.apply(this, args));\n\n // Handle promises\n if (result instanceof Promise) {\n return result.then(\n (value) => {\n if (captureOutput) {\n observation.update({ output: value });\n }\n observation.end();\n return value;\n },\n (err: unknown) => {\n observation.update({\n level: \"ERROR\",\n statusMessage: err instanceof Error ? err.message : \"Unknown error\",\n });\n observation.end();\n throw err;\n },\n ) as ReturnType<T>;\n }\n\n // Handle synchronous functions\n if (captureOutput) {\n observation.update({ output: result });\n }\n observation.end();\n\n return result as ReturnType<T>;\n };\n\n // Preserve function properties\n Object.defineProperty(wrappedFunction, \"name\", { value: fn.name });\n Object.defineProperty(wrappedFunction, \"length\", { value: fn.length });\n\n return wrappedFunction as T;\n}\n"],"mappings":";;;;;;;AAYA;AAA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AIA;AAOA;AAAA;AAAA;","names":["SemanticConventions","trace","context","SpanStatusCode"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _opentelemetry_api from '@opentelemetry/api';
|
|
|
2
2
|
import { Span, TimeInput, SpanStatus, Attributes, TracerProvider, SpanContext } from '@opentelemetry/api';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Types of observations (spans) supported by
|
|
5
|
+
* Types of observations (spans) supported by observability.
|
|
6
6
|
*
|
|
7
7
|
* These types align with OpenInference semantic conventions:
|
|
8
8
|
* https://github.com/Arize-ai/openinference/tree/main/spec
|
|
@@ -347,7 +347,7 @@ declare abstract class BaseObservation {
|
|
|
347
347
|
/** The trace ID from the OpenTelemetry span context */
|
|
348
348
|
traceId: string;
|
|
349
349
|
constructor(params: ObservationParams);
|
|
350
|
-
/** Gets the
|
|
350
|
+
/** Gets the OpenTelemetry tracer instance */
|
|
351
351
|
protected get tracer(): _opentelemetry_api.Tracer;
|
|
352
352
|
/**
|
|
353
353
|
* Ends the observation, marking it as complete.
|
|
@@ -582,7 +582,7 @@ declare function createTraceAttributes({ name, userId, sessionId, version, relea
|
|
|
582
582
|
* - Uses `openinference.span.kind` for span type
|
|
583
583
|
* - Uses `llm.*` for LLM-specific attributes
|
|
584
584
|
* - Uses `tool.*` for tool-specific attributes
|
|
585
|
-
* -
|
|
585
|
+
* - Uses `observation.*` for non-standard attributes
|
|
586
586
|
*
|
|
587
587
|
* @param type - Observation type (llm, tool, chain, etc.)
|
|
588
588
|
* @param attributes - Observation attributes to convert
|
|
@@ -655,6 +655,25 @@ declare function getTracerProvider(): TracerProvider;
|
|
|
655
655
|
*/
|
|
656
656
|
declare function getTracer(): _opentelemetry_api.Tracer;
|
|
657
657
|
|
|
658
|
+
/**
|
|
659
|
+
* OTEL attribute constants for observability.
|
|
660
|
+
*
|
|
661
|
+
* Uses OpenInference semantic conventions where applicable:
|
|
662
|
+
* https://github.com/Arize-ai/openinference/tree/main/spec
|
|
663
|
+
*
|
|
664
|
+
* Falls back to non-standard attributes where OpenInference
|
|
665
|
+
* doesn't define a standard.
|
|
666
|
+
*
|
|
667
|
+
* @module
|
|
668
|
+
*/
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* SDK information
|
|
672
|
+
*/
|
|
673
|
+
declare const OBSERVABILITY_TRACER_NAME = "agui-tracer";
|
|
674
|
+
declare const OBSERVABILITY_SDK_NAME = "observability";
|
|
675
|
+
declare const OBSERVABILITY_SDK_VERSION = "0.1.0";
|
|
676
|
+
|
|
658
677
|
/**
|
|
659
678
|
* Observability - OpenTelemetry-based tracing with OpenInference semantic conventions
|
|
660
679
|
*
|
|
@@ -839,4 +858,4 @@ type ObserveOptions = Omit<StartObservationOpts, "name"> & {
|
|
|
839
858
|
*/
|
|
840
859
|
declare function observe<T extends (...args: any[]) => any>(fn: T, options?: ObserveOptions): T;
|
|
841
860
|
|
|
842
|
-
export { type AgentAttributes, type BaseSpanAttributes, type ChainAttributes, type Document, type EmbeddingAttributes, type EvaluatorAttributes, type GuardrailAttributes, type LLMAttributes, type LLMMessage, type Observation, ObservationAgent, type ObservationAttributes, ObservationChain, ObservationEmbedding, ObservationEvaluator, ObservationGuardrail, ObservationLLM, type ObservationLevel, ObservationReranker, ObservationRetriever, ObservationSpan, ObservationTool, type ObservationType, type ObserveOptions, type RerankerAttributes, type RetrieverAttributes, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, type ToolAttributes, type ToolCall, type TraceAttributes, createObservationAttributes, createTraceAttributes, getActiveSpanId, getActiveTraceId, getTracer, getTracerProvider, observe, setTracerProvider, startActiveObservation, startObservation, updateActiveObservation, updateActiveTrace };
|
|
861
|
+
export { type AgentAttributes, type BaseSpanAttributes, type ChainAttributes, type Document, type EmbeddingAttributes, type EvaluatorAttributes, type GuardrailAttributes, type LLMAttributes, type LLMMessage, OBSERVABILITY_SDK_NAME, OBSERVABILITY_SDK_VERSION, OBSERVABILITY_TRACER_NAME, type Observation, ObservationAgent, type ObservationAttributes, ObservationChain, ObservationEmbedding, ObservationEvaluator, ObservationGuardrail, ObservationLLM, type ObservationLevel, ObservationReranker, ObservationRetriever, ObservationSpan, ObservationTool, type ObservationType, type ObserveOptions, type RerankerAttributes, type RetrieverAttributes, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, type ToolAttributes, type ToolCall, type TraceAttributes, createObservationAttributes, createTraceAttributes, getActiveSpanId, getActiveTraceId, getTracer, getTracerProvider, observe, setTracerProvider, startActiveObservation, startObservation, updateActiveObservation, updateActiveTrace };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _opentelemetry_api from '@opentelemetry/api';
|
|
|
2
2
|
import { Span, TimeInput, SpanStatus, Attributes, TracerProvider, SpanContext } from '@opentelemetry/api';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Types of observations (spans) supported by
|
|
5
|
+
* Types of observations (spans) supported by observability.
|
|
6
6
|
*
|
|
7
7
|
* These types align with OpenInference semantic conventions:
|
|
8
8
|
* https://github.com/Arize-ai/openinference/tree/main/spec
|
|
@@ -347,7 +347,7 @@ declare abstract class BaseObservation {
|
|
|
347
347
|
/** The trace ID from the OpenTelemetry span context */
|
|
348
348
|
traceId: string;
|
|
349
349
|
constructor(params: ObservationParams);
|
|
350
|
-
/** Gets the
|
|
350
|
+
/** Gets the OpenTelemetry tracer instance */
|
|
351
351
|
protected get tracer(): _opentelemetry_api.Tracer;
|
|
352
352
|
/**
|
|
353
353
|
* Ends the observation, marking it as complete.
|
|
@@ -582,7 +582,7 @@ declare function createTraceAttributes({ name, userId, sessionId, version, relea
|
|
|
582
582
|
* - Uses `openinference.span.kind` for span type
|
|
583
583
|
* - Uses `llm.*` for LLM-specific attributes
|
|
584
584
|
* - Uses `tool.*` for tool-specific attributes
|
|
585
|
-
* -
|
|
585
|
+
* - Uses `observation.*` for non-standard attributes
|
|
586
586
|
*
|
|
587
587
|
* @param type - Observation type (llm, tool, chain, etc.)
|
|
588
588
|
* @param attributes - Observation attributes to convert
|
|
@@ -655,6 +655,25 @@ declare function getTracerProvider(): TracerProvider;
|
|
|
655
655
|
*/
|
|
656
656
|
declare function getTracer(): _opentelemetry_api.Tracer;
|
|
657
657
|
|
|
658
|
+
/**
|
|
659
|
+
* OTEL attribute constants for observability.
|
|
660
|
+
*
|
|
661
|
+
* Uses OpenInference semantic conventions where applicable:
|
|
662
|
+
* https://github.com/Arize-ai/openinference/tree/main/spec
|
|
663
|
+
*
|
|
664
|
+
* Falls back to non-standard attributes where OpenInference
|
|
665
|
+
* doesn't define a standard.
|
|
666
|
+
*
|
|
667
|
+
* @module
|
|
668
|
+
*/
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* SDK information
|
|
672
|
+
*/
|
|
673
|
+
declare const OBSERVABILITY_TRACER_NAME = "agui-tracer";
|
|
674
|
+
declare const OBSERVABILITY_SDK_NAME = "observability";
|
|
675
|
+
declare const OBSERVABILITY_SDK_VERSION = "0.1.0";
|
|
676
|
+
|
|
658
677
|
/**
|
|
659
678
|
* Observability - OpenTelemetry-based tracing with OpenInference semantic conventions
|
|
660
679
|
*
|
|
@@ -839,4 +858,4 @@ type ObserveOptions = Omit<StartObservationOpts, "name"> & {
|
|
|
839
858
|
*/
|
|
840
859
|
declare function observe<T extends (...args: any[]) => any>(fn: T, options?: ObserveOptions): T;
|
|
841
860
|
|
|
842
|
-
export { type AgentAttributes, type BaseSpanAttributes, type ChainAttributes, type Document, type EmbeddingAttributes, type EvaluatorAttributes, type GuardrailAttributes, type LLMAttributes, type LLMMessage, type Observation, ObservationAgent, type ObservationAttributes, ObservationChain, ObservationEmbedding, ObservationEvaluator, ObservationGuardrail, ObservationLLM, type ObservationLevel, ObservationReranker, ObservationRetriever, ObservationSpan, ObservationTool, type ObservationType, type ObserveOptions, type RerankerAttributes, type RetrieverAttributes, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, type ToolAttributes, type ToolCall, type TraceAttributes, createObservationAttributes, createTraceAttributes, getActiveSpanId, getActiveTraceId, getTracer, getTracerProvider, observe, setTracerProvider, startActiveObservation, startObservation, updateActiveObservation, updateActiveTrace };
|
|
861
|
+
export { type AgentAttributes, type BaseSpanAttributes, type ChainAttributes, type Document, type EmbeddingAttributes, type EvaluatorAttributes, type GuardrailAttributes, type LLMAttributes, type LLMMessage, OBSERVABILITY_SDK_NAME, OBSERVABILITY_SDK_VERSION, OBSERVABILITY_TRACER_NAME, type Observation, ObservationAgent, type ObservationAttributes, ObservationChain, ObservationEmbedding, ObservationEvaluator, ObservationGuardrail, ObservationLLM, type ObservationLevel, ObservationReranker, ObservationRetriever, ObservationSpan, ObservationTool, type ObservationType, type ObserveOptions, type RerankerAttributes, type RetrieverAttributes, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, type ToolAttributes, type ToolCall, type TraceAttributes, createObservationAttributes, createTraceAttributes, getActiveSpanId, getActiveTraceId, getTracer, getTracerProvider, observe, setTracerProvider, startActiveObservation, startObservation, updateActiveObservation, updateActiveTrace };
|
package/dist/index.js
CHANGED
|
@@ -21,39 +21,42 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
21
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
22
|
|
|
23
23
|
// src/core/constants.ts
|
|
24
|
-
var import_openinference_semantic_conventions, OtelSpanAttributes;
|
|
24
|
+
var import_openinference_semantic_conventions, OBSERVABILITY_TRACER_NAME, OBSERVABILITY_SDK_NAME, OBSERVABILITY_SDK_VERSION, OtelSpanAttributes;
|
|
25
25
|
var init_constants = __esm({
|
|
26
26
|
"src/core/constants.ts"() {
|
|
27
27
|
"use strict";
|
|
28
28
|
import_openinference_semantic_conventions = require("@arizeai/openinference-semantic-conventions");
|
|
29
|
+
OBSERVABILITY_TRACER_NAME = "agui-tracer";
|
|
30
|
+
OBSERVABILITY_SDK_NAME = "observability";
|
|
31
|
+
OBSERVABILITY_SDK_VERSION = "0.1.0";
|
|
29
32
|
OtelSpanAttributes = {
|
|
30
33
|
// OpenInference - re-export all standard conventions
|
|
31
34
|
...import_openinference_semantic_conventions.SemanticConventions,
|
|
32
|
-
//
|
|
35
|
+
// Trace attributes (non-standard)
|
|
33
36
|
TRACE_NAME: "trace.name",
|
|
34
37
|
TRACE_TAGS: "trace.tags",
|
|
35
38
|
TRACE_PUBLIC: "trace.public",
|
|
36
39
|
TRACE_METADATA: "trace.metadata",
|
|
37
40
|
TRACE_INPUT: "trace.input",
|
|
38
41
|
TRACE_OUTPUT: "trace.output",
|
|
39
|
-
//
|
|
42
|
+
// Observation attributes (non-standard)
|
|
40
43
|
OBSERVATION_TYPE: "observation.type",
|
|
41
44
|
OBSERVATION_LEVEL: "observation.level",
|
|
42
45
|
OBSERVATION_STATUS_MESSAGE: "observation.status_message",
|
|
43
46
|
OBSERVATION_INPUT: "observation.input",
|
|
44
47
|
OBSERVATION_OUTPUT: "observation.output",
|
|
45
48
|
OBSERVATION_METADATA: "observation.metadata",
|
|
46
|
-
//
|
|
49
|
+
// LLM-specific (non-standard)
|
|
47
50
|
LLM_COMPLETION_START_TIME: "llm.completion_start_time",
|
|
48
51
|
LLM_MODEL_PARAMETERS: "llm.model_parameters",
|
|
49
52
|
LLM_USAGE_DETAILS: "llm.usage_details",
|
|
50
53
|
LLM_COST_DETAILS: "llm.cost_details",
|
|
51
|
-
//
|
|
54
|
+
// Retriever-specific (non-standard)
|
|
52
55
|
RETRIEVER_NAME: "retriever.name",
|
|
53
56
|
RETRIEVER_QUERY: "retriever.query",
|
|
54
57
|
RETRIEVER_INDEX_ID: "retriever.index_id",
|
|
55
58
|
RETRIEVER_TOP_K: "retriever.top_k",
|
|
56
|
-
//
|
|
59
|
+
// General (non-standard)
|
|
57
60
|
ENVIRONMENT: "environment",
|
|
58
61
|
RELEASE: "release",
|
|
59
62
|
VERSION: "version"
|
|
@@ -106,19 +109,20 @@ function createObservationAttributes(type, attributes) {
|
|
|
106
109
|
modelParameters,
|
|
107
110
|
usageDetails
|
|
108
111
|
} = attributes;
|
|
112
|
+
const spanKind = import_openinference_semantic_conventions.OpenInferenceSpanKind[type.toUpperCase()] || "UNKNOWN";
|
|
109
113
|
const otelAttributes = {
|
|
110
|
-
[import_openinference_semantic_conventions2.SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
114
|
+
[import_openinference_semantic_conventions2.SemanticConventions.OPENINFERENCE_SPAN_KIND]: spanKind,
|
|
111
115
|
[OtelSpanAttributes.OBSERVATION_TYPE]: type,
|
|
112
116
|
[OtelSpanAttributes.OBSERVATION_LEVEL]: level,
|
|
113
117
|
[OtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]: statusMessage,
|
|
114
118
|
[OtelSpanAttributes.VERSION]: version,
|
|
115
119
|
// Use OpenInference input.value convention
|
|
116
120
|
[import_openinference_semantic_conventions2.SemanticConventions.INPUT_VALUE]: _serialize(input),
|
|
117
|
-
// Also set
|
|
121
|
+
// Also set observation.input for compatibility
|
|
118
122
|
[OtelSpanAttributes.OBSERVATION_INPUT]: _serialize(input),
|
|
119
123
|
// Use OpenInference output.value convention
|
|
120
124
|
[import_openinference_semantic_conventions2.SemanticConventions.OUTPUT_VALUE]: _serialize(output),
|
|
121
|
-
// Also set
|
|
125
|
+
// Also set observation.output for compatibility
|
|
122
126
|
[OtelSpanAttributes.OBSERVATION_OUTPUT]: _serialize(output)
|
|
123
127
|
};
|
|
124
128
|
if (type === "llm") {
|
|
@@ -411,14 +415,13 @@ function getTracer() {
|
|
|
411
415
|
OBSERVABILITY_SDK_VERSION
|
|
412
416
|
);
|
|
413
417
|
}
|
|
414
|
-
var import_api, OBSERVABILITY_GLOBAL_SYMBOL
|
|
418
|
+
var import_api, OBSERVABILITY_GLOBAL_SYMBOL;
|
|
415
419
|
var init_tracerProvider = __esm({
|
|
416
420
|
"src/core/tracerProvider.ts"() {
|
|
417
421
|
"use strict";
|
|
418
422
|
import_api = require("@opentelemetry/api");
|
|
423
|
+
init_constants();
|
|
419
424
|
OBSERVABILITY_GLOBAL_SYMBOL = /* @__PURE__ */ Symbol.for("observability");
|
|
420
|
-
OBSERVABILITY_SDK_NAME = "ag-kit-observability";
|
|
421
|
-
OBSERVABILITY_SDK_VERSION = "0.1.0";
|
|
422
425
|
}
|
|
423
426
|
});
|
|
424
427
|
|
|
@@ -450,7 +453,7 @@ var init_spanWrapper = __esm({
|
|
|
450
453
|
);
|
|
451
454
|
}
|
|
452
455
|
}
|
|
453
|
-
/** Gets the
|
|
456
|
+
/** Gets the OpenTelemetry tracer instance */
|
|
454
457
|
get tracer() {
|
|
455
458
|
return getTracer();
|
|
456
459
|
}
|
|
@@ -609,6 +612,9 @@ var init_spanWrapper = __esm({
|
|
|
609
612
|
// src/index.ts
|
|
610
613
|
var src_exports = {};
|
|
611
614
|
__export(src_exports, {
|
|
615
|
+
OBSERVABILITY_SDK_NAME: () => OBSERVABILITY_SDK_NAME,
|
|
616
|
+
OBSERVABILITY_SDK_VERSION: () => OBSERVABILITY_SDK_VERSION,
|
|
617
|
+
OBSERVABILITY_TRACER_NAME: () => OBSERVABILITY_TRACER_NAME,
|
|
612
618
|
ObservationAgent: () => ObservationAgent,
|
|
613
619
|
ObservationChain: () => ObservationChain,
|
|
614
620
|
ObservationEmbedding: () => ObservationEmbedding,
|
|
@@ -880,11 +886,15 @@ var init_src = __esm({
|
|
|
880
886
|
init_tracerProvider();
|
|
881
887
|
init_attributes();
|
|
882
888
|
init_tracerProvider();
|
|
889
|
+
init_constants();
|
|
883
890
|
}
|
|
884
891
|
});
|
|
885
892
|
init_src();
|
|
886
893
|
// Annotate the CommonJS export names for ESM import in node:
|
|
887
894
|
0 && (module.exports = {
|
|
895
|
+
OBSERVABILITY_SDK_NAME,
|
|
896
|
+
OBSERVABILITY_SDK_VERSION,
|
|
897
|
+
OBSERVABILITY_TRACER_NAME,
|
|
888
898
|
ObservationAgent,
|
|
889
899
|
ObservationChain,
|
|
890
900
|
ObservationEmbedding,
|