openlit 1.11.0 → 1.13.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.
Files changed (192) hide show
  1. package/README.md +1 -1
  2. package/dist/config.d.ts +12 -4
  3. package/dist/config.js +7 -17
  4. package/dist/config.js.map +1 -1
  5. package/dist/evals/llm/anthropic.js +10 -6
  6. package/dist/evals/llm/anthropic.js.map +1 -1
  7. package/dist/evals/llm/openai.js +9 -5
  8. package/dist/evals/llm/openai.js.map +1 -1
  9. package/dist/features/vault.js +1 -1
  10. package/dist/features/vault.js.map +1 -1
  11. package/dist/helpers.d.ts +93 -1
  12. package/dist/helpers.js +271 -8
  13. package/dist/helpers.js.map +1 -1
  14. package/dist/index.d.ts +6 -5
  15. package/dist/index.js +95 -50
  16. package/dist/index.js.map +1 -1
  17. package/dist/instrumentation/__tests__/anthropic-wrapper.test.js +215 -27
  18. package/dist/instrumentation/__tests__/anthropic-wrapper.test.js.map +1 -1
  19. package/dist/instrumentation/__tests__/base-wrapper.test.js +19 -23
  20. package/dist/instrumentation/__tests__/base-wrapper.test.js.map +1 -1
  21. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.d.ts +1 -0
  22. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js +422 -0
  23. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js.map +1 -0
  24. package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js +1 -1
  25. package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js.map +1 -1
  26. package/dist/instrumentation/__tests__/cohere-wrapper.test.js +150 -25
  27. package/dist/instrumentation/__tests__/cohere-wrapper.test.js.map +1 -1
  28. package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js +152 -33
  29. package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js.map +1 -1
  30. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +391 -45
  31. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -1
  32. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.d.ts +2 -2
  33. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js +323 -31
  34. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js.map +1 -1
  35. package/dist/instrumentation/__tests__/langchain-wrapper.test.d.ts +1 -0
  36. package/dist/instrumentation/__tests__/langchain-wrapper.test.js +282 -0
  37. package/dist/instrumentation/__tests__/langchain-wrapper.test.js.map +1 -0
  38. package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js +1 -1
  39. package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js.map +1 -1
  40. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.d.ts +0 -3
  41. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js +275 -68
  42. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js.map +1 -1
  43. package/dist/instrumentation/__tests__/openai-wrapper.test.js +7 -9
  44. package/dist/instrumentation/__tests__/openai-wrapper.test.js.map +1 -1
  45. package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js +1 -1
  46. package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js.map +1 -1
  47. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.d.ts +2 -1
  48. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js +209 -21
  49. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js.map +1 -1
  50. package/dist/instrumentation/__tests__/together-trace-comparison.test.js +231 -51
  51. package/dist/instrumentation/__tests__/together-trace-comparison.test.js.map +1 -1
  52. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.d.ts +8 -0
  53. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js +446 -0
  54. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js.map +1 -0
  55. package/dist/instrumentation/anthropic/index.d.ts +2 -3
  56. package/dist/instrumentation/anthropic/index.js.map +1 -1
  57. package/dist/instrumentation/anthropic/wrapper.d.ts +1 -3
  58. package/dist/instrumentation/anthropic/wrapper.js +211 -91
  59. package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
  60. package/dist/instrumentation/azure-ai-inference/index.d.ts +11 -0
  61. package/dist/instrumentation/azure-ai-inference/index.js +76 -0
  62. package/dist/instrumentation/azure-ai-inference/index.js.map +1 -0
  63. package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +42 -0
  64. package/dist/instrumentation/azure-ai-inference/wrapper.js +515 -0
  65. package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -0
  66. package/dist/instrumentation/base-wrapper.d.ts +2 -1
  67. package/dist/instrumentation/base-wrapper.js +35 -23
  68. package/dist/instrumentation/base-wrapper.js.map +1 -1
  69. package/dist/instrumentation/bedrock/wrapper.d.ts +21 -3
  70. package/dist/instrumentation/bedrock/wrapper.js +318 -265
  71. package/dist/instrumentation/bedrock/wrapper.js.map +1 -1
  72. package/dist/instrumentation/chroma/wrapper.js +1 -1
  73. package/dist/instrumentation/chroma/wrapper.js.map +1 -1
  74. package/dist/instrumentation/claude-agent-sdk/index.d.ts +23 -0
  75. package/dist/instrumentation/claude-agent-sdk/index.js +83 -0
  76. package/dist/instrumentation/claude-agent-sdk/index.js.map +1 -0
  77. package/dist/instrumentation/claude-agent-sdk/wrapper.d.ts +13 -0
  78. package/dist/instrumentation/claude-agent-sdk/wrapper.js +1031 -0
  79. package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -0
  80. package/dist/instrumentation/cohere/index.d.ts +2 -3
  81. package/dist/instrumentation/cohere/index.js.map +1 -1
  82. package/dist/instrumentation/cohere/wrapper.d.ts +1 -1
  83. package/dist/instrumentation/cohere/wrapper.js +215 -56
  84. package/dist/instrumentation/cohere/wrapper.js.map +1 -1
  85. package/dist/instrumentation/cursor-sdk/index.d.ts +21 -0
  86. package/dist/instrumentation/cursor-sdk/index.js +58 -0
  87. package/dist/instrumentation/cursor-sdk/index.js.map +1 -0
  88. package/dist/instrumentation/cursor-sdk/wrapper.d.ts +17 -0
  89. package/dist/instrumentation/cursor-sdk/wrapper.js +689 -0
  90. package/dist/instrumentation/cursor-sdk/wrapper.js.map +1 -0
  91. package/dist/instrumentation/google-adk/index.d.ts +57 -0
  92. package/dist/instrumentation/google-adk/index.js +371 -0
  93. package/dist/instrumentation/google-adk/index.js.map +1 -0
  94. package/dist/instrumentation/google-adk/utils.d.ts +45 -0
  95. package/dist/instrumentation/google-adk/utils.js +663 -0
  96. package/dist/instrumentation/google-adk/utils.js.map +1 -0
  97. package/dist/instrumentation/google-adk/wrapper.d.ts +11 -0
  98. package/dist/instrumentation/google-adk/wrapper.js +391 -0
  99. package/dist/instrumentation/google-adk/wrapper.js.map +1 -0
  100. package/dist/instrumentation/google-ai/wrapper.d.ts +7 -4
  101. package/dist/instrumentation/google-ai/wrapper.js +197 -61
  102. package/dist/instrumentation/google-ai/wrapper.js.map +1 -1
  103. package/dist/instrumentation/groq/wrapper.js +137 -65
  104. package/dist/instrumentation/groq/wrapper.js.map +1 -1
  105. package/dist/instrumentation/huggingface/wrapper.js +241 -39
  106. package/dist/instrumentation/huggingface/wrapper.js.map +1 -1
  107. package/dist/instrumentation/index.d.ts +2 -2
  108. package/dist/instrumentation/index.js +66 -6
  109. package/dist/instrumentation/index.js.map +1 -1
  110. package/dist/instrumentation/langchain/index.d.ts +0 -7
  111. package/dist/instrumentation/langchain/index.js +2 -20
  112. package/dist/instrumentation/langchain/index.js.map +1 -1
  113. package/dist/instrumentation/langchain/wrapper.d.ts +35 -0
  114. package/dist/instrumentation/langchain/wrapper.js +1098 -184
  115. package/dist/instrumentation/langchain/wrapper.js.map +1 -1
  116. package/dist/instrumentation/langgraph/index.d.ts +12 -0
  117. package/dist/instrumentation/langgraph/index.js +99 -0
  118. package/dist/instrumentation/langgraph/index.js.map +1 -0
  119. package/dist/instrumentation/langgraph/wrapper.d.ts +20 -0
  120. package/dist/instrumentation/langgraph/wrapper.js +619 -0
  121. package/dist/instrumentation/langgraph/wrapper.js.map +1 -0
  122. package/dist/instrumentation/llamaindex/index.d.ts +31 -6
  123. package/dist/instrumentation/llamaindex/index.js +180 -61
  124. package/dist/instrumentation/llamaindex/index.js.map +1 -1
  125. package/dist/instrumentation/llamaindex/wrapper.d.ts +15 -3
  126. package/dist/instrumentation/llamaindex/wrapper.js +670 -179
  127. package/dist/instrumentation/llamaindex/wrapper.js.map +1 -1
  128. package/dist/instrumentation/milvus/wrapper.js +1 -1
  129. package/dist/instrumentation/milvus/wrapper.js.map +1 -1
  130. package/dist/instrumentation/mistral/wrapper.js +154 -79
  131. package/dist/instrumentation/mistral/wrapper.js.map +1 -1
  132. package/dist/instrumentation/ollama/index.js +33 -4
  133. package/dist/instrumentation/ollama/index.js.map +1 -1
  134. package/dist/instrumentation/ollama/wrapper.d.ts +28 -2
  135. package/dist/instrumentation/ollama/wrapper.js +432 -48
  136. package/dist/instrumentation/ollama/wrapper.js.map +1 -1
  137. package/dist/instrumentation/openai/index.d.ts +2 -3
  138. package/dist/instrumentation/openai/index.js.map +1 -1
  139. package/dist/instrumentation/openai/wrapper.js +293 -194
  140. package/dist/instrumentation/openai/wrapper.js.map +1 -1
  141. package/dist/instrumentation/openai-agents/index.d.ts +20 -0
  142. package/dist/instrumentation/openai-agents/index.js +174 -0
  143. package/dist/instrumentation/openai-agents/index.js.map +1 -0
  144. package/dist/instrumentation/openai-agents/processor.d.ts +35 -0
  145. package/dist/instrumentation/openai-agents/processor.js +249 -0
  146. package/dist/instrumentation/openai-agents/processor.js.map +1 -0
  147. package/dist/instrumentation/openai-agents/utils.d.ts +20 -0
  148. package/dist/instrumentation/openai-agents/utils.js +624 -0
  149. package/dist/instrumentation/openai-agents/utils.js.map +1 -0
  150. package/dist/instrumentation/pinecone/wrapper.js +2 -2
  151. package/dist/instrumentation/pinecone/wrapper.js.map +1 -1
  152. package/dist/instrumentation/qdrant/wrapper.js +1 -1
  153. package/dist/instrumentation/qdrant/wrapper.js.map +1 -1
  154. package/dist/instrumentation/replicate/wrapper.js +103 -21
  155. package/dist/instrumentation/replicate/wrapper.js.map +1 -1
  156. package/dist/instrumentation/strands/index.d.ts +21 -0
  157. package/dist/instrumentation/strands/index.js +83 -0
  158. package/dist/instrumentation/strands/index.js.map +1 -0
  159. package/dist/instrumentation/strands/processor.d.ts +45 -0
  160. package/dist/instrumentation/strands/processor.js +545 -0
  161. package/dist/instrumentation/strands/processor.js.map +1 -0
  162. package/dist/instrumentation/strands/utils.d.ts +24 -0
  163. package/dist/instrumentation/strands/utils.js +360 -0
  164. package/dist/instrumentation/strands/utils.js.map +1 -0
  165. package/dist/instrumentation/together/wrapper.js +125 -51
  166. package/dist/instrumentation/together/wrapper.js.map +1 -1
  167. package/dist/instrumentation/vercel-ai/wrapper.d.ts +28 -2
  168. package/dist/instrumentation/vercel-ai/wrapper.js +314 -164
  169. package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -1
  170. package/dist/llm/anthropic.js +10 -6
  171. package/dist/llm/anthropic.js.map +1 -1
  172. package/dist/llm/openai.js +9 -5
  173. package/dist/llm/openai.js.map +1 -1
  174. package/dist/otel/__tests__/metrics.test.js +16 -27
  175. package/dist/otel/__tests__/metrics.test.js.map +1 -1
  176. package/dist/otel/events.d.ts +11 -0
  177. package/dist/otel/events.js +74 -0
  178. package/dist/otel/events.js.map +1 -0
  179. package/dist/otel/metrics.d.ts +5 -6
  180. package/dist/otel/metrics.js +66 -48
  181. package/dist/otel/metrics.js.map +1 -1
  182. package/dist/otel/tracing.d.ts +6 -2
  183. package/dist/otel/tracing.js +71 -24
  184. package/dist/otel/tracing.js.map +1 -1
  185. package/dist/otel/utils.d.ts +11 -0
  186. package/dist/otel/utils.js +34 -0
  187. package/dist/otel/utils.js.map +1 -0
  188. package/dist/semantic-convention.d.ts +49 -5
  189. package/dist/semantic-convention.js +56 -8
  190. package/dist/semantic-convention.js.map +1 -1
  191. package/dist/types.d.ts +58 -22
  192. package/package.json +41 -9
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ /**
3
+ * OpenLIT OpenAI Agents TracingProcessor implementation.
4
+ *
5
+ * Integrates with the @openai/agents TracingProcessor interface.
6
+ * All span data fields are read at onSpanEnd (when fully populated).
7
+ * Compliant with OTel GenAI semantic conventions.
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.OpenLITTracingProcessor = void 0;
14
+ const api_1 = require("@opentelemetry/api");
15
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
16
+ const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
17
+ const constant_1 = require("../../constant");
18
+ const config_1 = __importDefault(require("../../config"));
19
+ const helpers_1 = require("../../helpers");
20
+ const utils_1 = require("./utils");
21
+ const [OPENAI_SERVER_ADDRESS, OPENAI_SERVER_PORT] = (0, helpers_1.getServerAddressForProvider)('openai');
22
+ const LLM_SPAN_TYPES = new Set(['response', 'generation']);
23
+ /**
24
+ * TracingProcessor that emits OTel GenAI-compliant spans from
25
+ * the @openai/agents SDK tracing lifecycle.
26
+ *
27
+ * Thread-safe by design: each trace/span entry is keyed independently.
28
+ * LLM span types (response, generation) are skipped -- the OpenAI
29
+ * provider instrumentation handles those with richer telemetry.
30
+ */
31
+ class OpenLITTracingProcessor {
32
+ constructor(tracer, agentCreationRegistry = null) {
33
+ // SDK span_id -> SpanEntry
34
+ this._otelSpans = new Map();
35
+ // SDK trace_id -> TraceEntry
36
+ this._rootSpans = new Map();
37
+ // trace_id -> group_id (conversation id)
38
+ this._traceGroupIds = new Map();
39
+ // Agent handoff tracker (bounded Map)
40
+ this._handoffTracker = new Map();
41
+ this._tracer = tracer;
42
+ this._agentCreationRegistry = agentCreationRegistry;
43
+ }
44
+ // ------------------------------------------------------------------
45
+ // Trace lifecycle
46
+ // ------------------------------------------------------------------
47
+ async onTraceStart(sdkTrace) {
48
+ try {
49
+ const traceId = sdkTrace.traceId ?? 'unknown';
50
+ const traceName = sdkTrace.name ?? 'workflow';
51
+ const groupId = sdkTrace.groupId ?? null;
52
+ const operation = semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK;
53
+ const spanName = `${operation} ${traceName}`;
54
+ const otelSpan = this._tracer.startSpan(spanName, {
55
+ kind: api_1.SpanKind.INTERNAL,
56
+ attributes: {
57
+ [semantic_convention_1.default.GEN_AI_OPERATION]: operation,
58
+ [semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: semantic_convention_1.default.GEN_AI_SYSTEM_OPENAI,
59
+ },
60
+ });
61
+ const startTime = Date.now();
62
+ this._rootSpans.set(traceId, { otelSpan, startTime });
63
+ if (groupId) {
64
+ this._traceGroupIds.set(traceId, String(groupId));
65
+ }
66
+ (0, helpers_1.setFrameworkParentContext)(api_1.trace.setSpan(api_1.context.active(), otelSpan));
67
+ }
68
+ catch {
69
+ // swallow
70
+ }
71
+ }
72
+ async onTraceEnd(sdkTrace) {
73
+ try {
74
+ const traceId = sdkTrace.traceId ?? 'unknown';
75
+ const traceName = sdkTrace.name ?? 'workflow';
76
+ const entry = this._rootSpans.get(traceId);
77
+ this._rootSpans.delete(traceId);
78
+ const groupId = this._traceGroupIds.get(traceId) ?? null;
79
+ this._traceGroupIds.delete(traceId);
80
+ if (!entry)
81
+ return;
82
+ const { otelSpan, startTime } = entry;
83
+ const endTime = Date.now();
84
+ const durationMs = endTime - startTime;
85
+ // Set common framework attributes
86
+ otelSpan.setAttribute(semantic_conventions_1.ATTR_TELEMETRY_SDK_NAME, constant_1.SDK_NAME);
87
+ otelSpan.setAttribute(semantic_convention_1.default.GEN_AI_SDK_VERSION, constant_1.SDK_VERSION);
88
+ otelSpan.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, semantic_convention_1.default.GEN_AI_SYSTEM_OPENAI);
89
+ otelSpan.setAttribute(semantic_convention_1.default.GEN_AI_OPERATION, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK);
90
+ if (OPENAI_SERVER_ADDRESS) {
91
+ otelSpan.setAttribute(semantic_convention_1.default.SERVER_ADDRESS, OPENAI_SERVER_ADDRESS);
92
+ if (OPENAI_SERVER_PORT) {
93
+ otelSpan.setAttribute(semantic_convention_1.default.SERVER_PORT, OPENAI_SERVER_PORT);
94
+ }
95
+ }
96
+ otelSpan.setAttribute(semantic_convention_1.default.ATTR_DEPLOYMENT_ENVIRONMENT, config_1.default.environment ?? 'default');
97
+ otelSpan.setAttribute(semantic_conventions_1.ATTR_SERVICE_NAME, config_1.default.applicationName ?? 'default');
98
+ otelSpan.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, durationMs / 1000);
99
+ otelSpan.setAttribute(semantic_convention_1.default.GEN_AI_WORKFLOW_NAME, traceName);
100
+ if (groupId) {
101
+ otelSpan.setAttribute(semantic_convention_1.default.GEN_AI_CONVERSATION_ID, groupId);
102
+ }
103
+ (0, helpers_1.applyCustomSpanAttributes)(otelSpan);
104
+ // Error handling
105
+ const error = sdkTrace.error;
106
+ if (error) {
107
+ const errorType = typeof error === 'object' && error !== null
108
+ ? error.constructor?.name || error.code || '_OTHER'
109
+ : '_OTHER';
110
+ const errorMsg = typeof error === 'object' && error !== null
111
+ ? error.message ?? String(error)
112
+ : String(error);
113
+ otelSpan.setAttribute(semantic_convention_1.default.ERROR_TYPE, errorType);
114
+ otelSpan.setStatus({ code: api_1.SpanStatusCode.ERROR, message: errorMsg });
115
+ }
116
+ else {
117
+ otelSpan.setStatus({ code: api_1.SpanStatusCode.OK });
118
+ }
119
+ // Metrics
120
+ if (!config_1.default.disableMetrics) {
121
+ (0, utils_1.recordMetrics)(semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK, durationMs / 1000, null);
122
+ }
123
+ otelSpan.end();
124
+ (0, helpers_1.clearFrameworkParentContext)();
125
+ }
126
+ catch {
127
+ // swallow
128
+ }
129
+ }
130
+ // ------------------------------------------------------------------
131
+ // Span lifecycle
132
+ // ------------------------------------------------------------------
133
+ async onSpanStart(sdkSpan) {
134
+ try {
135
+ const spanData = sdkSpan.spanData;
136
+ const spanType = spanData?.type ?? 'unknown';
137
+ // Skip LLM span types -- let the OpenAI provider instrumentation handle them
138
+ if (LLM_SPAN_TYPES.has(spanType))
139
+ return;
140
+ const traceId = sdkSpan.traceId ?? 'unknown';
141
+ const sdkSpanId = sdkSpan.spanId ?? null;
142
+ const parentSdkId = sdkSpan.parentId ?? null;
143
+ const operation = (0, utils_1.getOperationType)(spanType);
144
+ const kind = (0, utils_1.getSpanKind)(operation);
145
+ const spanName = (0, utils_1.generateSpanName)(spanData);
146
+ // Find parent OTel span context
147
+ let parentCtx = api_1.context.active();
148
+ if (parentSdkId && this._otelSpans.has(parentSdkId)) {
149
+ const parentEntry = this._otelSpans.get(parentSdkId);
150
+ parentCtx = api_1.trace.setSpan(api_1.context.active(), parentEntry.otelSpan);
151
+ }
152
+ else if (this._rootSpans.has(traceId)) {
153
+ const rootEntry = this._rootSpans.get(traceId);
154
+ parentCtx = api_1.trace.setSpan(api_1.context.active(), rootEntry.otelSpan);
155
+ }
156
+ // Span links: connect invoke_agent back to create_agent
157
+ const links = [];
158
+ if (spanType === 'agent' && this._agentCreationRegistry) {
159
+ const agentName = spanData.name;
160
+ if (agentName) {
161
+ const creationCtx = this._agentCreationRegistry.get(String(agentName));
162
+ if (creationCtx) {
163
+ links.push({ context: creationCtx, attributes: {} });
164
+ }
165
+ }
166
+ }
167
+ const otelSpan = this._tracer.startSpan(spanName, {
168
+ kind,
169
+ links,
170
+ attributes: {
171
+ [semantic_convention_1.default.GEN_AI_OPERATION]: operation,
172
+ [semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: semantic_convention_1.default.GEN_AI_SYSTEM_OPENAI,
173
+ },
174
+ }, parentCtx);
175
+ const startTime = Date.now();
176
+ if (sdkSpanId) {
177
+ this._otelSpans.set(sdkSpanId, { otelSpan, startTime });
178
+ }
179
+ (0, helpers_1.setFrameworkParentContext)(api_1.trace.setSpan(parentCtx, otelSpan));
180
+ }
181
+ catch {
182
+ // swallow
183
+ }
184
+ }
185
+ async onSpanEnd(sdkSpan) {
186
+ try {
187
+ const spanData = sdkSpan.spanData;
188
+ const spanType = spanData?.type ?? 'unknown';
189
+ // Skip LLM span types
190
+ if (LLM_SPAN_TYPES.has(spanType))
191
+ return;
192
+ const sdkSpanId = sdkSpan.spanId ?? null;
193
+ const traceId = sdkSpan.traceId ?? 'unknown';
194
+ if (!sdkSpanId)
195
+ return;
196
+ const entry = this._otelSpans.get(sdkSpanId);
197
+ this._otelSpans.delete(sdkSpanId);
198
+ if (!entry)
199
+ return;
200
+ const { otelSpan, startTime } = entry;
201
+ const conversationId = this._traceGroupIds.get(traceId) ?? null;
202
+ (0, utils_1.processSpanEnd)(otelSpan, sdkSpan, startTime, conversationId, this._handoffTracker);
203
+ otelSpan.end();
204
+ // Restore parent context so subsequent provider spans nest correctly
205
+ const parentSdkId = sdkSpan.parentId ?? null;
206
+ if (parentSdkId && this._otelSpans.has(parentSdkId)) {
207
+ const parentEntry = this._otelSpans.get(parentSdkId);
208
+ (0, helpers_1.setFrameworkParentContext)(api_1.trace.setSpan(api_1.context.active(), parentEntry.otelSpan));
209
+ }
210
+ else if (this._rootSpans.has(traceId)) {
211
+ const rootEntry = this._rootSpans.get(traceId);
212
+ (0, helpers_1.setFrameworkParentContext)(api_1.trace.setSpan(api_1.context.active(), rootEntry.otelSpan));
213
+ }
214
+ }
215
+ catch {
216
+ // swallow
217
+ }
218
+ }
219
+ // ------------------------------------------------------------------
220
+ // Lifecycle management
221
+ // ------------------------------------------------------------------
222
+ async forceFlush() {
223
+ try {
224
+ for (const [, { otelSpan }] of this._otelSpans) {
225
+ try {
226
+ otelSpan.end();
227
+ }
228
+ catch { /* ignore */ }
229
+ }
230
+ this._otelSpans.clear();
231
+ for (const [, { otelSpan }] of this._rootSpans) {
232
+ try {
233
+ otelSpan.end();
234
+ }
235
+ catch { /* ignore */ }
236
+ }
237
+ this._rootSpans.clear();
238
+ this._traceGroupIds.clear();
239
+ }
240
+ catch {
241
+ // swallow
242
+ }
243
+ }
244
+ async shutdown() {
245
+ await this.forceFlush();
246
+ }
247
+ }
248
+ exports.OpenLITTracingProcessor = OpenLITTracingProcessor;
249
+ //# sourceMappingURL=processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.js","sourceRoot":"","sources":["../../../src/instrumentation/openai-agents/processor.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,4CAQ4B;AAC5B,8EAAiG;AAEjG,oFAA2D;AAC3D,6CAAuD;AACvD,0DAAyC;AACzC,2CAKuB;AACvB,mCAMiB;AAEjB,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,GAAG,IAAA,qCAA2B,EAAC,QAAQ,CAAC,CAAC;AAE1F,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;AAiB3D;;;;;;;GAOG;AACH,MAAa,uBAAuB;IAalC,YACE,MAA0C,EAC1C,wBAAsD,IAAI;QAX5D,2BAA2B;QACnB,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;QAClD,6BAA6B;QACrB,eAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;QACnD,yCAAyC;QACjC,mBAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;QACnD,sCAAsC;QAC9B,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;QAMlD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,sBAAsB,GAAG,qBAAqB,CAAC;IACtD,CAAC;IAED,qEAAqE;IACrE,kBAAkB;IAClB,qEAAqE;IACrE,KAAK,CAAC,YAAY,CAAC,QAAa;QAC9B,IAAI,CAAC;YACH,MAAM,OAAO,GAAW,QAAQ,CAAC,OAAO,IAAI,SAAS,CAAC;YACtD,MAAM,SAAS,GAAW,QAAQ,CAAC,IAAI,IAAI,UAAU,CAA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
2
+ * OpenAI Agents utilities for OTel GenAI semantic convention compliant telemetry.
3
+ *
4
+ * Maps SDK span types to OTel operation names, determines SpanKind,
5
+ * generates span names, and sets type-specific attributes on OTel spans.
6
+ *
7
+ * All attribute setting happens at on_span_end (when span data is fully
8
+ * populated), matching the Python SDK pattern.
9
+ */
10
+ import { Span as OtelSpan, SpanKind } from '@opentelemetry/api';
11
+ export declare function getOperationType(spanType: string): string;
12
+ export declare function getSpanKind(operationType: string): SpanKind;
13
+ export declare function generateSpanName(spanData: any): string;
14
+ /**
15
+ * Set all OTel-compliant attributes on the OTel span using fully-populated SDK data.
16
+ * Called from on_span_end in the processor.
17
+ */
18
+ export declare function processSpanEnd(otelSpan: OtelSpan, sdkSpan: any, startTime: number, conversationId: string | null, handoffTracker: Map<string, string>): void;
19
+ export declare function recordMetrics(operationType: string, durationSeconds: number, requestModel: string | null): void;
20
+ export declare function extractModelFromSpanData(spanData: any): string | null;