openlit 1.10.0 → 1.12.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 (195) hide show
  1. package/README.md +35 -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/__tests__/rule-engine.test.d.ts +1 -0
  10. package/dist/features/__tests__/rule-engine.test.js +146 -0
  11. package/dist/features/__tests__/rule-engine.test.js.map +1 -0
  12. package/dist/features/base.d.ts +2 -0
  13. package/dist/features/base.js +2 -0
  14. package/dist/features/base.js.map +1 -1
  15. package/dist/features/rule-engine.d.ts +6 -0
  16. package/dist/features/rule-engine.js +60 -0
  17. package/dist/features/rule-engine.js.map +1 -0
  18. package/dist/features/vault.js +1 -1
  19. package/dist/features/vault.js.map +1 -1
  20. package/dist/helpers.d.ts +93 -1
  21. package/dist/helpers.js +270 -8
  22. package/dist/helpers.js.map +1 -1
  23. package/dist/index.d.ts +6 -5
  24. package/dist/index.js +95 -50
  25. package/dist/index.js.map +1 -1
  26. package/dist/instrumentation/__tests__/anthropic-wrapper.test.js +215 -27
  27. package/dist/instrumentation/__tests__/anthropic-wrapper.test.js.map +1 -1
  28. package/dist/instrumentation/__tests__/base-wrapper.test.js +19 -23
  29. package/dist/instrumentation/__tests__/base-wrapper.test.js.map +1 -1
  30. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.d.ts +1 -0
  31. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js +422 -0
  32. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js.map +1 -0
  33. package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js +1 -1
  34. package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js.map +1 -1
  35. package/dist/instrumentation/__tests__/cohere-wrapper.test.js +150 -25
  36. package/dist/instrumentation/__tests__/cohere-wrapper.test.js.map +1 -1
  37. package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js +152 -33
  38. package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js.map +1 -1
  39. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +391 -45
  40. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -1
  41. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.d.ts +2 -2
  42. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js +323 -31
  43. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js.map +1 -1
  44. package/dist/instrumentation/__tests__/langchain-wrapper.test.d.ts +1 -0
  45. package/dist/instrumentation/__tests__/langchain-wrapper.test.js +282 -0
  46. package/dist/instrumentation/__tests__/langchain-wrapper.test.js.map +1 -0
  47. package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js +1 -1
  48. package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js.map +1 -1
  49. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.d.ts +0 -3
  50. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js +275 -68
  51. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js.map +1 -1
  52. package/dist/instrumentation/__tests__/openai-wrapper.test.js +7 -9
  53. package/dist/instrumentation/__tests__/openai-wrapper.test.js.map +1 -1
  54. package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js +1 -1
  55. package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js.map +1 -1
  56. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.d.ts +2 -1
  57. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js +209 -21
  58. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js.map +1 -1
  59. package/dist/instrumentation/__tests__/together-trace-comparison.test.js +231 -51
  60. package/dist/instrumentation/__tests__/together-trace-comparison.test.js.map +1 -1
  61. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.d.ts +8 -0
  62. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js +446 -0
  63. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js.map +1 -0
  64. package/dist/instrumentation/anthropic/index.d.ts +2 -3
  65. package/dist/instrumentation/anthropic/index.js.map +1 -1
  66. package/dist/instrumentation/anthropic/wrapper.d.ts +1 -3
  67. package/dist/instrumentation/anthropic/wrapper.js +211 -91
  68. package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
  69. package/dist/instrumentation/azure-ai-inference/index.d.ts +11 -0
  70. package/dist/instrumentation/azure-ai-inference/index.js +76 -0
  71. package/dist/instrumentation/azure-ai-inference/index.js.map +1 -0
  72. package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +42 -0
  73. package/dist/instrumentation/azure-ai-inference/wrapper.js +515 -0
  74. package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -0
  75. package/dist/instrumentation/base-wrapper.d.ts +2 -1
  76. package/dist/instrumentation/base-wrapper.js +35 -23
  77. package/dist/instrumentation/base-wrapper.js.map +1 -1
  78. package/dist/instrumentation/bedrock/wrapper.d.ts +21 -3
  79. package/dist/instrumentation/bedrock/wrapper.js +318 -265
  80. package/dist/instrumentation/bedrock/wrapper.js.map +1 -1
  81. package/dist/instrumentation/chroma/wrapper.js +1 -1
  82. package/dist/instrumentation/chroma/wrapper.js.map +1 -1
  83. package/dist/instrumentation/claude-agent-sdk/index.d.ts +23 -0
  84. package/dist/instrumentation/claude-agent-sdk/index.js +83 -0
  85. package/dist/instrumentation/claude-agent-sdk/index.js.map +1 -0
  86. package/dist/instrumentation/claude-agent-sdk/wrapper.d.ts +13 -0
  87. package/dist/instrumentation/claude-agent-sdk/wrapper.js +1031 -0
  88. package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -0
  89. package/dist/instrumentation/cohere/index.d.ts +2 -3
  90. package/dist/instrumentation/cohere/index.js.map +1 -1
  91. package/dist/instrumentation/cohere/wrapper.d.ts +1 -1
  92. package/dist/instrumentation/cohere/wrapper.js +215 -56
  93. package/dist/instrumentation/cohere/wrapper.js.map +1 -1
  94. package/dist/instrumentation/google-adk/index.d.ts +57 -0
  95. package/dist/instrumentation/google-adk/index.js +371 -0
  96. package/dist/instrumentation/google-adk/index.js.map +1 -0
  97. package/dist/instrumentation/google-adk/utils.d.ts +45 -0
  98. package/dist/instrumentation/google-adk/utils.js +663 -0
  99. package/dist/instrumentation/google-adk/utils.js.map +1 -0
  100. package/dist/instrumentation/google-adk/wrapper.d.ts +11 -0
  101. package/dist/instrumentation/google-adk/wrapper.js +391 -0
  102. package/dist/instrumentation/google-adk/wrapper.js.map +1 -0
  103. package/dist/instrumentation/google-ai/wrapper.d.ts +7 -4
  104. package/dist/instrumentation/google-ai/wrapper.js +197 -61
  105. package/dist/instrumentation/google-ai/wrapper.js.map +1 -1
  106. package/dist/instrumentation/groq/wrapper.js +137 -65
  107. package/dist/instrumentation/groq/wrapper.js.map +1 -1
  108. package/dist/instrumentation/huggingface/wrapper.js +241 -39
  109. package/dist/instrumentation/huggingface/wrapper.js.map +1 -1
  110. package/dist/instrumentation/index.d.ts +2 -2
  111. package/dist/instrumentation/index.js +64 -6
  112. package/dist/instrumentation/index.js.map +1 -1
  113. package/dist/instrumentation/langchain/index.d.ts +0 -7
  114. package/dist/instrumentation/langchain/index.js +2 -20
  115. package/dist/instrumentation/langchain/index.js.map +1 -1
  116. package/dist/instrumentation/langchain/wrapper.d.ts +35 -0
  117. package/dist/instrumentation/langchain/wrapper.js +1098 -184
  118. package/dist/instrumentation/langchain/wrapper.js.map +1 -1
  119. package/dist/instrumentation/langgraph/index.d.ts +12 -0
  120. package/dist/instrumentation/langgraph/index.js +99 -0
  121. package/dist/instrumentation/langgraph/index.js.map +1 -0
  122. package/dist/instrumentation/langgraph/wrapper.d.ts +20 -0
  123. package/dist/instrumentation/langgraph/wrapper.js +619 -0
  124. package/dist/instrumentation/langgraph/wrapper.js.map +1 -0
  125. package/dist/instrumentation/llamaindex/index.d.ts +31 -6
  126. package/dist/instrumentation/llamaindex/index.js +180 -61
  127. package/dist/instrumentation/llamaindex/index.js.map +1 -1
  128. package/dist/instrumentation/llamaindex/wrapper.d.ts +15 -3
  129. package/dist/instrumentation/llamaindex/wrapper.js +670 -179
  130. package/dist/instrumentation/llamaindex/wrapper.js.map +1 -1
  131. package/dist/instrumentation/milvus/wrapper.js +1 -1
  132. package/dist/instrumentation/milvus/wrapper.js.map +1 -1
  133. package/dist/instrumentation/mistral/wrapper.js +154 -79
  134. package/dist/instrumentation/mistral/wrapper.js.map +1 -1
  135. package/dist/instrumentation/ollama/index.js +33 -4
  136. package/dist/instrumentation/ollama/index.js.map +1 -1
  137. package/dist/instrumentation/ollama/wrapper.d.ts +28 -2
  138. package/dist/instrumentation/ollama/wrapper.js +432 -48
  139. package/dist/instrumentation/ollama/wrapper.js.map +1 -1
  140. package/dist/instrumentation/openai/index.d.ts +2 -3
  141. package/dist/instrumentation/openai/index.js.map +1 -1
  142. package/dist/instrumentation/openai/wrapper.js +293 -194
  143. package/dist/instrumentation/openai/wrapper.js.map +1 -1
  144. package/dist/instrumentation/openai-agents/index.d.ts +20 -0
  145. package/dist/instrumentation/openai-agents/index.js +174 -0
  146. package/dist/instrumentation/openai-agents/index.js.map +1 -0
  147. package/dist/instrumentation/openai-agents/processor.d.ts +35 -0
  148. package/dist/instrumentation/openai-agents/processor.js +249 -0
  149. package/dist/instrumentation/openai-agents/processor.js.map +1 -0
  150. package/dist/instrumentation/openai-agents/utils.d.ts +20 -0
  151. package/dist/instrumentation/openai-agents/utils.js +624 -0
  152. package/dist/instrumentation/openai-agents/utils.js.map +1 -0
  153. package/dist/instrumentation/pinecone/wrapper.js +2 -2
  154. package/dist/instrumentation/pinecone/wrapper.js.map +1 -1
  155. package/dist/instrumentation/qdrant/wrapper.js +1 -1
  156. package/dist/instrumentation/qdrant/wrapper.js.map +1 -1
  157. package/dist/instrumentation/replicate/wrapper.js +103 -21
  158. package/dist/instrumentation/replicate/wrapper.js.map +1 -1
  159. package/dist/instrumentation/strands/index.d.ts +21 -0
  160. package/dist/instrumentation/strands/index.js +83 -0
  161. package/dist/instrumentation/strands/index.js.map +1 -0
  162. package/dist/instrumentation/strands/processor.d.ts +45 -0
  163. package/dist/instrumentation/strands/processor.js +545 -0
  164. package/dist/instrumentation/strands/processor.js.map +1 -0
  165. package/dist/instrumentation/strands/utils.d.ts +24 -0
  166. package/dist/instrumentation/strands/utils.js +360 -0
  167. package/dist/instrumentation/strands/utils.js.map +1 -0
  168. package/dist/instrumentation/together/wrapper.js +125 -51
  169. package/dist/instrumentation/together/wrapper.js.map +1 -1
  170. package/dist/instrumentation/vercel-ai/wrapper.d.ts +28 -2
  171. package/dist/instrumentation/vercel-ai/wrapper.js +314 -164
  172. package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -1
  173. package/dist/llm/anthropic.js +10 -6
  174. package/dist/llm/anthropic.js.map +1 -1
  175. package/dist/llm/openai.js +9 -5
  176. package/dist/llm/openai.js.map +1 -1
  177. package/dist/otel/__tests__/metrics.test.js +16 -27
  178. package/dist/otel/__tests__/metrics.test.js.map +1 -1
  179. package/dist/otel/events.d.ts +11 -0
  180. package/dist/otel/events.js +74 -0
  181. package/dist/otel/events.js.map +1 -0
  182. package/dist/otel/metrics.d.ts +5 -6
  183. package/dist/otel/metrics.js +66 -48
  184. package/dist/otel/metrics.js.map +1 -1
  185. package/dist/otel/tracing.d.ts +6 -2
  186. package/dist/otel/tracing.js +71 -24
  187. package/dist/otel/tracing.js.map +1 -1
  188. package/dist/otel/utils.d.ts +11 -0
  189. package/dist/otel/utils.js +34 -0
  190. package/dist/otel/utils.js.map +1 -0
  191. package/dist/semantic-convention.d.ts +44 -5
  192. package/dist/semantic-convention.js +51 -8
  193. package/dist/semantic-convention.js.map +1 -1
  194. package/dist/types.d.ts +74 -22
  195. package/package.json +41 -9
