weflayr 0.23.0 → 0.26.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 (225) hide show
  1. package/README.md +2 -2
  2. package/dist/{api → src/api}/generated/facade.gen.d.ts +163 -12
  3. package/dist/{api → src/api}/generated/facade.gen.js +10 -2
  4. package/dist/src/api/generated/index.d.ts +2 -0
  5. package/dist/{api → src/api}/generated/index.js +9 -1
  6. package/dist/{api → src/api}/generated/sdk.gen.d.ts +35 -3
  7. package/dist/{api → src/api}/generated/sdk.gen.js +88 -4
  8. package/{src/api/generated/types.gen.ts → dist/src/api/generated/types.gen.d.ts} +692 -116
  9. package/dist/{api → src/api}/makeEndpoint.js +1 -3
  10. package/dist/src/auto-instrument.d.ts +42 -0
  11. package/dist/src/auto-instrument.js +156 -0
  12. package/dist/src/index.d.ts +9 -0
  13. package/dist/src/index.js +49 -0
  14. package/dist/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.d.ts +20 -0
  15. package/dist/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +114 -0
  16. package/dist/src/instrumentation/anthropic/get_cache_config_telemetry.d.ts +28 -0
  17. package/dist/src/instrumentation/anthropic/get_cache_config_telemetry.js +92 -0
  18. package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.d.ts +25 -0
  19. package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.js +141 -0
  20. package/dist/src/instrumentation/anthropic/get_structured_output_schema_telemetry.d.ts +9 -0
  21. package/dist/src/instrumentation/anthropic/get_structured_output_schema_telemetry.js +17 -0
  22. package/dist/src/instrumentation/anthropic/get_tool_definitions_telemetry.d.ts +15 -0
  23. package/dist/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +50 -0
  24. package/dist/src/instrumentation/anthropic/set_telemetry_attributes.d.ts +15 -0
  25. package/dist/src/instrumentation/anthropic/set_telemetry_attributes.js +39 -0
  26. package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.d.ts +22 -0
  27. package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.js +97 -0
  28. package/dist/src/instrumentation/bedrock/get_cache_telemetry.d.ts +22 -0
  29. package/dist/src/instrumentation/bedrock/get_cache_telemetry.js +102 -0
  30. package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.d.ts +15 -0
  31. package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.js +91 -0
  32. package/dist/src/instrumentation/bedrock/get_model_id_telemetry.d.ts +21 -0
  33. package/dist/src/instrumentation/bedrock/get_model_id_telemetry.js +54 -0
  34. package/dist/src/instrumentation/bedrock/get_reasoning_output_telemetry.d.ts +19 -0
  35. package/dist/src/instrumentation/bedrock/get_reasoning_output_telemetry.js +81 -0
  36. package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.d.ts +27 -0
  37. package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +126 -0
  38. package/dist/src/instrumentation/bedrock/get_tool_call_output_telemetry.d.ts +17 -0
  39. package/dist/src/instrumentation/bedrock/get_tool_call_output_telemetry.js +85 -0
  40. package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.d.ts +15 -0
  41. package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.js +68 -0
  42. package/dist/src/instrumentation/bedrock/set_telemetry_attributes.d.ts +18 -0
  43. package/dist/src/instrumentation/bedrock/set_telemetry_attributes.js +47 -0
  44. package/dist/src/instrumentation/cohere/get_chat_telemetry.d.ts +23 -0
  45. package/dist/src/instrumentation/cohere/get_chat_telemetry.js +77 -0
  46. package/dist/src/instrumentation/cohere/get_embeddings_telemetry.d.ts +18 -0
  47. package/dist/src/instrumentation/cohere/get_embeddings_telemetry.js +88 -0
  48. package/dist/src/instrumentation/cohere/get_structured_output_schema_telemetry.d.ts +12 -0
  49. package/dist/src/instrumentation/cohere/get_structured_output_schema_telemetry.js +18 -0
  50. package/dist/src/instrumentation/cohere/get_tool_call_output_telemetry.d.ts +31 -0
  51. package/dist/src/instrumentation/cohere/get_tool_call_output_telemetry.js +106 -0
  52. package/dist/src/instrumentation/cohere/get_tool_definitions_telemetry.d.ts +27 -0
  53. package/dist/src/instrumentation/cohere/get_tool_definitions_telemetry.js +75 -0
  54. package/dist/src/instrumentation/cohere/set_telemetry_attributes.d.ts +17 -0
  55. package/dist/src/instrumentation/cohere/set_telemetry_attributes.js +44 -0
  56. package/dist/src/instrumentation/elevenlabs/full_instrumentation.d.ts +28 -0
  57. package/dist/src/instrumentation/elevenlabs/full_instrumentation.js +209 -0
  58. package/dist/src/instrumentation/google/get_audio_telemetry.d.ts +9 -0
  59. package/dist/src/instrumentation/google/get_audio_telemetry.js +28 -0
  60. package/dist/src/instrumentation/google/get_cache_operations_telemetry.d.ts +23 -0
  61. package/dist/src/instrumentation/google/get_cache_operations_telemetry.js +154 -0
  62. package/dist/src/instrumentation/google/get_cache_telemetry.d.ts +16 -0
  63. package/dist/src/instrumentation/google/get_cache_telemetry.js +38 -0
  64. package/dist/src/instrumentation/google/get_embeddings_telemetry.d.ts +12 -0
  65. package/dist/src/instrumentation/google/get_embeddings_telemetry.js +85 -0
  66. package/dist/src/instrumentation/google/get_provider_name.d.ts +11 -0
  67. package/{src → dist/src}/instrumentation/google/get_provider_name.js +11 -12
  68. package/{src/instrumentation/google/get_reasoning_telemetry.js → dist/src/instrumentation/google/get_reasoning_telemetry.d.ts} +1 -11
  69. package/dist/src/instrumentation/google/get_reasoning_telemetry.js +21 -0
  70. package/dist/src/instrumentation/google/get_structured_output_schema_telemetry.d.ts +12 -0
  71. package/dist/src/instrumentation/google/get_structured_output_schema_telemetry.js +19 -0
  72. package/dist/src/instrumentation/google/set_telemetry_attributes.d.ts +18 -0
  73. package/dist/src/instrumentation/google/set_telemetry_attributes.js +98 -0
  74. package/dist/src/instrumentation/openai/get_audio_telemetry.d.ts +25 -0
  75. package/dist/src/instrumentation/openai/get_audio_telemetry.js +123 -0
  76. package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.d.ts +35 -0
  77. package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.js +148 -0
  78. package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.d.ts +27 -0
  79. package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +72 -0
  80. package/dist/src/instrumentation/openai/get_cache_config_telemetry.d.ts +28 -0
  81. package/dist/src/instrumentation/openai/get_cache_config_telemetry.js +91 -0
  82. package/dist/src/instrumentation/openai/get_embeddings_telemetry.d.ts +18 -0
  83. package/dist/src/instrumentation/openai/get_embeddings_telemetry.js +86 -0
  84. package/dist/src/instrumentation/openai/get_streaming_usage.d.ts +21 -0
  85. package/dist/src/instrumentation/openai/get_streaming_usage.js +74 -0
  86. package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.d.ts +12 -0
  87. package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.js +20 -0
  88. package/dist/src/instrumentation/openai/set_telemetry_attributes.d.ts +17 -0
  89. package/dist/src/instrumentation/openai/set_telemetry_attributes.js +47 -0
  90. package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.d.ts +35 -0
  91. package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.js +76 -0
  92. package/dist/src/instrumentation/vercel/full_instrumentation.d.ts +3 -0
  93. package/dist/src/instrumentation/vercel/full_instrumentation.js +54 -0
  94. package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.d.ts +22 -0
  95. package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.js +66 -0
  96. package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.d.ts +24 -0
  97. package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.js +84 -0
  98. package/dist/src/logger.d.ts +1 -0
  99. package/dist/src/logger.js +6 -0
  100. package/dist/src/otel/exporter.d.ts +19 -0
  101. package/dist/src/otel/exporter.js +94 -0
  102. package/dist/src/otel/propagation.d.ts +46 -0
  103. package/dist/src/otel/propagation.js +110 -0
  104. package/dist/src/otel/span-filter.d.ts +3 -0
  105. package/dist/src/otel/span-filter.js +61 -0
  106. package/dist/src/otel/span-processor.d.ts +55 -0
  107. package/dist/src/otel/span-processor.js +169 -0
  108. package/dist/src/otel/vercel-ai-sdk-span-filter.d.ts +12 -0
  109. package/dist/src/otel/vercel-ai-sdk-span-filter.js +88 -0
  110. package/dist/src/setup.d.ts +50 -0
  111. package/dist/src/setup.js +155 -0
  112. package/package.json +11 -5
  113. package/.prettierignore +0 -2
  114. package/.prettierrc.json +0 -7
  115. package/LICENSE-MIT +0 -21
  116. package/NOTICE +0 -12
  117. package/dist/api/generated/index.d.ts +0 -2
  118. package/dist/api/generated/types.gen.d.ts +0 -749
  119. package/eslint.config.mjs +0 -36
  120. package/index.d.ts +0 -167
  121. package/openapi-ts.config.mjs +0 -9
  122. package/scripts/generate_facade.mjs +0 -86
  123. package/src/api/caseConversion.ts +0 -58
  124. package/src/api/generated/client/client.gen.ts +0 -277
  125. package/src/api/generated/client/index.ts +0 -27
  126. package/src/api/generated/client/types.gen.ts +0 -218
  127. package/src/api/generated/client/utils.gen.ts +0 -316
  128. package/src/api/generated/client.gen.ts +0 -16
  129. package/src/api/generated/core/auth.gen.ts +0 -48
  130. package/src/api/generated/core/bodySerializer.gen.ts +0 -82
  131. package/src/api/generated/core/params.gen.ts +0 -178
  132. package/src/api/generated/core/pathSerializer.gen.ts +0 -171
  133. package/src/api/generated/core/queryKeySerializer.gen.ts +0 -117
  134. package/src/api/generated/core/serverSentEvents.gen.ts +0 -242
  135. package/src/api/generated/core/types.gen.ts +0 -110
  136. package/src/api/generated/core/utils.gen.ts +0 -140
  137. package/src/api/generated/facade.gen.ts +0 -68
  138. package/src/api/generated/index.ts +0 -4
  139. package/src/api/generated/sdk.gen.ts +0 -121
  140. package/src/api/index.ts +0 -45
  141. package/src/api/makeEndpoint.ts +0 -54
  142. package/src/auto-instrument.js +0 -171
  143. package/src/index.js +0 -19
  144. package/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +0 -107
  145. package/src/instrumentation/anthropic/get_streaming_stop_reason_telemetry.js +0 -121
  146. package/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +0 -50
  147. package/src/instrumentation/anthropic/set_telemetry_attributes.js +0 -37
  148. package/src/instrumentation/bedrock/get_cache_telemetry.js +0 -104
  149. package/src/instrumentation/bedrock/get_input_message_content_telemetry.js +0 -94
  150. package/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +0 -87
  151. package/src/instrumentation/bedrock/set_telemetry_attributes.js +0 -36
  152. package/src/instrumentation/cohere/get_chat_telemetry.js +0 -88
  153. package/src/instrumentation/cohere/get_embeddings_telemetry.js +0 -107
  154. package/src/instrumentation/cohere/set_telemetry_attributes.js +0 -32
  155. package/src/instrumentation/elevenlabs/full_instrumentation.js +0 -236
  156. package/src/instrumentation/google/get_audio_telemetry.js +0 -30
  157. package/src/instrumentation/google/get_cache_telemetry.js +0 -25
  158. package/src/instrumentation/google/get_embeddings_telemetry.js +0 -99
  159. package/src/instrumentation/google/set_telemetry_attributes.js +0 -98
  160. package/src/instrumentation/openai/get_audio_telemetry.js +0 -149
  161. package/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +0 -71
  162. package/src/instrumentation/openai/get_embeddings_telemetry.js +0 -107
  163. package/src/instrumentation/openai/get_streaming_usage.js +0 -81
  164. package/src/instrumentation/openai/set_telemetry_attributes.js +0 -39
  165. package/src/instrumentation/vercel/full_instrumentation.js +0 -44
  166. package/src/logger.js +0 -8
  167. package/src/otel/exporter.js +0 -108
  168. package/src/otel/propagation.js +0 -133
  169. package/src/otel/span-filter.js +0 -69
  170. package/src/otel/span-processor.js +0 -162
  171. package/src/otel/vercel-ai-sdk-span-filter.js +0 -79
  172. package/src/setup.js +0 -167
  173. package/tests/api/index.test.js +0 -437
  174. package/tests/index.test.js +0 -824
  175. package/tests/instrumentation/anthropic/get_cache_and_reasoning_telemetry.test.js +0 -158
  176. package/tests/instrumentation/anthropic/get_streaming_stop_reason_telemetry.test.js +0 -117
  177. package/tests/instrumentation/anthropic/get_tool_definitions_telemetry.test.js +0 -82
  178. package/tests/instrumentation/bedrock/get_cache_telemetry.test.js +0 -102
  179. package/tests/instrumentation/bedrock/get_input_message_content_telemetry.test.js +0 -89
  180. package/tests/instrumentation/bedrock/get_streaming_output_message_telemetry.test.js +0 -87
  181. package/tests/instrumentation/cohere/get_chat_telemetry.test.js +0 -148
  182. package/tests/instrumentation/cohere/get_embeddings_telemetry.test.js +0 -132
  183. package/tests/instrumentation/elevenlabs/full_instrumentation.test.js +0 -258
  184. package/tests/instrumentation/google/get_embeddings_telemetry.test.js +0 -128
  185. package/tests/instrumentation/google/get_reasoning_telemetry.test.js +0 -41
  186. package/tests/instrumentation/google/set_telemetry_attributes.test.js +0 -219
  187. package/tests/instrumentation/openai/get_audio_telemetry.test.js +0 -170
  188. package/tests/instrumentation/openai/get_cache_and_reasoning_telemetry.test.js +0 -83
  189. package/tests/instrumentation/openai/get_embeddings_telemetry.test.js +0 -145
  190. package/tests/instrumentation/openai/get_streaming_usage.test.js +0 -105
  191. package/tests/instrumentation/vercel/full_instrumentation.test.js +0 -16
  192. package/tests/otel/vercel-ai-sdk-span-filter.test.js +0 -159
  193. package/tsconfig.json +0 -18
  194. /package/dist/{api → src/api}/caseConversion.d.ts +0 -0
  195. /package/dist/{api → src/api}/caseConversion.js +0 -0
  196. /package/dist/{api → src/api}/generated/client/client.gen.d.ts +0 -0
  197. /package/dist/{api → src/api}/generated/client/client.gen.js +0 -0
  198. /package/dist/{api → src/api}/generated/client/index.d.ts +0 -0
  199. /package/dist/{api → src/api}/generated/client/index.js +0 -0
  200. /package/dist/{api → src/api}/generated/client/types.gen.d.ts +0 -0
  201. /package/dist/{api → src/api}/generated/client/types.gen.js +0 -0
  202. /package/dist/{api → src/api}/generated/client/utils.gen.d.ts +0 -0
  203. /package/dist/{api → src/api}/generated/client/utils.gen.js +0 -0
  204. /package/dist/{api → src/api}/generated/client.gen.d.ts +0 -0
  205. /package/dist/{api → src/api}/generated/client.gen.js +0 -0
  206. /package/dist/{api → src/api}/generated/core/auth.gen.d.ts +0 -0
  207. /package/dist/{api → src/api}/generated/core/auth.gen.js +0 -0
  208. /package/dist/{api → src/api}/generated/core/bodySerializer.gen.d.ts +0 -0
  209. /package/dist/{api → src/api}/generated/core/bodySerializer.gen.js +0 -0
  210. /package/dist/{api → src/api}/generated/core/params.gen.d.ts +0 -0
  211. /package/dist/{api → src/api}/generated/core/params.gen.js +0 -0
  212. /package/dist/{api → src/api}/generated/core/pathSerializer.gen.d.ts +0 -0
  213. /package/dist/{api → src/api}/generated/core/pathSerializer.gen.js +0 -0
  214. /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.d.ts +0 -0
  215. /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.js +0 -0
  216. /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.d.ts +0 -0
  217. /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.js +0 -0
  218. /package/dist/{api → src/api}/generated/core/types.gen.d.ts +0 -0
  219. /package/dist/{api → src/api}/generated/core/types.gen.js +0 -0
  220. /package/dist/{api → src/api}/generated/core/utils.gen.d.ts +0 -0
  221. /package/dist/{api → src/api}/generated/core/utils.gen.js +0 -0
  222. /package/dist/{api → src/api}/generated/types.gen.js +0 -0
  223. /package/dist/{api → src/api}/index.d.ts +0 -0
  224. /package/dist/{api → src/api}/index.js +0 -0
  225. /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,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