weflayr 0.24.0 → 0.26.1

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 (235) hide show
  1. package/README.md +2 -2
  2. package/dist/package.json +51 -0
  3. package/dist/{api → src/api}/generated/facade.gen.d.ts +86 -12
  4. package/dist/{api → src/api}/generated/facade.gen.js +4 -2
  5. package/dist/src/api/generated/index.d.ts +2 -0
  6. package/dist/{api → src/api}/generated/index.js +3 -1
  7. package/dist/{api → src/api}/generated/sdk.gen.d.ts +11 -3
  8. package/dist/{api → src/api}/generated/sdk.gen.js +34 -4
  9. package/{src/api/generated/types.gen.ts → dist/src/api/generated/types.gen.d.ts} +436 -153
  10. package/dist/{api → src/api}/makeEndpoint.js +1 -3
  11. package/dist/src/auto-instrument.d.ts +42 -0
  12. package/dist/src/auto-instrument.js +156 -0
  13. package/dist/src/index.d.ts +9 -0
  14. package/dist/src/index.js +49 -0
  15. package/dist/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.d.ts +20 -0
  16. package/dist/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +114 -0
  17. package/dist/src/instrumentation/anthropic/get_cache_config_telemetry.d.ts +28 -0
  18. package/dist/src/instrumentation/anthropic/get_cache_config_telemetry.js +92 -0
  19. package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.d.ts +25 -0
  20. package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.js +141 -0
  21. package/dist/src/instrumentation/anthropic/get_structured_output_schema_telemetry.d.ts +9 -0
  22. package/dist/src/instrumentation/anthropic/get_structured_output_schema_telemetry.js +17 -0
  23. package/dist/src/instrumentation/anthropic/get_tool_definitions_telemetry.d.ts +15 -0
  24. package/dist/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +50 -0
  25. package/dist/src/instrumentation/anthropic/set_telemetry_attributes.d.ts +15 -0
  26. package/dist/src/instrumentation/anthropic/set_telemetry_attributes.js +39 -0
  27. package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.d.ts +22 -0
  28. package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.js +97 -0
  29. package/dist/src/instrumentation/bedrock/get_cache_telemetry.d.ts +22 -0
  30. package/dist/src/instrumentation/bedrock/get_cache_telemetry.js +102 -0
  31. package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.d.ts +15 -0
  32. package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.js +91 -0
  33. package/dist/src/instrumentation/bedrock/get_model_id_telemetry.d.ts +21 -0
  34. package/dist/src/instrumentation/bedrock/get_model_id_telemetry.js +54 -0
  35. package/dist/src/instrumentation/bedrock/get_reasoning_output_telemetry.d.ts +19 -0
  36. package/dist/src/instrumentation/bedrock/get_reasoning_output_telemetry.js +81 -0
  37. package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.d.ts +27 -0
  38. package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +126 -0
  39. package/dist/src/instrumentation/bedrock/get_tool_call_output_telemetry.d.ts +17 -0
  40. package/dist/src/instrumentation/bedrock/get_tool_call_output_telemetry.js +85 -0
  41. package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.d.ts +15 -0
  42. package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.js +68 -0
  43. package/dist/src/instrumentation/bedrock/set_telemetry_attributes.d.ts +18 -0
  44. package/dist/src/instrumentation/bedrock/set_telemetry_attributes.js +47 -0
  45. package/dist/src/instrumentation/cohere/get_chat_telemetry.d.ts +23 -0
  46. package/dist/src/instrumentation/cohere/get_chat_telemetry.js +77 -0
  47. package/dist/src/instrumentation/cohere/get_embeddings_telemetry.d.ts +18 -0
  48. package/dist/src/instrumentation/cohere/get_embeddings_telemetry.js +88 -0
  49. package/dist/src/instrumentation/cohere/get_structured_output_schema_telemetry.d.ts +12 -0
  50. package/dist/src/instrumentation/cohere/get_structured_output_schema_telemetry.js +18 -0
  51. package/dist/src/instrumentation/cohere/get_tool_call_output_telemetry.d.ts +31 -0
  52. package/dist/src/instrumentation/cohere/get_tool_call_output_telemetry.js +106 -0
  53. package/dist/src/instrumentation/cohere/get_tool_definitions_telemetry.d.ts +27 -0
  54. package/dist/src/instrumentation/cohere/get_tool_definitions_telemetry.js +75 -0
  55. package/dist/src/instrumentation/cohere/set_telemetry_attributes.d.ts +17 -0
  56. package/dist/src/instrumentation/cohere/set_telemetry_attributes.js +44 -0
  57. package/dist/src/instrumentation/elevenlabs/full_instrumentation.d.ts +28 -0
  58. package/dist/src/instrumentation/elevenlabs/full_instrumentation.js +209 -0
  59. package/dist/src/instrumentation/google/get_audio_telemetry.d.ts +9 -0
  60. package/dist/src/instrumentation/google/get_audio_telemetry.js +28 -0
  61. package/dist/src/instrumentation/google/get_cache_operations_telemetry.d.ts +23 -0
  62. package/dist/src/instrumentation/google/get_cache_operations_telemetry.js +154 -0
  63. package/dist/src/instrumentation/google/get_cache_telemetry.d.ts +16 -0
  64. package/{src → dist/src}/instrumentation/google/get_cache_telemetry.js +18 -19
  65. package/dist/src/instrumentation/google/get_embeddings_telemetry.d.ts +12 -0
  66. package/dist/src/instrumentation/google/get_embeddings_telemetry.js +85 -0
  67. package/dist/src/instrumentation/google/get_provider_name.d.ts +11 -0
  68. package/{src → dist/src}/instrumentation/google/get_provider_name.js +11 -12
  69. package/{src/instrumentation/google/get_reasoning_telemetry.js → dist/src/instrumentation/google/get_reasoning_telemetry.d.ts} +1 -11
  70. package/dist/src/instrumentation/google/get_reasoning_telemetry.js +21 -0
  71. package/dist/src/instrumentation/google/get_structured_output_schema_telemetry.d.ts +12 -0
  72. package/dist/src/instrumentation/google/get_structured_output_schema_telemetry.js +19 -0
  73. package/dist/src/instrumentation/google/set_telemetry_attributes.d.ts +18 -0
  74. package/dist/src/instrumentation/google/set_telemetry_attributes.js +98 -0
  75. package/dist/src/instrumentation/openai/get_audio_telemetry.d.ts +25 -0
  76. package/dist/src/instrumentation/openai/get_audio_telemetry.js +123 -0
  77. package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.d.ts +35 -0
  78. package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.js +148 -0
  79. package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.d.ts +27 -0
  80. package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +72 -0
  81. package/dist/src/instrumentation/openai/get_cache_config_telemetry.d.ts +28 -0
  82. package/dist/src/instrumentation/openai/get_cache_config_telemetry.js +91 -0
  83. package/dist/src/instrumentation/openai/get_embeddings_telemetry.d.ts +18 -0
  84. package/dist/src/instrumentation/openai/get_embeddings_telemetry.js +86 -0
  85. package/dist/src/instrumentation/openai/get_streaming_usage.d.ts +21 -0
  86. package/dist/src/instrumentation/openai/get_streaming_usage.js +74 -0
  87. package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.d.ts +12 -0
  88. package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.js +20 -0
  89. package/dist/src/instrumentation/openai/set_telemetry_attributes.d.ts +17 -0
  90. package/dist/src/instrumentation/openai/set_telemetry_attributes.js +47 -0
  91. package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.d.ts +35 -0
  92. package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.js +76 -0
  93. package/dist/src/instrumentation/vercel/full_instrumentation.d.ts +3 -0
  94. package/dist/src/instrumentation/vercel/full_instrumentation.js +54 -0
  95. package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.d.ts +22 -0
  96. package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.js +66 -0
  97. package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.d.ts +24 -0
  98. package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.js +84 -0
  99. package/dist/src/logger.d.ts +1 -0
  100. package/dist/src/logger.js +6 -0
  101. package/dist/src/otel/exporter.d.ts +19 -0
  102. package/dist/src/otel/exporter.js +94 -0
  103. package/dist/src/otel/propagation.d.ts +46 -0
  104. package/dist/src/otel/propagation.js +110 -0
  105. package/dist/src/otel/span-filter.d.ts +3 -0
  106. package/dist/src/otel/span-filter.js +61 -0
  107. package/dist/src/otel/span-processor.d.ts +55 -0
  108. package/dist/src/otel/span-processor.js +169 -0
  109. package/dist/src/otel/vercel-ai-sdk-span-filter.d.ts +12 -0
  110. package/dist/src/otel/vercel-ai-sdk-span-filter.js +88 -0
  111. package/dist/src/setup.d.ts +50 -0
  112. package/dist/src/setup.js +155 -0
  113. package/package.json +12 -5
  114. package/.prettierignore +0 -2
  115. package/.prettierrc.json +0 -7
  116. package/LICENSE-MIT +0 -21
  117. package/NOTICE +0 -12
  118. package/dist/api/generated/index.d.ts +0 -2
  119. package/dist/api/generated/types.gen.d.ts +0 -1005
  120. package/eslint.config.mjs +0 -36
  121. package/index.d.ts +0 -170
  122. package/openapi-ts.config.mjs +0 -9
  123. package/scripts/generate_facade.mjs +0 -86
  124. package/src/api/caseConversion.ts +0 -58
  125. package/src/api/generated/client/client.gen.ts +0 -277
  126. package/src/api/generated/client/index.ts +0 -27
  127. package/src/api/generated/client/types.gen.ts +0 -218
  128. package/src/api/generated/client/utils.gen.ts +0 -316
  129. package/src/api/generated/client.gen.ts +0 -16
  130. package/src/api/generated/core/auth.gen.ts +0 -48
  131. package/src/api/generated/core/bodySerializer.gen.ts +0 -82
  132. package/src/api/generated/core/params.gen.ts +0 -178
  133. package/src/api/generated/core/pathSerializer.gen.ts +0 -171
  134. package/src/api/generated/core/queryKeySerializer.gen.ts +0 -117
  135. package/src/api/generated/core/serverSentEvents.gen.ts +0 -242
  136. package/src/api/generated/core/types.gen.ts +0 -110
  137. package/src/api/generated/core/utils.gen.ts +0 -140
  138. package/src/api/generated/facade.gen.ts +0 -104
  139. package/src/api/generated/index.ts +0 -4
  140. package/src/api/generated/sdk.gen.ts +0 -175
  141. package/src/api/index.ts +0 -45
  142. package/src/api/makeEndpoint.ts +0 -54
  143. package/src/auto-instrument.js +0 -172
  144. package/src/index.js +0 -19
  145. package/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +0 -118
  146. package/src/instrumentation/anthropic/get_cache_config_telemetry.js +0 -90
  147. package/src/instrumentation/anthropic/get_streaming_stop_reason_telemetry.js +0 -121
  148. package/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +0 -55
  149. package/src/instrumentation/anthropic/set_telemetry_attributes.js +0 -39
  150. package/src/instrumentation/bedrock/get_cache_config_telemetry.js +0 -106
  151. package/src/instrumentation/bedrock/get_cache_telemetry.js +0 -109
  152. package/src/instrumentation/bedrock/get_input_message_content_telemetry.js +0 -94
  153. package/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +0 -87
  154. package/src/instrumentation/bedrock/set_telemetry_attributes.js +0 -40
  155. package/src/instrumentation/cohere/get_chat_telemetry.js +0 -88
  156. package/src/instrumentation/cohere/get_embeddings_telemetry.js +0 -107
  157. package/src/instrumentation/cohere/set_telemetry_attributes.js +0 -32
  158. package/src/instrumentation/elevenlabs/full_instrumentation.js +0 -236
  159. package/src/instrumentation/google/get_audio_telemetry.js +0 -30
  160. package/src/instrumentation/google/get_cache_operations_telemetry.js +0 -171
  161. package/src/instrumentation/google/get_embeddings_telemetry.js +0 -99
  162. package/src/instrumentation/google/set_telemetry_attributes.js +0 -104
  163. package/src/instrumentation/openai/get_audio_telemetry.js +0 -149
  164. package/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +0 -71
  165. package/src/instrumentation/openai/get_cache_config_telemetry.js +0 -63
  166. package/src/instrumentation/openai/get_embeddings_telemetry.js +0 -107
  167. package/src/instrumentation/openai/get_streaming_usage.js +0 -81
  168. package/src/instrumentation/openai/set_telemetry_attributes.js +0 -41
  169. package/src/instrumentation/vercel/full_instrumentation.js +0 -52
  170. package/src/instrumentation/vercel/get_cache_creation_telemetry.js +0 -70
  171. package/src/logger.js +0 -8
  172. package/src/otel/exporter.js +0 -108
  173. package/src/otel/propagation.js +0 -146
  174. package/src/otel/span-filter.js +0 -69
  175. package/src/otel/span-processor.js +0 -170
  176. package/src/otel/vercel-ai-sdk-span-filter.js +0 -79
  177. package/src/setup.js +0 -167
  178. package/tests/api/index.test.js +0 -437
  179. package/tests/index.test.js +0 -884
  180. package/tests/instrumentation/anthropic/get_cache_and_reasoning_telemetry.test.js +0 -181
  181. package/tests/instrumentation/anthropic/get_cache_config_telemetry.test.js +0 -92
  182. package/tests/instrumentation/anthropic/get_streaming_stop_reason_telemetry.test.js +0 -117
  183. package/tests/instrumentation/anthropic/get_tool_definitions_telemetry.test.js +0 -97
  184. package/tests/instrumentation/bedrock/get_cache_config_telemetry.test.js +0 -107
  185. package/tests/instrumentation/bedrock/get_cache_telemetry.test.js +0 -118
  186. package/tests/instrumentation/bedrock/get_input_message_content_telemetry.test.js +0 -89
  187. package/tests/instrumentation/bedrock/get_streaming_output_message_telemetry.test.js +0 -87
  188. package/tests/instrumentation/cohere/get_chat_telemetry.test.js +0 -148
  189. package/tests/instrumentation/cohere/get_embeddings_telemetry.test.js +0 -132
  190. package/tests/instrumentation/elevenlabs/full_instrumentation.test.js +0 -258
  191. package/tests/instrumentation/google/get_cache_operations_telemetry.test.js +0 -130
  192. package/tests/instrumentation/google/get_embeddings_telemetry.test.js +0 -128
  193. package/tests/instrumentation/google/get_reasoning_telemetry.test.js +0 -41
  194. package/tests/instrumentation/google/set_telemetry_attributes.test.js +0 -219
  195. package/tests/instrumentation/openai/get_audio_telemetry.test.js +0 -170
  196. package/tests/instrumentation/openai/get_cache_and_reasoning_telemetry.test.js +0 -83
  197. package/tests/instrumentation/openai/get_cache_config_telemetry.test.js +0 -83
  198. package/tests/instrumentation/openai/get_embeddings_telemetry.test.js +0 -145
  199. package/tests/instrumentation/openai/get_streaming_usage.test.js +0 -105
  200. package/tests/instrumentation/vercel/full_instrumentation.test.js +0 -16
  201. package/tests/instrumentation/vercel/get_cache_creation_telemetry.test.js +0 -96
  202. package/tests/otel/vercel-ai-sdk-span-filter.test.js +0 -159
  203. package/tsconfig.json +0 -18
  204. /package/dist/{api → src/api}/caseConversion.d.ts +0 -0
  205. /package/dist/{api → src/api}/caseConversion.js +0 -0
  206. /package/dist/{api → src/api}/generated/client/client.gen.d.ts +0 -0
  207. /package/dist/{api → src/api}/generated/client/client.gen.js +0 -0
  208. /package/dist/{api → src/api}/generated/client/index.d.ts +0 -0
  209. /package/dist/{api → src/api}/generated/client/index.js +0 -0
  210. /package/dist/{api → src/api}/generated/client/types.gen.d.ts +0 -0
  211. /package/dist/{api → src/api}/generated/client/types.gen.js +0 -0
  212. /package/dist/{api → src/api}/generated/client/utils.gen.d.ts +0 -0
  213. /package/dist/{api → src/api}/generated/client/utils.gen.js +0 -0
  214. /package/dist/{api → src/api}/generated/client.gen.d.ts +0 -0
  215. /package/dist/{api → src/api}/generated/client.gen.js +0 -0
  216. /package/dist/{api → src/api}/generated/core/auth.gen.d.ts +0 -0
  217. /package/dist/{api → src/api}/generated/core/auth.gen.js +0 -0
  218. /package/dist/{api → src/api}/generated/core/bodySerializer.gen.d.ts +0 -0
  219. /package/dist/{api → src/api}/generated/core/bodySerializer.gen.js +0 -0
  220. /package/dist/{api → src/api}/generated/core/params.gen.d.ts +0 -0
  221. /package/dist/{api → src/api}/generated/core/params.gen.js +0 -0
  222. /package/dist/{api → src/api}/generated/core/pathSerializer.gen.d.ts +0 -0
  223. /package/dist/{api → src/api}/generated/core/pathSerializer.gen.js +0 -0
  224. /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.d.ts +0 -0
  225. /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.js +0 -0
  226. /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.d.ts +0 -0
  227. /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.js +0 -0
  228. /package/dist/{api → src/api}/generated/core/types.gen.d.ts +0 -0
  229. /package/dist/{api → src/api}/generated/core/types.gen.js +0 -0
  230. /package/dist/{api → src/api}/generated/core/utils.gen.d.ts +0 -0
  231. /package/dist/{api → src/api}/generated/core/utils.gen.js +0 -0
  232. /package/dist/{api → src/api}/generated/types.gen.js +0 -0
  233. /package/dist/{api → src/api}/index.d.ts +0 -0
  234. /package/dist/{api → src/api}/index.js +0 -0
  235. /package/dist/{api → src/api}/makeEndpoint.d.ts +0 -0