@@ -0,0 +1,371 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
7
+ const api_1 = require("@opentelemetry/api");
8
+ const constant_1 = require("../../constant");
9
+ const utils_1 = require("./utils");
10
+ const wrapper_1 = require("./wrapper");
11
+ const config_1 = __importDefault(require("../../config"));
12
+ /**
13
+ * OTel GenAI semantic convention compliant instrumentor for Google ADK.
14
+ *
15
+ * Monkey-patches Runner, BaseAgent, and LlmAgent from @google/adk.
16
+ * Replaces ADK's internal tracers with PassthroughTracer to suppress
17
+ * duplicate spans. Enriches ADK's LLM and tool spans with OTel attributes.
18
+ */
19
+ class GoogleADKInstrumentation extends instrumentation_1.InstrumentationBase {
20
+ constructor(config = {}) {
21
+ super(`${constant_1.INSTRUMENTATION_PREFIX}/instrumentation-google-adk`, '1.0.0', config);
22
+ this._registry = new wrapper_1.AgentCreationRegistry();
23
+ this._originalTracers = {};
24
+ this._originalTraceCallLlm = null;
25
+ this._originalTraceToolCall = null;
26
+ this._originalTraceMergedToolCalls = null;
27
+ }
28
+ init() {
29
+ const module = new instrumentation_1.InstrumentationNodeModuleDefinition('@google/adk', ['>=1.2.0'], (moduleExports) => {
30
+ this._patchAll(moduleExports);
31
+ return moduleExports;
32
+ }, (moduleExports) => {
33
+ if (moduleExports !== undefined) {
34
+ this._unpatchAll(moduleExports);
35
+ }
36
+ });
37
+ return [module];
38
+ }
39
+ manualPatch(adkModule) {
40
+ this._patchAll(adkModule);
41
+ }
42
+ // ---------------------------------------------------------------------------
43
+ // Patching
44
+ // ---------------------------------------------------------------------------
45
+ _patchAll(moduleExports) {
46
+ try {
47
+ this._disableExistingTracers(moduleExports);
48
+ this._wrapTraceCallLlm(moduleExports);
49
+ this._wrapTraceToolCall(moduleExports);
50
+ this._wrapTraceMergedToolCalls(moduleExports);
51
+ this._patchLlmAgent(moduleExports);
52
+ this._patchRunner(moduleExports);
53
+ this._patchBaseAgent(moduleExports);
54
+ }
55
+ catch { /* graceful degradation */ }
56
+ }
57
+ /**
58
+ * Replace ADK's internal tracers with PassthroughTracer to suppress
59
+ * duplicate top-level spans (mirrors Python _disable_existing_tracers).
60
+ */
61
+ _disableExistingTracers(moduleExports) {
62
+ try {
63
+ const runners = this._resolveSubmodule(moduleExports, 'runners');
64
+ if (runners && runners.tracer) {
65
+ this._originalTracers['runners.tracer'] = runners.tracer;
66
+ runners.tracer = new utils_1.PassthroughTracer(runners.tracer);
67
+ }
68
+ }
69
+ catch { /* ignore */ }
70
+ try {
71
+ const baseAgentMod = this._resolveSubmodule(moduleExports, 'agents', 'base_agent') ??
72
+ this._resolveSubmodule(moduleExports, 'agents');
73
+ if (baseAgentMod && baseAgentMod.tracer) {
74
+ this._originalTracers['base_agent.tracer'] = baseAgentMod.tracer;
75
+ baseAgentMod.tracer = new utils_1.PassthroughTracer(baseAgentMod.tracer);
76
+ }
77
+ }
78
+ catch { /* ignore */ }
79
+ }
80
+ /**
81
+ * Wrap ADK's trace_call_llm to enrich the current span with OTel GenAI attributes.
82
+ */
83
+ _wrapTraceCallLlm(moduleExports) {
84
+ try {
85
+ const blfMod = this._resolveSubmodule(moduleExports, 'flows', 'llm_flows', 'base_llm_flow') ??
86
+ this._resolveSubmodule(moduleExports, 'flows');
87
+ if (!blfMod)
88
+ return;
89
+ const originalFn = blfMod.trace_call_llm ?? blfMod.traceCallLlm;
90
+ if (!originalFn)
91
+ return;
92
+ this._originalTraceCallLlm = originalFn;
93
+ const captureContent = () => config_1.default.captureMessageContent ?? true;
94
+ const enriched = (...args) => {
95
+ const result = originalFn(...args);
96
+ try {
97
+ const span = api_1.trace.getActiveSpan();
98
+ if (span) {
99
+ const llmRequest = args[2];
100
+ const llmResponse = args[3];
101
+ (0, utils_1.enrichLlmSpan)(span, llmRequest, llmResponse, captureContent());
102
+ }
103
+ }
104
+ catch { /* ignore */ }
105
+ return result;
106
+ };
107
+ if (blfMod.trace_call_llm) {
108
+ blfMod.trace_call_llm = enriched;
109
+ }
110
+ else if (blfMod.traceCallLlm) {
111
+ blfMod.traceCallLlm = enriched;
112
+ }
113
+ }
114
+ catch { /* ignore */ }
115
+ }
116
+ /**
117
+ * Wrap ADK's trace_tool_call to enrich the current span with tool attributes.
118
+ */
119
+ _wrapTraceToolCall(moduleExports) {
120
+ try {
121
+ const fnMod = this._resolveSubmodule(moduleExports, 'flows', 'llm_flows', 'functions') ??
122
+ this._resolveSubmodule(moduleExports, 'flows');
123
+ if (!fnMod)
124
+ return;
125
+ const originalFn = fnMod.trace_tool_call ?? fnMod.traceToolCall;
126
+ if (!originalFn)
127
+ return;
128
+ this._originalTraceToolCall = originalFn;
129
+ const captureContent = () => config_1.default.captureMessageContent ?? true;
130
+ const enriched = (...args) => {
131
+ const result = originalFn(...args);
132
+ try {
133
+ const span = api_1.trace.getActiveSpan();
134
+ if (span) {
135
+ const tool = args[0];
136
+ const functionArgs = args[1];
137
+ const functionResponseEvent = args[2];
138
+ const toolError = args[3];
139
+ (0, utils_1.enrichToolSpan)(span, tool, functionArgs, functionResponseEvent, captureContent(), toolError);
140
+ }
141
+ }
142
+ catch { /* ignore */ }
143
+ return result;
144
+ };
145
+ if (fnMod.trace_tool_call) {
146
+ fnMod.trace_tool_call = enriched;
147
+ }
148
+ else if (fnMod.traceToolCall) {
149
+ fnMod.traceToolCall = enriched;
150
+ }
151
+ }
152
+ catch { /* ignore */ }
153
+ }
154
+ /**
155
+ * Wrap ADK's trace_merged_tool_calls to enrich the current span with merged tool attributes.
156
+ */
157
+ _wrapTraceMergedToolCalls(moduleExports) {
158
+ try {
159
+ const fnMod = this._resolveSubmodule(moduleExports, 'flows', 'llm_flows', 'functions') ??
160
+ this._resolveSubmodule(moduleExports, 'flows');
161
+ if (!fnMod)
162
+ return;
163
+ const originalFn = fnMod.trace_merged_tool_calls ?? fnMod.traceMergedToolCalls;
164
+ if (!originalFn)
165
+ return;
166
+ this._originalTraceMergedToolCalls = originalFn;
167
+ const captureContent = () => config_1.default.captureMessageContent ?? true;
168
+ const enriched = (...args) => {
169
+ const result = originalFn(...args);
170
+ try {
171
+ const span = api_1.trace.getActiveSpan();
172
+ if (span) {
173
+ const responseEventId = args[0];
174
+ const functionResponseEvent = args[1];
175
+ (0, utils_1.enrichMergedToolSpan)(span, responseEventId, functionResponseEvent, captureContent());
176
+ }
177
+ }
178
+ catch { /* ignore */ }
179
+ return result;
180
+ };
181
+ if (fnMod.trace_merged_tool_calls) {
182
+ fnMod.trace_merged_tool_calls = enriched;
183
+ }
184
+ else if (fnMod.traceMergedToolCalls) {
185
+ fnMod.traceMergedToolCalls = enriched;
186
+ }
187
+ }
188
+ catch { /* ignore */ }
189
+ }
190
+ /**
191
+ * Patch LlmAgent constructor to create create_agent spans.
192
+ */
193
+ _patchLlmAgent(moduleExports) {
194
+ try {
195
+ const LlmAgent = moduleExports.LlmAgent ?? moduleExports.Agent;
196
+ if (!LlmAgent?.prototype)
197
+ return;
198
+ const originalClass = LlmAgent;
199
+ const patchFn = (0, wrapper_1.wrapAgentInit)(this.tracer, this._registry);
200
+ // Wrap any init-like method if available; otherwise wrap the class prototype methods
201
+ // ADK's LlmAgent may expose initialization through sub_agents, tools setters, etc.
202
+ // The most reliable approach is patching the constructor via a proxy pattern.
203
+ if (typeof originalClass === 'function') {
204
+ const wrappedConstructor = patchFn(function (...args) {
205
+ return Reflect.construct(originalClass, args, new.target || originalClass);
206
+ });
207
+ // Copy static properties
208
+ Object.setPrototypeOf(wrappedConstructor, originalClass);
209
+ wrappedConstructor.prototype = originalClass.prototype;
210
+ // ESM-to-CJS interop may define exports as getter-only properties;
211
+ // both defineProperty and assignment may fail for ESM Module Namespace objects.
212
+ const exportName = moduleExports.LlmAgent ? 'LlmAgent' : 'Agent';
213
+ try {
214
+ Object.defineProperty(moduleExports, exportName, {
215
+ enumerable: true,
216
+ configurable: true,
217
+ writable: true,
218
+ value: wrappedConstructor,
219
+ });
220
+ }
221
+ catch {
222
+ try {
223
+ moduleExports[exportName] = wrappedConstructor;
224
+ }
225
+ catch { /* strict mode */ }
226
+ }
227
+ }
228
+ }
229
+ catch { /* ignore */ }
230
+ }
231
+ /**
232
+ * Patch Runner.run and Runner.runAsync (or run_async).
233
+ */
234
+ _patchRunner(moduleExports) {
235
+ try {
236
+ const Runner = moduleExports.Runner;
237
+ if (!Runner?.prototype)
238
+ return;
239
+ // Runner.run (sync)
240
+ const runMethod = Runner.prototype.run;
241
+ if (runMethod && !(0, instrumentation_1.isWrapped)(runMethod)) {
242
+ this._wrap(Runner.prototype, 'run', (0, wrapper_1.wrapRunnerRun)(this.tracer, 'runner_run', this._registry));
243
+ }
244
+ // Runner.runAsync or Runner.run_async (async generator)
245
+ const runAsyncName = Runner.prototype.runAsync ? 'runAsync' : 'run_async';
246
+ const runAsyncMethod = Runner.prototype[runAsyncName];
247
+ if (runAsyncMethod) {
248
+ if ((0, instrumentation_1.isWrapped)(runAsyncMethod))
249
+ this._unwrap(Runner.prototype, runAsyncName);
250
+ this._wrap(Runner.prototype, runAsyncName, (0, wrapper_1.wrapRunnerRunAsync)(this.tracer, 'runner_run_async', this._registry));
251
+ }
252
+ // Runner.runLive or Runner.run_live (async generator)
253
+ const runLiveName = Runner.prototype.runLive ? 'runLive' : 'run_live';
254
+ const runLiveMethod = Runner.prototype[runLiveName];
255
+ if (runLiveMethod) {
256
+ if ((0, instrumentation_1.isWrapped)(runLiveMethod))
257
+ this._unwrap(Runner.prototype, runLiveName);
258
+ this._wrap(Runner.prototype, runLiveName, (0, wrapper_1.wrapRunnerRunAsync)(this.tracer, 'runner_run_live', this._registry));
259
+ }
260
+ }
261
+ catch { /* ignore */ }
262
+ }
263
+ /**
264
+ * Patch BaseAgent.runAsync (or run_async).
265
+ */
266
+ _patchBaseAgent(moduleExports) {
267
+ try {
268
+ const BaseAgent = moduleExports.BaseAgent;
269
+ if (!BaseAgent?.prototype)
270
+ return;
271
+ const runAsyncName = BaseAgent.prototype.runAsync ? 'runAsync' : 'run_async';
272
+ const runAsyncMethod = BaseAgent.prototype[runAsyncName];
273
+ if (runAsyncMethod) {
274
+ if ((0, instrumentation_1.isWrapped)(runAsyncMethod))
275
+ this._unwrap(BaseAgent.prototype, runAsyncName);
276
+ this._wrap(BaseAgent.prototype, runAsyncName, (0, wrapper_1.wrapAgentRunAsync)(this.tracer, 'agent_run_async', this._registry));
277
+ }
278
+ }
279
+ catch { /* ignore */ }
280
+ }
281
+ // ---------------------------------------------------------------------------
282
+ // Submodule resolution
283
+ // ---------------------------------------------------------------------------
284
+ /**
285
+ * Attempt to resolve a nested submodule from the ADK exports.
286
+ * ADK's JS package may organize exports differently from Python.
287
+ */
288
+ _resolveSubmodule(moduleExports, ...path) {
289
+ let current = moduleExports;
290
+ for (const segment of path) {
291
+ if (!current)
292
+ return null;
293
+ current = current[segment];
294
+ }
295
+ return current || null;
296
+ }
297
+ // ---------------------------------------------------------------------------
298
+ // Unpatching
299
+ // ---------------------------------------------------------------------------
300
+ _unpatchAll(moduleExports) {
301
+ try {
302
+ // Restore original tracers
303
+ if (this._originalTracers['runners.tracer']) {
304
+ const runners = this._resolveSubmodule(moduleExports, 'runners');
305
+ if (runners)
306
+ runners.tracer = this._originalTracers['runners.tracer'];
307
+ }
308
+ if (this._originalTracers['base_agent.tracer']) {
309
+ const baseAgentMod = this._resolveSubmodule(moduleExports, 'agents', 'base_agent') ??
310
+ this._resolveSubmodule(moduleExports, 'agents');
311
+ if (baseAgentMod)
312
+ baseAgentMod.tracer = this._originalTracers['base_agent.tracer'];
313
+ }
314
+ // Restore original tracing functions
315
+ if (this._originalTraceCallLlm) {
316
+ const blfMod = this._resolveSubmodule(moduleExports, 'flows', 'llm_flows', 'base_llm_flow') ??
317
+ this._resolveSubmodule(moduleExports, 'flows');
318
+ if (blfMod) {
319
+ if (blfMod.trace_call_llm)
320
+ blfMod.trace_call_llm = this._originalTraceCallLlm;
321
+ else if (blfMod.traceCallLlm)
322
+ blfMod.traceCallLlm = this._originalTraceCallLlm;
323
+ }
324
+ }
325
+ if (this._originalTraceToolCall) {
326
+ const fnMod = this._resolveSubmodule(moduleExports, 'flows', 'llm_flows', 'functions') ??
327
+ this._resolveSubmodule(moduleExports, 'flows');
328
+ if (fnMod) {
329
+ if (fnMod.trace_tool_call)
330
+ fnMod.trace_tool_call = this._originalTraceToolCall;
331
+ else if (fnMod.traceToolCall)
332
+ fnMod.traceToolCall = this._originalTraceToolCall;
333
+ }
334
+ }
335
+ if (this._originalTraceMergedToolCalls) {
336
+ const fnMod = this._resolveSubmodule(moduleExports, 'flows', 'llm_flows', 'functions') ??
337
+ this._resolveSubmodule(moduleExports, 'flows');
338
+ if (fnMod) {
339
+ if (fnMod.trace_merged_tool_calls)
340
+ fnMod.trace_merged_tool_calls = this._originalTraceMergedToolCalls;
341
+ else if (fnMod.traceMergedToolCalls)
342
+ fnMod.traceMergedToolCalls = this._originalTraceMergedToolCalls;
343
+ }
344
+ }
345
+ // Unwrap patched methods
346
+ const Runner = moduleExports.Runner;
347
+ if (Runner?.prototype) {
348
+ if ((0, instrumentation_1.isWrapped)(Runner.prototype.run))
349
+ this._unwrap(Runner.prototype, 'run');
350
+ const runAsyncName = Runner.prototype.runAsync ? 'runAsync' : 'run_async';
351
+ if (Runner.prototype[runAsyncName] && (0, instrumentation_1.isWrapped)(Runner.prototype[runAsyncName])) {
352
+ this._unwrap(Runner.prototype, runAsyncName);
353
+ }
354
+ const runLiveName = Runner.prototype.runLive ? 'runLive' : 'run_live';
355
+ if (Runner.prototype[runLiveName] && (0, instrumentation_1.isWrapped)(Runner.prototype[runLiveName])) {
356
+ this._unwrap(Runner.prototype, runLiveName);
357
+ }
358
+ }
359
+ const BaseAgent = moduleExports.BaseAgent;
360
+ if (BaseAgent?.prototype) {
361
+ const runAsyncName = BaseAgent.prototype.runAsync ? 'runAsync' : 'run_async';
362
+ if (BaseAgent.prototype[runAsyncName] && (0, instrumentation_1.isWrapped)(BaseAgent.prototype[runAsyncName])) {
363
+ this._unwrap(BaseAgent.prototype, runAsyncName);
364
+ }
365
+ }
366
+ }
367
+ catch { /* ignore */ }
368
+ }
369
+ }
370
+ exports.default = GoogleADKInstrumentation;
371
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/instrumentation/google-adk/index.ts"],"names":[],"mappings":";;;;;AAAA,oEAKwC;AAExC,4CAA2C;AAC3C,6CAAwD;AACxD,mCAKiB;AACjB,uCAMmB;AACnB,0DAAyC;AAIzC;;;;;;GAMG;AACH,MAAqB,wBAAyB,SAAQ,qCAAmB;IAOvE,YAAY,SAAyC,EAAE;QACrD,KAAK,CAAC,GAAG,iCAAsB,6BAA6B,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAPzE,cAAS,GAAG,IAAI,+BAAqB,EAAE,CAAC;QACxC,qBAAgB,GAAwB,EAAE,CAAC;QAC3C,0BAAqB,GAAQ,IAAI,CAAC;QAClC,2BAAsB,GAAQ,IAAI,CAAC;QACnC,kCAA6B,GAAQ,IAAI,CAAC;IAIlD,CAAC;IAES,IAAI;QACZ,MAAM,MAAM,GAAG,IAAI,qDAAmC,CACpD,aAAa,EACb,CAAC,SAAS,CAAC,EACX,CAAC,aAAa,EAAE,EAAE;YAChB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;YAC9B,OAAO,aAAa,CAAC;QACvB,CAAC,EACD,CAAC,aAAa,EAAE,EAAE;YAChB,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;gBAChC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;YAClC,CAAC;QACH,CAAC,CACF,CAAC;QAEF,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAEM,WAAW,CAAC,SAAc;QAC/B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;IAED,8EAA8E;IAC9E,WAAW;IACX,8EAA8E;IAEtE,SAAS,C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AS,EAAE,CAAC;gBACzB,MAAM,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;gBAC7E,IAAI,SAAS,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,IAAA,2BAAS,EAAC,SAAS,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;oBACtF,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;gBAClD,CAAC;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;CACF;AAlXD,2CAkXC"}
@@ -0,0 +1,45 @@
1
+ import { Span, SpanKind } from '@opentelemetry/api';
2
+ import { AsyncLocalStorage } from 'async_hooks';
3
+ /**
4
+ * Prevents Runner.run_async from creating a second invoke_agent span
5
+ * when called internally by Runner.run (mirrors Python _ADK_WORKFLOW_ACTIVE).
6
+ */
7
+ export declare const adkWorkflowActive: AsyncLocalStorage<boolean>;
8
+ export declare function isAdkWorkflowActive(): boolean;
9
+ export declare const OPERATION_MAP: Record<string, string>;
10
+ export declare function getOperationType(endpoint: string): string;
11
+ export declare function getSpanKind(operationType: string): SpanKind;
12
+ export declare function generateSpanName(endpoint: string, instance: any): string;
13
+ /**
14
+ * Drop-in replacement for ADK's tracer objects. Overrides
15
+ * `startActiveSpan` to yield the current span instead of creating a new one,
16
+ * letting OpenLIT own top-level spans while ADK's code still runs.
17
+ */
18
+ export declare class PassthroughTracer {
19
+ private _wrapped;
20
+ constructor(wrapped: any);
21
+ startActiveSpan(...args: any[]): any;
22
+ startSpan(...args: any[]): any;
23
+ }
24
+ export declare function resolveModelString(modelObj: any): string | null;
25
+ export declare function extractModelName(instance: any): string;
26
+ export declare function resolveServerInfo(instance?: any, modelName?: string | null): [string, number, string];
27
+ export declare function setCommonSpanAttributes(span: Span, operationType: string): void;
28
+ export declare function captureInputMessages(span: Span, llmRequest: any, captureContent: boolean): void;
29
+ export declare function captureOutputMessages(span: Span, llmResponse: any, captureContent: boolean, finishReason?: string): void;
30
+ export declare function captureEventOutput(span: Span, event: any, captureContent: boolean): void;
31
+ export interface TokenUsage {
32
+ inputTokens?: number;
33
+ outputTokens?: number;
34
+ reasoningTokens?: number;
35
+ cachedTokens?: number;
36
+ totalTokens?: number;
37
+ }
38
+ export declare function extractTokenUsage(llmResponse: any): TokenUsage;
39
+ export declare function enrichLlmSpan(span: Span, llmRequest: any, llmResponse: any, captureMessageContent: boolean): void;
40
+ export declare function enrichToolSpan(span: Span, tool: any, functionArgs: any, functionResponseEvent: any, captureMessageContent: boolean, error?: any): void;
41
+ export declare function enrichMergedToolSpan(span: Span, responseEventId: any, functionResponseEvent: any, captureMessageContent: boolean): void;
42
+ export declare function setRunnerAgentAttributes(span: Span, instance: any, endpoint: string): void;
43
+ export declare function setAgentAttributes(span: Span, instance: any): void;
44
+ export declare function processGoogleAdkResponse(span: Span, endpoint: string, instance: any, startTime: number, _captureMessageContent: boolean): void;
45
+ export declare function recordGoogleAdkMetrics(operationType: string, duration: number, requestModel: string, serverAddress: string, serverPort: number): void;