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
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Structured-output schema capture for Vercel AI SDK (ai >= 7) model-call spans.
3
+ *
4
+ * A `generateObject` call's schema is only ever emitted on the operation's ROOT
5
+ * span (`onObjectOperationStart` stamps `ai.schema` there under the
6
+ * supplemental-attributes opt-in) — and weflayr's span filter drops that
7
+ * aggregate span, keeping one span per model call. So the schema never reaches
8
+ * the exported span, even though the gateway bills it as input.
9
+ *
10
+ * The operation and its nested model call share one `callId` in the
11
+ * dispatcher's call state. Wrap `onObjectOperationStart` to remember the
12
+ * event's schema by callId, and `onObjectStepEnd` — the object operation's own
13
+ * model-call hook, where the call state's `inferenceSpan` exists (object
14
+ * operations never fire `onLanguageModelCallEnd`; verified live) — to stamp it
15
+ * as `ai.schema` on that span, the attribute the worker already reads.
16
+ * `cleanupCallState` is wrapped so an operation that errors before its model
17
+ * call does not leak its entry.
18
+ */
19
+ export declare class VercelStructuredOutputSchemaInstrumentor {
20
+ private _patched;
21
+ private _schemasByCallId;
22
+ instrument(dispatcher: any): void;
23
+ uninstrument(): void;
24
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Structured-output schema capture for Vercel AI SDK (ai >= 7) model-call spans.
4
+ *
5
+ * A `generateObject` call's schema is only ever emitted on the operation's ROOT
6
+ * span (`onObjectOperationStart` stamps `ai.schema` there under the
7
+ * supplemental-attributes opt-in) — and weflayr's span filter drops that
8
+ * aggregate span, keeping one span per model call. So the schema never reaches
9
+ * the exported span, even though the gateway bills it as input.
10
+ *
11
+ * The operation and its nested model call share one `callId` in the
12
+ * dispatcher's call state. Wrap `onObjectOperationStart` to remember the
13
+ * event's schema by callId, and `onObjectStepEnd` — the object operation's own
14
+ * model-call hook, where the call state's `inferenceSpan` exists (object
15
+ * operations never fire `onLanguageModelCallEnd`; verified live) — to stamp it
16
+ * as `ai.schema` on that span, the attribute the worker already reads.
17
+ * `cleanupCallState` is wrapped so an operation that errors before its model
18
+ * call does not leak its entry.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.VercelStructuredOutputSchemaInstrumentor = void 0;
22
+ const SCHEMA_ATTR = 'ai.schema';
23
+ class VercelStructuredOutputSchemaInstrumentor {
24
+ // [owner, methodName, originalFunction] for uninstrument().
25
+ _patched = [];
26
+ _schemasByCallId = new Map();
27
+ // No-op (and never throws) if the interface is missing — the worst case is
28
+ // the schema capture staying empty, exactly the pre-complement behaviour.
29
+ instrument(dispatcher) {
30
+ if (!dispatcher ||
31
+ typeof dispatcher.onObjectOperationStart !== 'function' ||
32
+ typeof dispatcher.onObjectStepEnd !== 'function') {
33
+ return;
34
+ }
35
+ const schemasByCallId = this._schemasByCallId;
36
+ const originalOperationStart = dispatcher.onObjectOperationStart;
37
+ dispatcher.onObjectOperationStart = function onObjectOperationStartWithSchema(event) {
38
+ try {
39
+ if (event && event.callId && event.schema && typeof event.schema === 'object') {
40
+ schemasByCallId.set(event.callId, event.schema);
41
+ }
42
+ }
43
+ catch {
44
+ // Never break span creation over an enrichment failure.
45
+ }
46
+ return originalOperationStart.call(this, event);
47
+ };
48
+ this._patched.push([dispatcher, 'onObjectOperationStart', originalOperationStart]);
49
+ const originalStepEnd = dispatcher.onObjectStepEnd;
50
+ dispatcher.onObjectStepEnd = function onObjectStepEndWithSchema(event) {
51
+ try {
52
+ const schema = event && schemasByCallId.get(event.callId);
53
+ if (schema) {
54
+ const callState = this.getCallState && this.getCallState(event.callId);
55
+ const span = callState && callState.inferenceSpan;
56
+ if (span && typeof span.setAttribute === 'function') {
57
+ span.setAttribute(SCHEMA_ATTR, JSON.stringify(schema));
58
+ }
59
+ }
60
+ }
61
+ catch {
62
+ // Never break span finalization over an enrichment failure.
63
+ }
64
+ return originalStepEnd.call(this, event);
65
+ };
66
+ this._patched.push([dispatcher, 'onObjectStepEnd', originalStepEnd]);
67
+ const originalCleanup = dispatcher.cleanupCallState;
68
+ if (typeof originalCleanup === 'function') {
69
+ dispatcher.cleanupCallState = function cleanupCallStateWithSchema(callId) {
70
+ schemasByCallId.delete(callId);
71
+ return originalCleanup.call(this, callId);
72
+ };
73
+ this._patched.push([dispatcher, 'cleanupCallState', originalCleanup]);
74
+ }
75
+ }
76
+ uninstrument() {
77
+ for (const [owner, methodName, original] of this._patched) {
78
+ owner[methodName] = original;
79
+ }
80
+ this._patched = [];
81
+ this._schemasByCallId.clear();
82
+ }
83
+ }
84
+ exports.VercelStructuredOutputSchemaInstrumentor = VercelStructuredOutputSchemaInstrumentor;
@@ -0,0 +1 @@
1
+ export declare const debug: import("node:util").DebugLogger;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.debug = void 0;
4
+ const node_util_1 = require("node:util");
5
+ // Enable with NODE_DEBUG=weflayr
6
+ exports.debug = (0, node_util_1.debuglog)('weflayr');
@@ -0,0 +1,19 @@
1
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
2
+ import type { ExportResult } from '@opentelemetry/core';
3
+ import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
4
+ declare const _RETRYABLE_STATUS: Set<number>;
5
+ type ExportFn = (spans: ReadableSpan[], resultCallback: (result: ExportResult) => void) => void;
6
+ export declare function _exportWithRetry(originalExport: ExportFn, { maxRetries, maxRetryMs }: {
7
+ maxRetries: number;
8
+ maxRetryMs: number;
9
+ }): ExportFn;
10
+ interface BuildExporterOptions {
11
+ baseUrl: string;
12
+ apiKey: string;
13
+ timeoutMs?: number;
14
+ warnOnExportError?: boolean;
15
+ maxRetries?: number;
16
+ maxRetryMs?: number;
17
+ }
18
+ export declare function buildExporter({ baseUrl, apiKey, timeoutMs, warnOnExportError, maxRetries, maxRetryMs, }: BuildExporterOptions): OTLPTraceExporter;
19
+ export { _RETRYABLE_STATUS };
@@ -0,0 +1,94 @@
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
+ exports._RETRYABLE_STATUS = void 0;
7
+ exports._exportWithRetry = _exportWithRetry;
8
+ exports.buildExporter = buildExporter;
9
+ const async_retry_1 = __importDefault(require("async-retry"));
10
+ const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
11
+ const logger_1 = require("../logger");
12
+ // OTLP-spec retryable statuses: rate-limit + transient server errors.
13
+ const _RETRYABLE_STATUS = new Set([429, 502, 503, 504]);
14
+ exports._RETRYABLE_STATUS = _RETRYABLE_STATUS;
15
+ function _isNonRetryable(err) {
16
+ // Tells async-retry's `bail` whether to give up: bail on 4xx (other than
17
+ // 429); retry on retryable statuses and on transport errors (no status).
18
+ const status = err?.exportResult?.error?.code;
19
+ return status !== undefined && !_RETRYABLE_STATUS.has(status);
20
+ }
21
+ function _formatFailure(result, url) {
22
+ const err = result?.error;
23
+ const status = err?.code;
24
+ const body = typeof err?.data === 'string' ? err.data.slice(0, 200) : undefined;
25
+ const message = err?.message || String(err) || 'unknown error';
26
+ let hint = '';
27
+ if (status === 401 || status === 403) {
28
+ hint = ' Check your apiKey / WEFLAYR_API_KEY.';
29
+ }
30
+ else if (status === 404) {
31
+ hint = ' Check the baseUrl is correct.';
32
+ }
33
+ else if (!status && /ECONN|ENOTFOUND|timeout/i.test(message)) {
34
+ hint = ' The endpoint is unreachable — check baseUrl and network.';
35
+ }
36
+ return (`Weflayr: failed to export telemetry to ${url}` +
37
+ (status ? ` (HTTP ${status})` : '') +
38
+ `: ${message}.${hint}` +
39
+ (body ? ` Response: ${body}` : ''));
40
+ }
41
+ // Wrap a callback-style OTel exporter `export(spans, cb)` with retry. Retries
42
+ // transport errors + retryable HTTP statuses; bails on other 4xx.
43
+ function _exportWithRetry(originalExport, { maxRetries, maxRetryMs }) {
44
+ return (spans, resultCallback) => {
45
+ (0, async_retry_1.default)(async (bail) => {
46
+ const result = await new Promise((resolve) => originalExport(spans, resolve));
47
+ if (result?.code === 0)
48
+ return result;
49
+ const err = new Error(result?.error?.message || 'export failed');
50
+ err.exportResult = result;
51
+ if (_isNonRetryable(err)) {
52
+ bail(err);
53
+ return result;
54
+ }
55
+ throw err;
56
+ }, { retries: maxRetries - 1, minTimeout: 50, maxRetryTime: maxRetryMs, factor: 2 })
57
+ .then((result) => resultCallback(result))
58
+ .catch((err) => resultCallback(err.exportResult || { code: 1, error: err }));
59
+ };
60
+ }
61
+ function buildExporter({ baseUrl, apiKey, timeoutMs = 5000, warnOnExportError = true, maxRetries = 2, maxRetryMs = 1000, }) {
62
+ const url = `${baseUrl.replace(/\/$/, '')}/`;
63
+ const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({
64
+ url,
65
+ headers: {
66
+ Authorization: `Bearer ${apiKey}`,
67
+ },
68
+ timeoutMillis: timeoutMs,
69
+ });
70
+ const originalExport = exporter.export.bind(exporter);
71
+ const wrappedExport = _exportWithRetry(originalExport, { maxRetries, maxRetryMs });
72
+ exporter.export = (spans, resultCallback) => {
73
+ const start = Date.now();
74
+ (0, logger_1.debug)('exporter.export: posting count=%d', spans.length);
75
+ wrappedExport(spans, (result) => {
76
+ const ms = Date.now() - start;
77
+ if (result && result.code === 0) {
78
+ (0, logger_1.debug)('exporter.export: ok count=%d elapsed_ms=%d', spans.length, ms);
79
+ }
80
+ else {
81
+ const err = result?.error;
82
+ (0, logger_1.debug)('exporter.export: FAIL count=%d elapsed_ms=%d code=%s error=%s', spans.length, ms, err?.code, err?.message || err || '(none)');
83
+ if (warnOnExportError) {
84
+ // console.warn writes to stderr synchronously. process.emitWarning
85
+ // is queued for the next tick, so a caller doing process.exit() from
86
+ // their error handler races past it and the warning is lost.
87
+ console.warn(`[weflayr] ${_formatFailure(result, url)}`);
88
+ }
89
+ }
90
+ resultCallback(result);
91
+ });
92
+ };
93
+ return exporter;
94
+ }
@@ -0,0 +1,46 @@
1
+ import { type Context } from '@opentelemetry/api';
2
+ import type { AIProviderName } from '../auto-instrument';
3
+ declare const WEFLAYR_METADATA_CONTEXT_KEY: symbol;
4
+ declare const FEATURE_NAME_ATTR = "weflayr.feature_name";
5
+ declare const CUSTOMER_NAME_ATTR = "weflayr.customer_name";
6
+ declare const PROVIDER_NAME_ATTR = "weflayr.provider_name";
7
+ declare const UUID_ATTR = "weflayr.uuid";
8
+ declare const EXTRA_TAG_PREFIX = "weflayr.tag.";
9
+ export interface PropagateMetadataOptions {
10
+ /** Product-side feature triggering the LLM call (e.g. `"onboarding-summary"`). */
11
+ featureName: string;
12
+ /** Name of the end-user / tenant customer the call is made for. */
13
+ customerName?: string;
14
+ /** @deprecated Use `customerName` instead. */
15
+ customerId?: string;
16
+ /**
17
+ * Override for the provider seen on the wire. Set this only if it differs
18
+ * from the SDK auto-detected by OpenTelemetry — e.g. calls routed through
19
+ * `vercel_ai_gateway` that proxies to OpenAI/Anthropic but should be
20
+ * reported as the gateway.
21
+ */
22
+ providerNameOverride?: AIProviderName;
23
+ /** @deprecated Use `providerNameOverride` instead. */
24
+ providerName?: AIProviderName;
25
+ /**
26
+ * Arbitrary scalar key/value pairs to attach. Values must be `string`,
27
+ * `number`, or `boolean` so they survive the ClickHouse `Map(String,
28
+ * String)` column they land in. Avoid `featureName` / `customerName` keys
29
+ * here — they have dedicated fields.
30
+ */
31
+ extraTags?: Record<string, string | number | boolean>;
32
+ }
33
+ export declare function getMergedMetadataFromContext(parentContext?: Context): Record<string, unknown>;
34
+ /**
35
+ * Attach Weflayr metadata to every LLM span created inside this scope.
36
+ *
37
+ * Callable form: `propagateMetadata(options, fn)` runs `fn` immediately.
38
+ * Decorator form: `propagateMetadata(options)` returns a wrapper usable as a
39
+ * function-decorator (`@propagateMetadata(...)` on class methods) or as a
40
+ * plain `wrap(fn)` -> wrappedFn helper. Each invocation of the wrapped
41
+ * function mints a fresh `uuid`, matching the callable form's "one uuid per
42
+ * propagateMetadata call" contract.
43
+ */
44
+ export declare function propagateMetadata<T>(options: PropagateMetadataOptions, fn: () => Promise<T> | T): Promise<T> | T;
45
+ export declare function propagateMetadata(options: PropagateMetadataOptions): (target: unknown, key?: string, descriptor?: PropertyDescriptor) => unknown;
46
+ export { WEFLAYR_METADATA_CONTEXT_KEY, FEATURE_NAME_ATTR, CUSTOMER_NAME_ATTR, PROVIDER_NAME_ATTR, UUID_ATTR, EXTRA_TAG_PREFIX, };
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ // Copyright 2024 Langfuse GmbH
3
+ // Licensed under the MIT License.
4
+ // Original source: https://github.com/langfuse/langfuse-js/blob/main/packages/core/src/propagation.ts
5
+ //
6
+ // Modifications copyright 2026 Weflayr
7
+ // This file has been modified from its original form:
8
+ // - Translated from TypeScript to JavaScript
9
+ // - Replaced Langfuse's fixed schema with Weflayr's structured metadata
10
+ // (featureName, customerName, providerNameOverride, extraTags) plus an
11
+ // auto-generated per-call uuid
12
+ // - Removed asBaggage cross-process propagation (not needed yet)
13
+ // - Removed experiment framework keys
14
+ // - Structured fields are written under stable `weflayr.*` span attribute
15
+ // keys; extraTags entries are written verbatim
16
+ //
17
+ // See LICENSE-MIT in the package root for the full license text.
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.EXTRA_TAG_PREFIX = exports.UUID_ATTR = exports.PROVIDER_NAME_ATTR = exports.CUSTOMER_NAME_ATTR = exports.FEATURE_NAME_ATTR = exports.WEFLAYR_METADATA_CONTEXT_KEY = void 0;
20
+ exports.getMergedMetadataFromContext = getMergedMetadataFromContext;
21
+ exports.propagateMetadata = propagateMetadata;
22
+ const node_crypto_1 = require("node:crypto");
23
+ const api_1 = require("@opentelemetry/api");
24
+ const WEFLAYR_METADATA_CONTEXT_KEY = (0, api_1.createContextKey)('weflayr_metadata');
25
+ exports.WEFLAYR_METADATA_CONTEXT_KEY = WEFLAYR_METADATA_CONTEXT_KEY;
26
+ const FEATURE_NAME_ATTR = 'weflayr.feature_name';
27
+ exports.FEATURE_NAME_ATTR = FEATURE_NAME_ATTR;
28
+ const CUSTOMER_NAME_ATTR = 'weflayr.customer_name';
29
+ exports.CUSTOMER_NAME_ATTR = CUSTOMER_NAME_ATTR;
30
+ const PROVIDER_NAME_ATTR = 'weflayr.provider_name';
31
+ exports.PROVIDER_NAME_ATTR = PROVIDER_NAME_ATTR;
32
+ const UUID_ATTR = 'weflayr.uuid';
33
+ exports.UUID_ATTR = UUID_ATTR;
34
+ // Prefix for user-supplied `extraTags` so downstream normalizers can pick
35
+ // them out without colliding with instrumentor-set `gen_ai.*` attributes.
36
+ const EXTRA_TAG_PREFIX = 'weflayr.tag.';
37
+ exports.EXTRA_TAG_PREFIX = EXTRA_TAG_PREFIX;
38
+ function getMergedMetadataFromContext(parentContext) {
39
+ const ctx = parentContext ?? api_1.context.active();
40
+ const existing = ctx.getValue(WEFLAYR_METADATA_CONTEXT_KEY);
41
+ return existing && typeof existing === 'object' ? { ...existing } : {};
42
+ }
43
+ function _buildAttributes({ featureName, customerName, providerNameOverride, extraTags, spanUuid, }) {
44
+ const attributes = {
45
+ [FEATURE_NAME_ATTR]: featureName,
46
+ [CUSTOMER_NAME_ATTR]: customerName,
47
+ [UUID_ATTR]: spanUuid,
48
+ };
49
+ for (const [key, value] of Object.entries(extraTags)) {
50
+ attributes[`${EXTRA_TAG_PREFIX}${key}`] = value;
51
+ }
52
+ if (providerNameOverride !== undefined && providerNameOverride !== null) {
53
+ attributes[PROVIDER_NAME_ATTR] = providerNameOverride;
54
+ }
55
+ return attributes;
56
+ }
57
+ function propagateMetadata(options, fn) {
58
+ const { featureName, customerId, providerName } = options ?? {};
59
+ let { customerName, providerNameOverride } = options ?? {};
60
+ if (customerId != null) {
61
+ process.emitWarning('propagateMetadata: `customerId` is deprecated, use `customerName`', 'DeprecationWarning');
62
+ customerName = customerName ?? customerId;
63
+ }
64
+ if (providerName != null) {
65
+ process.emitWarning('propagateMetadata: `providerName` is deprecated, use `providerNameOverride`', 'DeprecationWarning');
66
+ providerNameOverride = providerNameOverride ?? providerName;
67
+ }
68
+ if (featureName == null || customerName == null) {
69
+ throw new Error('propagateMetadata: `featureName` and `customerName` are required');
70
+ }
71
+ const normalizedOptions = { ...options, customerName, providerNameOverride };
72
+ if (typeof fn === 'function') {
73
+ return _runWithMetadata(normalizedOptions, fn);
74
+ }
75
+ return function decorator(target, _key, descriptor) {
76
+ if (descriptor && typeof descriptor.value === 'function') {
77
+ const original = descriptor.value;
78
+ descriptor.value = function wrapped(...args) {
79
+ return _runWithMetadata(normalizedOptions, () => original.apply(this, args));
80
+ };
81
+ return descriptor;
82
+ }
83
+ if (typeof target === 'function') {
84
+ return function wrapped(...args) {
85
+ return _runWithMetadata(normalizedOptions, () => target.apply(this, args));
86
+ };
87
+ }
88
+ return target;
89
+ };
90
+ }
91
+ function _runWithMetadata(options, fn) {
92
+ const { featureName, customerName, providerNameOverride, extraTags } = options;
93
+ const attributes = _buildAttributes({
94
+ featureName,
95
+ customerName,
96
+ providerNameOverride,
97
+ extraTags: extraTags ?? {},
98
+ spanUuid: (0, node_crypto_1.randomUUID)().replace(/-/g, ''),
99
+ });
100
+ const parent = api_1.context.active();
101
+ const merged = { ...getMergedMetadataFromContext(parent), ...attributes };
102
+ const newContext = parent.setValue(WEFLAYR_METADATA_CONTEXT_KEY, merged);
103
+ const activeSpan = api_1.trace.getActiveSpan();
104
+ if (activeSpan && activeSpan.isRecording()) {
105
+ for (const [k, v] of Object.entries(attributes)) {
106
+ activeSpan.setAttribute(k, v);
107
+ }
108
+ }
109
+ return api_1.context.with(newContext, fn);
110
+ }
@@ -0,0 +1,3 @@
1
+ import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
2
+ export declare function isKnownLLMInstrumentor(span: ReadableSpan): boolean;
3
+ export declare function isDefaultExportSpan(span: ReadableSpan): boolean;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ // Copyright 2024 Langfuse GmbH
3
+ // Licensed under the MIT License.
4
+ // Original source: https://github.com/langfuse/langfuse-js/blob/main/packages/otel/src/span-filter.ts
5
+ //
6
+ // Modifications copyright 2026 Weflayr
7
+ // This file has been modified from its original form:
8
+ // - Translated from TypeScript to JavaScript
9
+ // - Dropped the LANGFUSE_TRACER_NAME special case (we have no SDK-internal tracer)
10
+ // - Dropped isLangfuseSpan
11
+ // - Export only spans from known LLM instrumentation scopes: general-purpose
12
+ // APM SDKs (Sentry, Datadog, ...) also instrument LLM calls with gen_ai.*
13
+ // attributes, so the original "any span with gen_ai.* attributes" check
14
+ // exported the same call twice
15
+ //
16
+ // See LICENSE-MIT in the package root for the full license text.
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.isKnownLLMInstrumentor = isKnownLLMInstrumentor;
19
+ exports.isDefaultExportSpan = isDefaultExportSpan;
20
+ const KNOWN_LLM_INSTRUMENTATION_SCOPE_PREFIXES = [
21
+ 'agent_framework',
22
+ 'ai',
23
+ 'gen_ai',
24
+ 'haystack',
25
+ 'langsmith',
26
+ 'litellm',
27
+ 'mistralai_sdk_tracer',
28
+ 'openinference',
29
+ 'opentelemetry.instrumentation.anthropic',
30
+ 'opentelemetry.instrumentation.aws_bedrock',
31
+ 'opentelemetry.instrumentation.bedrock',
32
+ 'opentelemetry.instrumentation.cohere',
33
+ 'opentelemetry.instrumentation.gemini',
34
+ 'opentelemetry.instrumentation.google_genai',
35
+ 'opentelemetry.instrumentation.google_generativeai',
36
+ 'opentelemetry.instrumentation.openai',
37
+ 'opentelemetry.instrumentation.openai_v2',
38
+ 'opentelemetry.instrumentation.vertex_ai',
39
+ 'opentelemetry.instrumentation.vertexai',
40
+ 'weflayr.instrumentation',
41
+ 'strands-agents',
42
+ 'vllm',
43
+ '@traceloop/instrumentation-openai',
44
+ '@traceloop/instrumentation-anthropic',
45
+ '@traceloop/instrumentation-bedrock',
46
+ '@traceloop/instrumentation-cohere',
47
+ '@traceloop/instrumentation-google-generativeai',
48
+ '@traceloop/instrumentation-langchain',
49
+ '@traceloop/instrumentation-llamaindex',
50
+ '@traceloop/instrumentation-pinecone',
51
+ '@traceloop/instrumentation-chromadb',
52
+ '@traceloop/instrumentation-qdrant',
53
+ '@traceloop/instrumentation-mcp',
54
+ ];
55
+ function isKnownLLMInstrumentor(span) {
56
+ const scope = span.instrumentationScope.name;
57
+ return KNOWN_LLM_INSTRUMENTATION_SCOPE_PREFIXES.some((prefix) => scope === prefix || scope.startsWith(`${prefix}.`));
58
+ }
59
+ function isDefaultExportSpan(span) {
60
+ return isKnownLLMInstrumentor(span);
61
+ }
@@ -0,0 +1,55 @@
1
+ import { type Context, type Span } from '@opentelemetry/api';
2
+ import { type ReadableSpan, type SpanExporter, type SpanProcessor } from '@opentelemetry/sdk-trace-base';
3
+ export declare const CONTENT_CAPTURE_ENV = "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT";
4
+ /** Arbitrary key-value tags applied to OTel spans. */
5
+ export type Tags = Record<string, string | number | boolean>;
6
+ /**
7
+ * Span attributes the mask callback can read or scrub. The OpenTelemetry GenAI
8
+ * semantic-convention keys get autocomplete; the index signature catches user
9
+ * tags and provider-specific attributes (e.g. Vercel AI's `ai.*`).
10
+ */
11
+ export interface OtelSpanAttributes {
12
+ 'gen_ai.system'?: string;
13
+ 'gen_ai.operation.name'?: string;
14
+ 'gen_ai.request.model'?: string;
15
+ 'gen_ai.request.temperature'?: number;
16
+ 'gen_ai.request.max_tokens'?: number;
17
+ 'gen_ai.response.model'?: string;
18
+ 'gen_ai.response.id'?: string;
19
+ 'gen_ai.response.finish_reasons'?: string[];
20
+ 'gen_ai.usage.input_tokens'?: number;
21
+ 'gen_ai.usage.output_tokens'?: number;
22
+ /** Only populated when `captureMessageContent=true`. */
23
+ 'gen_ai.prompt'?: string;
24
+ /** Only populated when `captureMessageContent=true`. */
25
+ 'gen_ai.completion'?: string;
26
+ 'gen_ai.tool.name'?: string;
27
+ 'gen_ai.tool.call.id'?: string;
28
+ 'gen_ai.tool.call.arguments'?: string;
29
+ 'error.type'?: string;
30
+ [key: string]: unknown;
31
+ }
32
+ export interface WeflayrSpanProcessorOptions {
33
+ exporter: SpanExporter;
34
+ exportMode?: 'batch' | 'immediate';
35
+ defaultTags?: Tags;
36
+ mask?: (attrs: OtelSpanAttributes) => OtelSpanAttributes;
37
+ shouldExportSpan?: (span: ReadableSpan) => boolean;
38
+ }
39
+ type StartedSpan = Span & ReadableSpan;
40
+ export declare class WeflayrSpanProcessor implements SpanProcessor {
41
+ private _delegate;
42
+ private _defaultTags;
43
+ private _mask?;
44
+ private _maskFunctionSource;
45
+ private _shouldExportSpan;
46
+ private _vercelAiSdkSpanFilter;
47
+ private _openLlmSpans;
48
+ constructor({ exporter, exportMode, defaultTags, mask, shouldExportSpan, }: WeflayrSpanProcessorOptions);
49
+ onStart(span: StartedSpan, parentContext: Context): void;
50
+ onEnd(span: ReadableSpan): void;
51
+ forceFlush(): Promise<void>;
52
+ private _endOrphanedLlmSpans;
53
+ shutdown(): Promise<void>;
54
+ }
55
+ export {};