@@ -1,105 +0,0 @@
1
- 'use strict';
2
-
3
- // Tests for the OpenAI streamed token-usage complement. It wraps the primary
4
- // instrumentor's `_streamingWrapPromise` so the streamed usage chunk's counts land
5
- // on the span as gen_ai.usage.* attributes.
6
-
7
- const test = require('node:test');
8
- const assert = require('node:assert/strict');
9
-
10
- const {
11
- OpenAIStreamingUsageInstrumentor,
12
- } = require('../../../src/instrumentation/openai/get_streaming_usage');
13
-
14
- function fakeSpan() {
15
- const attrs = {};
16
- return {
17
- attrs,
18
- isRecording: () => true,
19
- setAttribute(key, value) {
20
- attrs[key] = value;
21
- },
22
- };
23
- }
24
-
25
- test('backfills token usage from the streamed usage chunk', async () => {
26
- const instrumentation = {
27
- _streamingWrapPromise() {
28
- return (async function* () {
29
- yield { choices: [{ delta: { content: 'hi' } }] };
30
- yield { usage: { prompt_tokens: 12, completion_tokens: 3, total_tokens: 15 } };
31
- })();
32
- },
33
- };
34
- new OpenAIStreamingUsageInstrumentor().instrument(instrumentation);
35
-
36
- const span = fakeSpan();
37
- const stream = instrumentation._streamingWrapPromise({ span });
38
- for await (const _chunk of stream) {
39
- void _chunk;
40
- }
41
-
42
- assert.equal(span.attrs['gen_ai.usage.input_tokens'], 12);
43
- assert.equal(span.attrs['gen_ai.usage.output_tokens'], 3);
44
- assert.equal(span.attrs['gen_ai.usage.total_tokens'], 15);
45
- });
46
-
47
- test('backfills cached-prompt tokens from the streamed usage chunk', async () => {
48
- const instrumentation = {
49
- _streamingWrapPromise() {
50
- return (async function* () {
51
- yield {
52
- usage: {
53
- prompt_tokens: 1600,
54
- completion_tokens: 2,
55
- total_tokens: 1602,
56
- prompt_tokens_details: { cached_tokens: 1536 },
57
- },
58
- };
59
- })();
60
- },
61
- };
62
- new OpenAIStreamingUsageInstrumentor().instrument(instrumentation);
63
-
64
- const span = fakeSpan();
65
- for await (const _chunk of instrumentation._streamingWrapPromise({ span })) {
66
- void _chunk;
67
- }
68
-
69
- assert.equal(span.attrs['gen_ai.usage.cache_read_input_tokens'], 1536);
70
- });
71
-
72
- test('re-yields every stream chunk unchanged — no telemetry collision with the payload', async () => {
73
- const emitted = [
74
- { choices: [{ delta: { content: 'hel' } }] },
75
- { choices: [{ delta: { content: 'lo' } }] },
76
- { usage: { prompt_tokens: 12, completion_tokens: 3, total_tokens: 15 } },
77
- ];
78
- const instrumentation = {
79
- _streamingWrapPromise() {
80
- return (async function* () {
81
- for (const chunk of emitted) yield chunk;
82
- })();
83
- },
84
- };
85
- new OpenAIStreamingUsageInstrumentor().instrument(instrumentation);
86
-
87
- const span = fakeSpan();
88
- const collected = [];
89
- for await (const chunk of instrumentation._streamingWrapPromise({ span })) {
90
- collected.push(chunk);
91
- }
92
-
93
- // Same count, order, and object identity: backfillUsage re-yields each chunk by
94
- // reference without copying or mutating it.
95
- assert.equal(collected.length, emitted.length);
96
- collected.forEach((chunk, index) => assert.equal(chunk, emitted[index]));
97
- // …while still backfilling usage off the trailing chunk.
98
- assert.equal(span.attrs['gen_ai.usage.output_tokens'], 3);
99
- });
100
-
101
- test('is a no-op when the instrumentor has no _streamingWrapPromise', () => {
102
- const instrumentation = {};
103
- new OpenAIStreamingUsageInstrumentor().instrument(instrumentation);
104
- assert.equal(instrumentation._streamingWrapPromise, undefined);
105
- });
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- const test = require('node:test');
4
- const assert = require('node:assert/strict');
5
-
6
- const {
7
- VercelAiSdkInstrumentor,
8
- } = require('../../../src/instrumentation/vercel/full_instrumentation');
9
-
10
- // The `ai` / `@ai-sdk/otel` packages are app dependencies (not installed in
11
- // this repo), so instrument() must fail with an actionable install message.
12
- // The success path (registerTelemetry wiring) is covered by the vercel e2e
13
- // ingestion scenario.
14
- test('instrument() without the ai packages installed throws an install hint', () => {
15
- assert.throws(() => new VercelAiSdkInstrumentor().instrument(), /npm install ai @ai-sdk\/otel/);
16
- });
@@ -1,96 +0,0 @@
1
- 'use strict';
2
-
3
- // Tests for the ai >= 7 cache-write capture: the telemetry dispatcher's
4
- // onLanguageModelCallEnd reads the raw `usage.cache_creation` off the event's
5
- // raw provider usage and stamps it verbatim on the still-open model-call span
6
- // (reached through the integration's call state) before ending it.
7
-
8
- const test = require('node:test');
9
- const assert = require('node:assert/strict');
10
-
11
- const {
12
- VercelCacheCreationInstrumentor,
13
- cacheCreationFromRawUsage,
14
- } = require('../../../src/instrumentation/vercel/get_cache_creation_telemetry');
15
-
16
- const RAW_ANTHROPIC_USAGE = {
17
- input_tokens: 7,
18
- cache_creation_input_tokens: 6053,
19
- cache_creation: { ephemeral_5m_input_tokens: 6053, ephemeral_1h_input_tokens: 0 },
20
- };
21
-
22
- function makeFakeSpan() {
23
- const attributes = {};
24
- return {
25
- attributes,
26
- setAttribute(key, value) {
27
- attributes[key] = value;
28
- },
29
- };
30
- }
31
-
32
- function makeInstrumentedDispatcher() {
33
- const span = makeFakeSpan();
34
- const endedEvents = [];
35
- const dispatcher = {
36
- onLanguageModelCallEnd(event) {
37
- endedEvents.push(event);
38
- },
39
- getCallState(callId) {
40
- return callId === 'call-1' ? { inferenceSpan: span } : undefined;
41
- },
42
- };
43
- const instrumentor = new VercelCacheCreationInstrumentor();
44
- instrumentor.instrument(dispatcher);
45
- return { dispatcher, span, endedEvents, instrumentor };
46
- }
47
-
48
- test('stamps the raw cache_creation from the provider usage on the model-call span', () => {
49
- const { dispatcher, span, endedEvents } = makeInstrumentedDispatcher();
50
-
51
- dispatcher.onLanguageModelCallEnd({
52
- callId: 'call-1',
53
- usage: { inputTokens: 6060, outputTokens: 5, raw: RAW_ANTHROPIC_USAGE },
54
- });
55
-
56
- assert.deepEqual(
57
- JSON.parse(span.attributes['weflayr.cache.creation']),
58
- RAW_ANTHROPIC_USAGE.cache_creation
59
- );
60
- // The original handler still runs (it ends the span).
61
- assert.equal(endedEvents.length, 1);
62
- });
63
-
64
- test('stamps nothing without a cache_creation in the raw usage', () => {
65
- const { dispatcher, span } = makeInstrumentedDispatcher();
66
-
67
- dispatcher.onLanguageModelCallEnd({
68
- callId: 'call-1',
69
- usage: { inputTokens: 13, outputTokens: 5, raw: { input_tokens: 13 } },
70
- });
71
-
72
- assert.ok(!('weflayr.cache.creation' in span.attributes));
73
- });
74
-
75
- test('cacheCreationFromRawUsage drops an all-zero cache_creation', () => {
76
- assert.deepEqual(
77
- cacheCreationFromRawUsage({
78
- cache_creation: { ephemeral_5m_input_tokens: 4000, ephemeral_1h_input_tokens: 1300 },
79
- }),
80
- { ephemeral_5m_input_tokens: 4000, ephemeral_1h_input_tokens: 1300 }
81
- );
82
- assert.equal(
83
- cacheCreationFromRawUsage({
84
- cache_creation: { ephemeral_5m_input_tokens: 0, ephemeral_1h_input_tokens: 0 },
85
- }),
86
- undefined
87
- );
88
- assert.equal(cacheCreationFromRawUsage(undefined), undefined);
89
- });
90
-
91
- test('uninstrument restores the original handler', () => {
92
- const { dispatcher, instrumentor } = makeInstrumentedDispatcher();
93
- assert.equal(dispatcher.onLanguageModelCallEnd.name, 'onLanguageModelCallEndWithCacheCreation');
94
- instrumentor.uninstrument();
95
- assert.equal(dispatcher.onLanguageModelCallEnd.name, 'onLanguageModelCallEnd');
96
- });
@@ -1,159 +0,0 @@
1
- 'use strict';
2
-
3
- // The Vercel AI SDK emits aggregate spans around each model call (see
4
- // src/otel/vercel-ai-sdk-span-filter.js). These tests drive real spans through
5
- // the WeflayrSpanProcessor and assert exactly one span per model call is
6
- // exported, for both the ai >= 7 semconv shape and the legacy ai.* shape.
7
-
8
- const test = require('node:test');
9
- const assert = require('node:assert/strict');
10
- const { context, trace } = require('@opentelemetry/api');
11
- const { BasicTracerProvider, InMemorySpanExporter } = require('@opentelemetry/sdk-trace-base');
12
-
13
- const { WeflayrSpanProcessor } = require('../../src/otel/span-processor');
14
-
15
- function buildProviderWithExporter() {
16
- const exporter = new InMemorySpanExporter();
17
- const provider = new BasicTracerProvider({
18
- spanProcessors: [new WeflayrSpanProcessor({ exporter, exportMode: 'immediate' })],
19
- });
20
- return { exporter, provider };
21
- }
22
-
23
- function startChildSpan(tracer, parentSpan, name, attributes) {
24
- const parentContext = trace.setSpan(context.active(), parentSpan);
25
- return tracer.startSpan(name, { attributes }, parentContext);
26
- }
27
-
28
- test('semconv shape: only the chat span is exported, not invoke_agent/step/tool', () => {
29
- const { exporter, provider } = buildProviderWithExporter();
30
- const tracer = provider.getTracer('gen_ai');
31
-
32
- const invokeAgent = tracer.startSpan('invoke_agent openai/gpt-4o-mini', {
33
- attributes: {
34
- 'gen_ai.operation.name': 'invoke_agent',
35
- 'gen_ai.usage.input_tokens': 50,
36
- 'gen_ai.usage.output_tokens': 15,
37
- },
38
- });
39
- const step = startChildSpan(tracer, invokeAgent, 'step 1', {
40
- 'gen_ai.operation.name': 'agent_step',
41
- });
42
- const chat = startChildSpan(tracer, step, 'chat openai/gpt-4o-mini', {
43
- 'gen_ai.operation.name': 'chat',
44
- 'gen_ai.usage.input_tokens': 50,
45
- 'gen_ai.usage.output_tokens': 15,
46
- });
47
- const tool = startChildSpan(tracer, step, 'execute_tool get_weather', {
48
- 'gen_ai.operation.name': 'execute_tool',
49
- });
50
-
51
- chat.end();
52
- tool.end();
53
- step.end();
54
- invokeAgent.end();
55
-
56
- const exported = exporter.getFinishedSpans();
57
- assert.equal(exported.length, 1);
58
- assert.equal(exported[0].name, 'chat openai/gpt-4o-mini');
59
- });
60
-
61
- test('semconv shape: nested embeddings span is dropped, the outer one is exported', () => {
62
- const { exporter, provider } = buildProviderWithExporter();
63
- const tracer = provider.getTracer('gen_ai');
64
-
65
- const outerEmbeddings = tracer.startSpan('embeddings openai/text-embedding-3-small', {
66
- attributes: {
67
- 'gen_ai.operation.name': 'embeddings',
68
- 'gen_ai.usage.input_tokens': 2,
69
- },
70
- });
71
- const modelCallEmbeddings = startChildSpan(
72
- tracer,
73
- outerEmbeddings,
74
- 'embeddings openai/text-embedding-3-small',
75
- {
76
- 'gen_ai.operation.name': 'embeddings',
77
- 'gen_ai.usage.input_tokens': 2,
78
- }
79
- );
80
-
81
- modelCallEmbeddings.end();
82
- outerEmbeddings.end();
83
-
84
- const exported = exporter.getFinishedSpans();
85
- assert.equal(exported.length, 1);
86
- assert.equal(exported[0].spanContext().spanId, outerEmbeddings.spanContext().spanId);
87
- });
88
-
89
- test('legacy shape: only ai.<fn>.do* spans are exported', () => {
90
- const { exporter, provider } = buildProviderWithExporter();
91
- const tracer = provider.getTracer('ai');
92
-
93
- const outer = tracer.startSpan('ai.streamText', {
94
- attributes: { 'ai.usage.inputTokens': 100 },
95
- });
96
- const doStream = startChildSpan(tracer, outer, 'ai.streamText.doStream', {
97
- 'gen_ai.usage.input_tokens': 100,
98
- });
99
- const toolCall = startChildSpan(tracer, outer, 'ai.toolCall', {});
100
- const doEmbed = tracer.startSpan('ai.embed.doEmbed', {
101
- attributes: { 'gen_ai.usage.input_tokens': 1 },
102
- });
103
-
104
- doStream.end();
105
- toolCall.end();
106
- doEmbed.end();
107
- outer.end();
108
-
109
- const exported = exporter.getFinishedSpans().map((span) => span.name);
110
- assert.deepEqual(exported.sort(), ['ai.embed.doEmbed', 'ai.streamText.doStream']);
111
- });
112
-
113
- test('gateway provider id gets the weflayr override, direct providers do not', () => {
114
- const { exporter, provider } = buildProviderWithExporter();
115
- const tracer = provider.getTracer('gen_ai');
116
-
117
- const gatewayChat = tracer.startSpan('chat openai/gpt-4o-mini', {
118
- attributes: { 'gen_ai.operation.name': 'chat', 'gen_ai.provider.name': 'gateway' },
119
- });
120
- gatewayChat.end();
121
- const directChat = tracer.startSpan('chat gpt-4o-mini', {
122
- attributes: { 'gen_ai.operation.name': 'chat', 'gen_ai.provider.name': 'openai' },
123
- });
124
- directChat.end();
125
-
126
- const [gatewayExported, directExported] = exporter.getFinishedSpans();
127
- assert.equal(gatewayExported.attributes['weflayr.provider_name'], 'vercel_ai_gateway');
128
- assert.equal(directExported.attributes['weflayr.provider_name'], undefined);
129
- });
130
-
131
- test('gateway provider id does not overwrite a propagateMetadata providerName', () => {
132
- const { exporter, provider } = buildProviderWithExporter();
133
- const tracer = provider.getTracer('gen_ai');
134
-
135
- const chat = tracer.startSpan('chat openai/gpt-4o-mini', {
136
- attributes: {
137
- 'gen_ai.operation.name': 'chat',
138
- 'gen_ai.provider.name': 'gateway',
139
- 'weflayr.provider_name': 'openai',
140
- },
141
- });
142
- chat.end();
143
-
144
- assert.equal(exporter.getFinishedSpans()[0].attributes['weflayr.provider_name'], 'openai');
145
- });
146
-
147
- test('non-Vercel scopes still go through the default export filter', () => {
148
- const { exporter, provider } = buildProviderWithExporter();
149
-
150
- const llmSpan = provider
151
- .getTracer('@traceloop/instrumentation-openai')
152
- .startSpan('openai.chat', { attributes: { 'gen_ai.system': 'openai' } });
153
- llmSpan.end();
154
- const unrelatedSpan = provider.getTracer('my-app').startSpan('http request');
155
- unrelatedSpan.end();
156
-
157
- const exported = exporter.getFinishedSpans().map((span) => span.name);
158
- assert.deepEqual(exported, ['openai.chat']);
159
- });
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- // First TypeScript module of the SDK: only src/api is compiled (to dist/);
3
- // the rest of src stays plain JavaScript until it is migrated.
4
- "compilerOptions": {
5
- "target": "ES2022",
6
- "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
- "module": "NodeNext",
8
- "moduleResolution": "NodeNext",
9
- "rootDir": "src",
10
- "outDir": "dist",
11
- "declaration": true,
12
- "strict": true,
13
- "esModuleInterop": true,
14
- "skipLibCheck": true,
15
- "types": ["node"]
16
- },
17
- "include": ["src/api"]
18
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes