weflayr 0.24.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 (234) hide show
  1. package/README.md +2 -2
  2. package/dist/{api → src/api}/generated/facade.gen.d.ts +86 -12
  3. package/dist/{api → src/api}/generated/facade.gen.js +4 -2
  4. package/dist/src/api/generated/index.d.ts +2 -0
  5. package/dist/{api → src/api}/generated/index.js +3 -1
  6. package/dist/{api → src/api}/generated/sdk.gen.d.ts +11 -3
  7. package/dist/{api → src/api}/generated/sdk.gen.js +34 -4
  8. package/{src/api/generated/types.gen.ts → dist/src/api/generated/types.gen.d.ts} +436 -153
  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/{src → dist/src}/instrumentation/google/get_cache_telemetry.js +18 -19
  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 -1005
  119. package/eslint.config.mjs +0 -36
  120. package/index.d.ts +0 -170
  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 -104
  138. package/src/api/generated/index.ts +0 -4
  139. package/src/api/generated/sdk.gen.ts +0 -175
  140. package/src/api/index.ts +0 -45
  141. package/src/api/makeEndpoint.ts +0 -54
  142. package/src/auto-instrument.js +0 -172
  143. package/src/index.js +0 -19
  144. package/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +0 -118
  145. package/src/instrumentation/anthropic/get_cache_config_telemetry.js +0 -90
  146. package/src/instrumentation/anthropic/get_streaming_stop_reason_telemetry.js +0 -121
  147. package/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +0 -55
  148. package/src/instrumentation/anthropic/set_telemetry_attributes.js +0 -39
  149. package/src/instrumentation/bedrock/get_cache_config_telemetry.js +0 -106
  150. package/src/instrumentation/bedrock/get_cache_telemetry.js +0 -109
  151. package/src/instrumentation/bedrock/get_input_message_content_telemetry.js +0 -94
  152. package/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +0 -87
  153. package/src/instrumentation/bedrock/set_telemetry_attributes.js +0 -40
  154. package/src/instrumentation/cohere/get_chat_telemetry.js +0 -88
  155. package/src/instrumentation/cohere/get_embeddings_telemetry.js +0 -107
  156. package/src/instrumentation/cohere/set_telemetry_attributes.js +0 -32
  157. package/src/instrumentation/elevenlabs/full_instrumentation.js +0 -236
  158. package/src/instrumentation/google/get_audio_telemetry.js +0 -30
  159. package/src/instrumentation/google/get_cache_operations_telemetry.js +0 -171
  160. package/src/instrumentation/google/get_embeddings_telemetry.js +0 -99
  161. package/src/instrumentation/google/set_telemetry_attributes.js +0 -104
  162. package/src/instrumentation/openai/get_audio_telemetry.js +0 -149
  163. package/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +0 -71
  164. package/src/instrumentation/openai/get_cache_config_telemetry.js +0 -63
  165. package/src/instrumentation/openai/get_embeddings_telemetry.js +0 -107
  166. package/src/instrumentation/openai/get_streaming_usage.js +0 -81
  167. package/src/instrumentation/openai/set_telemetry_attributes.js +0 -41
  168. package/src/instrumentation/vercel/full_instrumentation.js +0 -52
  169. package/src/instrumentation/vercel/get_cache_creation_telemetry.js +0 -70
  170. package/src/logger.js +0 -8
  171. package/src/otel/exporter.js +0 -108
  172. package/src/otel/propagation.js +0 -146
  173. package/src/otel/span-filter.js +0 -69
  174. package/src/otel/span-processor.js +0 -170
  175. package/src/otel/vercel-ai-sdk-span-filter.js +0 -79
  176. package/src/setup.js +0 -167
  177. package/tests/api/index.test.js +0 -437
  178. package/tests/index.test.js +0 -884
  179. package/tests/instrumentation/anthropic/get_cache_and_reasoning_telemetry.test.js +0 -181
  180. package/tests/instrumentation/anthropic/get_cache_config_telemetry.test.js +0 -92
  181. package/tests/instrumentation/anthropic/get_streaming_stop_reason_telemetry.test.js +0 -117
  182. package/tests/instrumentation/anthropic/get_tool_definitions_telemetry.test.js +0 -97
  183. package/tests/instrumentation/bedrock/get_cache_config_telemetry.test.js +0 -107
  184. package/tests/instrumentation/bedrock/get_cache_telemetry.test.js +0 -118
  185. package/tests/instrumentation/bedrock/get_input_message_content_telemetry.test.js +0 -89
  186. package/tests/instrumentation/bedrock/get_streaming_output_message_telemetry.test.js +0 -87
  187. package/tests/instrumentation/cohere/get_chat_telemetry.test.js +0 -148
  188. package/tests/instrumentation/cohere/get_embeddings_telemetry.test.js +0 -132
  189. package/tests/instrumentation/elevenlabs/full_instrumentation.test.js +0 -258
  190. package/tests/instrumentation/google/get_cache_operations_telemetry.test.js +0 -130
  191. package/tests/instrumentation/google/get_embeddings_telemetry.test.js +0 -128
  192. package/tests/instrumentation/google/get_reasoning_telemetry.test.js +0 -41
  193. package/tests/instrumentation/google/set_telemetry_attributes.test.js +0 -219
  194. package/tests/instrumentation/openai/get_audio_telemetry.test.js +0 -170
  195. package/tests/instrumentation/openai/get_cache_and_reasoning_telemetry.test.js +0 -83
  196. package/tests/instrumentation/openai/get_cache_config_telemetry.test.js +0 -83
  197. package/tests/instrumentation/openai/get_embeddings_telemetry.test.js +0 -145
  198. package/tests/instrumentation/openai/get_streaming_usage.test.js +0 -105
  199. package/tests/instrumentation/vercel/full_instrumentation.test.js +0 -16
  200. package/tests/instrumentation/vercel/get_cache_creation_telemetry.test.js +0 -96
  201. package/tests/otel/vercel-ai-sdk-span-filter.test.js +0 -159
  202. package/tsconfig.json +0 -18
  203. /package/dist/{api → src/api}/caseConversion.d.ts +0 -0
  204. /package/dist/{api → src/api}/caseConversion.js +0 -0
  205. /package/dist/{api → src/api}/generated/client/client.gen.d.ts +0 -0
  206. /package/dist/{api → src/api}/generated/client/client.gen.js +0 -0
  207. /package/dist/{api → src/api}/generated/client/index.d.ts +0 -0
  208. /package/dist/{api → src/api}/generated/client/index.js +0 -0
  209. /package/dist/{api → src/api}/generated/client/types.gen.d.ts +0 -0
  210. /package/dist/{api → src/api}/generated/client/types.gen.js +0 -0
  211. /package/dist/{api → src/api}/generated/client/utils.gen.d.ts +0 -0
  212. /package/dist/{api → src/api}/generated/client/utils.gen.js +0 -0
  213. /package/dist/{api → src/api}/generated/client.gen.d.ts +0 -0
  214. /package/dist/{api → src/api}/generated/client.gen.js +0 -0
  215. /package/dist/{api → src/api}/generated/core/auth.gen.d.ts +0 -0
  216. /package/dist/{api → src/api}/generated/core/auth.gen.js +0 -0
  217. /package/dist/{api → src/api}/generated/core/bodySerializer.gen.d.ts +0 -0
  218. /package/dist/{api → src/api}/generated/core/bodySerializer.gen.js +0 -0
  219. /package/dist/{api → src/api}/generated/core/params.gen.d.ts +0 -0
  220. /package/dist/{api → src/api}/generated/core/params.gen.js +0 -0
  221. /package/dist/{api → src/api}/generated/core/pathSerializer.gen.d.ts +0 -0
  222. /package/dist/{api → src/api}/generated/core/pathSerializer.gen.js +0 -0
  223. /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.d.ts +0 -0
  224. /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.js +0 -0
  225. /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.d.ts +0 -0
  226. /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.js +0 -0
  227. /package/dist/{api → src/api}/generated/core/types.gen.d.ts +0 -0
  228. /package/dist/{api → src/api}/generated/core/types.gen.js +0 -0
  229. /package/dist/{api → src/api}/generated/core/utils.gen.d.ts +0 -0
  230. /package/dist/{api → src/api}/generated/core/utils.gen.js +0 -0
  231. /package/dist/{api → src/api}/generated/types.gen.js +0 -0
  232. /package/dist/{api → src/api}/index.d.ts +0 -0
  233. /package/dist/{api → src/api}/index.js +0 -0
  234. /package/dist/{api → src/api}/makeEndpoint.d.ts +0 -0
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /**
3
+ * Chat token-usage enrichment complement for the Cohere v1 chat path.
4
+ *
5
+ * `@traceloop/instrumentation-cohere` creates the `cohere.chat` span but reads
6
+ * token usage from the obsolete `result.token_count.{prompt,response}_tokens`
7
+ * shape; modern cohere-ai returns usage under `meta.billedUnits` instead, so the
8
+ * traceloop span ends up with zero chat tokens. This thin complement backfills
9
+ * `gen_ai.usage.{input,output}_tokens` from `meta.billedUnits`, the same source
10
+ * traceloop already uses for the `generate` endpoint — bringing Node chat tokens
11
+ * to parity with the Python SDK (OpenLLMetry captures them natively, so there is
12
+ * no Python counterpart).
13
+ *
14
+ * It hooks the internal `CohereClient.prototype.__chat` (which the public `chat`
15
+ * delegates to synchronously) rather than the public `chat`: traceloop wraps
16
+ * `chat` and opens the span around it, so `__chat` runs while that span is the
17
+ * active span — letting this complement enrich it regardless of patch order.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.CohereChatTokenUsageInstrumentor = void 0;
21
+ const api_1 = require("@opentelemetry/api");
22
+ function _billedUnits(result) {
23
+ // Public `chat` resolves to the response body, but `__chat` resolves to the
24
+ // Fern wrapper `{ data, rawResponse }`; read billedUnits off either shape.
25
+ const response = result && result.data ? result.data : result;
26
+ return response && response.meta ? response.meta.billedUnits : undefined;
27
+ }
28
+ function _setChatTokenUsage(span, result) {
29
+ const billedUnits = _billedUnits(result);
30
+ if (!billedUnits)
31
+ return;
32
+ if (typeof billedUnits.inputTokens === 'number') {
33
+ span.setAttribute('gen_ai.usage.input_tokens', billedUnits.inputTokens);
34
+ }
35
+ if (typeof billedUnits.outputTokens === 'number') {
36
+ span.setAttribute('gen_ai.usage.output_tokens', billedUnits.outputTokens);
37
+ }
38
+ }
39
+ class CohereChatTokenUsageInstrumentor {
40
+ // [ownerPrototype, methodName, originalFunction] for uninstrument().
41
+ _patched = [];
42
+ instrument() {
43
+ let CohereClient;
44
+ try {
45
+ ({ CohereClient } = require('cohere-ai/Client'));
46
+ }
47
+ catch (err) {
48
+ throw new Error('weflayr.autoInstrument(COHERE): the cohere-ai client is not installed. ' +
49
+ 'Install it with: npm install cohere-ai\n' +
50
+ `Underlying error: ${err.message}`);
51
+ }
52
+ this._wrap(CohereClient.prototype, '__chat');
53
+ }
54
+ uninstrument() {
55
+ for (const [owner, methodName, original] of this._patched) {
56
+ owner[methodName] = original;
57
+ }
58
+ this._patched = [];
59
+ }
60
+ _wrap(owner, methodName) {
61
+ const original = owner[methodName];
62
+ function wrapper(...args) {
63
+ // Captured synchronously, while traceloop's chat span is still active.
64
+ const span = api_1.trace.getActiveSpan();
65
+ const result = original.apply(this, args);
66
+ if (!span || !span.isRecording || !span.isRecording())
67
+ return result;
68
+ return Promise.resolve(result).then((response) => {
69
+ _setChatTokenUsage(span, response);
70
+ return response;
71
+ });
72
+ }
73
+ owner[methodName] = wrapper;
74
+ this._patched.push([owner, methodName, original]);
75
+ }
76
+ }
77
+ exports.CohereChatTokenUsageInstrumentor = CohereChatTokenUsageInstrumentor;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Hand-written OTel instrumentor for the Cohere embeddings endpoint.
3
+ *
4
+ * `@traceloop/instrumentation-cohere` (the package weflayr uses for Cohere on
5
+ * Node) wraps chat/generate/rerank but not `embed`, so this ships inside weflayr
6
+ * to cover it. OpenLLMetry's cohere instrumentor doesn't cover `embed` either, so
7
+ * the Python SDK has a mirror complement (`cohere_embeddings.py`) shaped to
8
+ * normalize identically. It is registered alongside the traceloop instrumentor
9
+ * whenever `autoInstrument({ aiSdks: 'cohere' })` runs.
10
+ *
11
+ * Embeddings are billed per input token, so the span records the input tokens
12
+ * Cohere returns under `gen_ai.usage.input_tokens`; there is no completion.
13
+ */
14
+ export declare class CohereEmbeddingsInstrumentor {
15
+ private _patched;
16
+ instrument(): void;
17
+ uninstrument(): void;
18
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /**
3
+ * Hand-written OTel instrumentor for the Cohere embeddings endpoint.
4
+ *
5
+ * `@traceloop/instrumentation-cohere` (the package weflayr uses for Cohere on
6
+ * Node) wraps chat/generate/rerank but not `embed`, so this ships inside weflayr
7
+ * to cover it. OpenLLMetry's cohere instrumentor doesn't cover `embed` either, so
8
+ * the Python SDK has a mirror complement (`cohere_embeddings.py`) shaped to
9
+ * normalize identically. It is registered alongside the traceloop instrumentor
10
+ * whenever `autoInstrument({ aiSdks: 'cohere' })` runs.
11
+ *
12
+ * Embeddings are billed per input token, so the span records the input tokens
13
+ * Cohere returns under `gen_ai.usage.input_tokens`; there is no completion.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.CohereEmbeddingsInstrumentor = void 0;
17
+ const api_1 = require("@opentelemetry/api");
18
+ const TRACER_NAME = 'weflayr.instrumentation.cohere_embeddings';
19
+ // Matches the gen_ai.system the cohere chat instrumentors set (Python + Node).
20
+ const SYSTEM = 'Cohere';
21
+ const EMBEDDINGS_OPERATION = 'embeddings';
22
+ function _recordError(span, error) {
23
+ span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error?.message ?? String(error) });
24
+ span.recordException(error);
25
+ }
26
+ function _wrapEmbed(owner, patched) {
27
+ const original = owner.embed;
28
+ function wrapper(request, ...rest) {
29
+ const span = api_1.trace.getTracer(TRACER_NAME).startSpan(EMBEDDINGS_OPERATION);
30
+ span.setAttribute('gen_ai.system', SYSTEM);
31
+ span.setAttribute('gen_ai.operation.name', EMBEDDINGS_OPERATION);
32
+ if (request && request.model) {
33
+ span.setAttribute('gen_ai.request.model', request.model);
34
+ }
35
+ // The embedded texts are the prompt; stamp one user message per text, like
36
+ // the chat path. The span processor strips it when content capture is off.
37
+ if (request && Array.isArray(request.texts) && request.texts.length) {
38
+ span.setAttribute('gen_ai.input.messages', JSON.stringify(request.texts.map((text) => ({
39
+ role: 'user',
40
+ parts: [{ type: 'text', content: text }],
41
+ }))));
42
+ }
43
+ return Promise.resolve(original.call(this, request, ...rest)).then((response) => {
44
+ // Node SDK reports the billed input tokens under camelCase keys.
45
+ const inputTokens = response?.meta?.billedUnits?.inputTokens ?? response?.meta?.tokens?.inputTokens;
46
+ if (inputTokens != null) {
47
+ span.setAttribute('gen_ai.usage.input_tokens', inputTokens);
48
+ }
49
+ span.end();
50
+ return response;
51
+ }, (error) => {
52
+ _recordError(span, error);
53
+ span.end();
54
+ throw error;
55
+ });
56
+ }
57
+ owner.embed = wrapper;
58
+ patched.push([owner, 'embed', original]);
59
+ }
60
+ class CohereEmbeddingsInstrumentor {
61
+ // [ownerPrototype, methodName, originalFunction] for uninstrument().
62
+ _patched = [];
63
+ instrument() {
64
+ let CohereClient;
65
+ let V2Client;
66
+ try {
67
+ // v1 `embed` is a prototype method on CohereClient; v2 `embed` lives on
68
+ // V2Client.prototype (CohereClientV2 binds it as an instance property, so
69
+ // it must be patched on the underlying V2Client class instead).
70
+ ({ CohereClient } = require('cohere-ai/Client'));
71
+ ({ V2Client } = require('cohere-ai/api/resources/v2/client/Client'));
72
+ }
73
+ catch (err) {
74
+ throw new Error('weflayr.autoInstrument(COHERE): the cohere-ai client is not installed. ' +
75
+ 'Install it with: npm install cohere-ai\n' +
76
+ `Underlying error: ${err.message}`);
77
+ }
78
+ _wrapEmbed(CohereClient.prototype, this._patched);
79
+ _wrapEmbed(V2Client.prototype, this._patched);
80
+ }
81
+ uninstrument() {
82
+ for (const [owner, methodName, original] of this._patched) {
83
+ owner[methodName] = original;
84
+ }
85
+ this._patched = [];
86
+ }
87
+ }
88
+ exports.CohereEmbeddingsInstrumentor = CohereEmbeddingsInstrumentor;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Structured-output schema location for Cohere requests.
3
+ *
4
+ * Cohere pins an answer to a JSON schema with
5
+ * `responseFormat: { type: 'json_object', schema }`. The traceloop instrumentor
6
+ * records the request's model and sampling params but never the schema.
7
+ *
8
+ * The JS client sends camelCase (`responseFormat`) where the Python one sends
9
+ * snake_case, so both spellings are read: the instrumentor hands over whatever
10
+ * the caller passed.
11
+ */
12
+ export declare function readStructuredOutputSchema(params: any): unknown;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * Structured-output schema location for Cohere requests.
4
+ *
5
+ * Cohere pins an answer to a JSON schema with
6
+ * `responseFormat: { type: 'json_object', schema }`. The traceloop instrumentor
7
+ * records the request's model and sampling params but never the schema.
8
+ *
9
+ * The JS client sends camelCase (`responseFormat`) where the Python one sends
10
+ * snake_case, so both spellings are read: the instrumentor hands over whatever
11
+ * the caller passed.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.readStructuredOutputSchema = readStructuredOutputSchema;
15
+ function readStructuredOutputSchema(params) {
16
+ const responseFormat = params && (params.responseFormat || params.response_format);
17
+ return responseFormat && responseFormat.schema;
18
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Tool-call output parts for Cohere chat spans.
3
+ *
4
+ * `@traceloop/instrumentation-cohere` records the response as legacy indexed
5
+ * `gen_ai.completion.0.*` attributes, which carry a role and flat text and have
6
+ * no way to express a tool call, so the v1 client's `response.toolCalls` (bare
7
+ * `{name, parameters}` entries) reach the span nowhere.
8
+ *
9
+ * When the response carries tool calls this complement stamps the whole
10
+ * `gen_ai.output.messages` instead, in the standard role+parts shape, so the
11
+ * tool call normalizes to the same `tool_call` part every other provider
12
+ * produces. Calls without tool calls are left to the instrumentor's own
13
+ * attributes: there is nothing it fails to express about them.
14
+ *
15
+ * Like the chat token-usage complement it hooks the internal
16
+ * `CohereClient.prototype.__chat`, which runs while traceloop's `cohere.chat`
17
+ * span is active — so the stamp lands on that span regardless of patch order.
18
+ */
19
+ export declare const OUTPUT_MESSAGES_ATTRIBUTE = "gen_ai.output.messages";
20
+ /**
21
+ * The response as one assistant message, or [] when it carries no tool call
22
+ * (nothing the instrumentor's own attributes cannot express). The text the
23
+ * model emits alongside a tool call — its plan for using it — is kept as a
24
+ * leading text part so stamping this attribute loses nothing.
25
+ */
26
+ export declare function buildOutputMessages(result: any): any[];
27
+ export declare class CohereToolCallOutputInstrumentor {
28
+ private _patched;
29
+ instrument(): void;
30
+ uninstrument(): void;
31
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ /**
3
+ * Tool-call output parts for Cohere chat spans.
4
+ *
5
+ * `@traceloop/instrumentation-cohere` records the response as legacy indexed
6
+ * `gen_ai.completion.0.*` attributes, which carry a role and flat text and have
7
+ * no way to express a tool call, so the v1 client's `response.toolCalls` (bare
8
+ * `{name, parameters}` entries) reach the span nowhere.
9
+ *
10
+ * When the response carries tool calls this complement stamps the whole
11
+ * `gen_ai.output.messages` instead, in the standard role+parts shape, so the
12
+ * tool call normalizes to the same `tool_call` part every other provider
13
+ * produces. Calls without tool calls are left to the instrumentor's own
14
+ * attributes: there is nothing it fails to express about them.
15
+ *
16
+ * Like the chat token-usage complement it hooks the internal
17
+ * `CohereClient.prototype.__chat`, which runs while traceloop's `cohere.chat`
18
+ * span is active — so the stamp lands on that span regardless of patch order.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.CohereToolCallOutputInstrumentor = exports.OUTPUT_MESSAGES_ATTRIBUTE = void 0;
22
+ exports.buildOutputMessages = buildOutputMessages;
23
+ const api_1 = require("@opentelemetry/api");
24
+ exports.OUTPUT_MESSAGES_ATTRIBUTE = 'gen_ai.output.messages';
25
+ // Public `chat` resolves to the response body, but `__chat` resolves to the
26
+ // Fern wrapper `{ data, rawResponse }`; read the response off either shape.
27
+ function _responseBody(result) {
28
+ return result && result.data ? result.data : result;
29
+ }
30
+ /**
31
+ * The response as one assistant message, or [] when it carries no tool call
32
+ * (nothing the instrumentor's own attributes cannot express). The text the
33
+ * model emits alongside a tool call — its plan for using it — is kept as a
34
+ * leading text part so stamping this attribute loses nothing.
35
+ */
36
+ function buildOutputMessages(result) {
37
+ const response = _responseBody(result);
38
+ const toolCalls = response && response.toolCalls;
39
+ if (!Array.isArray(toolCalls) || !toolCalls.length)
40
+ return [];
41
+ const parts = [];
42
+ if (response.text)
43
+ parts.push({ type: 'text', content: String(response.text) });
44
+ for (const toolCall of toolCalls) {
45
+ // v1 assigns no call id, so the part carries none — unlike the providers
46
+ // whose API returns one.
47
+ if (toolCall && toolCall.name) {
48
+ parts.push({
49
+ type: 'tool_call',
50
+ name: String(toolCall.name),
51
+ arguments: toolCall.parameters || {},
52
+ });
53
+ }
54
+ }
55
+ if (!parts.length)
56
+ return [];
57
+ const message = { role: 'assistant', parts };
58
+ if (response.finishReason)
59
+ message.finish_reason = String(response.finishReason);
60
+ return [message];
61
+ }
62
+ class CohereToolCallOutputInstrumentor {
63
+ // [ownerPrototype, methodName, originalFunction] for uninstrument().
64
+ _patched = [];
65
+ instrument() {
66
+ let CohereClient;
67
+ try {
68
+ ({ CohereClient } = require('cohere-ai/Client'));
69
+ }
70
+ catch (err) {
71
+ throw new Error('weflayr.autoInstrument(COHERE): the cohere-ai client is not installed. ' +
72
+ 'Install it with: npm install cohere-ai\n' +
73
+ `Underlying error: ${err.message}`);
74
+ }
75
+ const owner = CohereClient.prototype;
76
+ const original = owner.__chat;
77
+ function wrapper(...args) {
78
+ // Captured synchronously, while traceloop's chat span is still active.
79
+ const span = api_1.trace.getActiveSpan();
80
+ const result = original.apply(this, args);
81
+ if (!span || !span.isRecording || !span.isRecording())
82
+ return result;
83
+ return Promise.resolve(result).then((response) => {
84
+ try {
85
+ const messages = buildOutputMessages(response);
86
+ if (messages.length) {
87
+ span.setAttribute(exports.OUTPUT_MESSAGES_ATTRIBUTE, JSON.stringify(messages));
88
+ }
89
+ }
90
+ catch {
91
+ // Never break the caller's Cohere call over an enrichment failure.
92
+ }
93
+ return response;
94
+ });
95
+ }
96
+ owner.__chat = wrapper;
97
+ this._patched.push([owner, '__chat', original]);
98
+ }
99
+ uninstrument() {
100
+ for (const [owner, methodName, original] of this._patched) {
101
+ owner[methodName] = original;
102
+ }
103
+ this._patched = [];
104
+ }
105
+ }
106
+ exports.CohereToolCallOutputInstrumentor = CohereToolCallOutputInstrumentor;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Tool definitions for Cohere chat spans.
3
+ *
4
+ * `@traceloop/instrumentation-cohere` records the request's model and message
5
+ * but never its `tools`, so a tool-using call carries no
6
+ * `gen_ai.tool.definitions`.
7
+ *
8
+ * Like the chat token-usage complement it hooks the internal
9
+ * `CohereClient.prototype.__chat`, which runs while traceloop's `cohere.chat`
10
+ * span is active — so the stamp lands on that span regardless of patch order.
11
+ */
12
+ export declare const TOOL_DEFINITIONS_ATTRIBUTE = "gen_ai.tool.definitions";
13
+ /**
14
+ * The request's tool definitions in the shape they go on the wire.
15
+ *
16
+ * The complement sees the request before the JS client serializes it, where the
17
+ * parameters still sit under the camelCase `parameterDefinitions`; the client
18
+ * renames it to `parameter_definitions` on the way out, which is what the
19
+ * Python client passes in already. Renaming it here is what lets both SDKs
20
+ * normalize a Cohere tool definition identically.
21
+ */
22
+ export declare function extractToolDefinitions(request: any): any[];
23
+ export declare class CohereToolDefinitionsInstrumentor {
24
+ private _patched;
25
+ instrument(): void;
26
+ uninstrument(): void;
27
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /**
3
+ * Tool definitions for Cohere chat spans.
4
+ *
5
+ * `@traceloop/instrumentation-cohere` records the request's model and message
6
+ * but never its `tools`, so a tool-using call carries no
7
+ * `gen_ai.tool.definitions`.
8
+ *
9
+ * Like the chat token-usage complement it hooks the internal
10
+ * `CohereClient.prototype.__chat`, which runs while traceloop's `cohere.chat`
11
+ * span is active — so the stamp lands on that span regardless of patch order.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.CohereToolDefinitionsInstrumentor = exports.TOOL_DEFINITIONS_ATTRIBUTE = void 0;
15
+ exports.extractToolDefinitions = extractToolDefinitions;
16
+ const api_1 = require("@opentelemetry/api");
17
+ exports.TOOL_DEFINITIONS_ATTRIBUTE = 'gen_ai.tool.definitions';
18
+ /**
19
+ * The request's tool definitions in the shape they go on the wire.
20
+ *
21
+ * The complement sees the request before the JS client serializes it, where the
22
+ * parameters still sit under the camelCase `parameterDefinitions`; the client
23
+ * renames it to `parameter_definitions` on the way out, which is what the
24
+ * Python client passes in already. Renaming it here is what lets both SDKs
25
+ * normalize a Cohere tool definition identically.
26
+ */
27
+ function extractToolDefinitions(request) {
28
+ const tools = request && request.tools;
29
+ if (!Array.isArray(tools))
30
+ return [];
31
+ return tools
32
+ .filter((tool) => tool && tool.name)
33
+ .map(({ parameterDefinitions, ...tool }) => parameterDefinitions === undefined
34
+ ? tool
35
+ : { ...tool, parameter_definitions: parameterDefinitions });
36
+ }
37
+ class CohereToolDefinitionsInstrumentor {
38
+ // [ownerPrototype, methodName, originalFunction] for uninstrument().
39
+ _patched = [];
40
+ instrument() {
41
+ let CohereClient;
42
+ try {
43
+ ({ CohereClient } = require('cohere-ai/Client'));
44
+ }
45
+ catch (err) {
46
+ throw new Error('weflayr.autoInstrument(COHERE): the cohere-ai client is not installed. ' +
47
+ 'Install it with: npm install cohere-ai\n' +
48
+ `Underlying error: ${err.message}`);
49
+ }
50
+ const owner = CohereClient.prototype;
51
+ const original = owner.__chat;
52
+ function wrapper(...args) {
53
+ const span = api_1.trace.getActiveSpan();
54
+ try {
55
+ const definitions = extractToolDefinitions(args[0]);
56
+ if (definitions.length && span && span.isRecording && span.isRecording()) {
57
+ span.setAttribute(exports.TOOL_DEFINITIONS_ATTRIBUTE, JSON.stringify(definitions));
58
+ }
59
+ }
60
+ catch {
61
+ // Never break the caller's Cohere call over an enrichment failure.
62
+ }
63
+ return original.apply(this, args);
64
+ }
65
+ owner.__chat = wrapper;
66
+ this._patched.push([owner, '__chat', original]);
67
+ }
68
+ uninstrument() {
69
+ for (const [owner, methodName, original] of this._patched) {
70
+ owner[methodName] = original;
71
+ }
72
+ this._patched = [];
73
+ }
74
+ }
75
+ exports.CohereToolDefinitionsInstrumentor = CohereToolDefinitionsInstrumentor;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Cohere telemetry complement — the registered orchestrator.
3
+ *
4
+ * Wires the weflayr-supplied patches the traceloop Cohere instrumentor misses:
5
+ * - chat token usage (traceloop reads the obsolete usage shape and records
6
+ * zero chat tokens),
7
+ * - the embeddings endpoint it doesn't cover,
8
+ * - the request's structured-output schema, and
9
+ * - function calling: it records neither the request's tools nor the
10
+ * response's tool calls.
11
+ */
12
+ export declare class CohereTelemetryInstrumentor {
13
+ private _subInstrumentors;
14
+ constructor();
15
+ instrument(instrumentation: any): void;
16
+ uninstrument(): void;
17
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Cohere telemetry complement — the registered orchestrator.
4
+ *
5
+ * Wires the weflayr-supplied patches the traceloop Cohere instrumentor misses:
6
+ * - chat token usage (traceloop reads the obsolete usage shape and records
7
+ * zero chat tokens),
8
+ * - the embeddings endpoint it doesn't cover,
9
+ * - the request's structured-output schema, and
10
+ * - function calling: it records neither the request's tools nor the
11
+ * response's tool calls.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.CohereTelemetryInstrumentor = void 0;
15
+ const get_structured_output_schema_telemetry_1 = require("../shared/get_structured_output_schema_telemetry");
16
+ const get_chat_telemetry_1 = require("./get_chat_telemetry");
17
+ const get_embeddings_telemetry_1 = require("./get_embeddings_telemetry");
18
+ const get_structured_output_schema_telemetry_2 = require("./get_structured_output_schema_telemetry");
19
+ const get_tool_call_output_telemetry_1 = require("./get_tool_call_output_telemetry");
20
+ const get_tool_definitions_telemetry_1 = require("./get_tool_definitions_telemetry");
21
+ class CohereTelemetryInstrumentor {
22
+ _subInstrumentors;
23
+ constructor() {
24
+ this._subInstrumentors = [
25
+ new get_chat_telemetry_1.CohereChatTokenUsageInstrumentor(),
26
+ new get_embeddings_telemetry_1.CohereEmbeddingsInstrumentor(),
27
+ new get_structured_output_schema_telemetry_1.TraceloopStructuredOutputSchemaInstrumentor(get_structured_output_schema_telemetry_2.readStructuredOutputSchema),
28
+ new get_tool_definitions_telemetry_1.CohereToolDefinitionsInstrumentor(),
29
+ new get_tool_call_output_telemetry_1.CohereToolCallOutputInstrumentor(),
30
+ ];
31
+ }
32
+ instrument(instrumentation) {
33
+ for (const sub of this._subInstrumentors)
34
+ sub.instrument(instrumentation);
35
+ }
36
+ uninstrument() {
37
+ // Newest first: the token-usage, tool-definition and tool-call complements
38
+ // all wrap `CohereClient.prototype.__chat`, so unwinding in instrument
39
+ // order would reinstall an earlier wrapper instead of the true original.
40
+ for (const sub of [...this._subInstrumentors].reverse())
41
+ sub.uninstrument();
42
+ }
43
+ }
44
+ exports.CohereTelemetryInstrumentor = CohereTelemetryInstrumentor;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Hand-written OTel instrumentor for the ElevenLabs audio clients.
3
+ *
4
+ * No official OpenTelemetry instrumentor exists for the ElevenLabs SDK (it's
5
+ * audio, not an LLM), so this ships inside weflayr. It wraps the Text-to-Speech
6
+ * and Speech-to-Text entrypoints to emit one `gen_ai.*` span per call, which
7
+ * flows through the standard span processor -> exporter with no new transport code.
8
+ *
9
+ * The billable unit differs by API, so each span records the one ElevenLabs bills:
10
+ * - Text-to-Speech is billed per input character -> `gen_ai.usage.input_characters`.
11
+ * - Speech-to-Text is billed per second of audio -> `gen_ai.usage.input_seconds`.
12
+ *
13
+ * Entrypoints come in three result shapes, independent of which API they belong to:
14
+ * - *byte stream* methods resolve to a `ReadableStream` of audio chunks;
15
+ * - *object stream* methods resolve to an async-iterable of chunk objects;
16
+ * - *unary* methods resolve to the full response.
17
+ * The HTTP request -- plus any error -- only happens while a stream is awaited
18
+ * and consumed, so the span is started eagerly (to capture the
19
+ * `propagateMetadata` context active at the call site) and ended once the result
20
+ * is exhausted (streams) or returned (unary), giving an `elapsed_ms` that covers
21
+ * the whole call. The per-second billable unit is read off the STT response.
22
+ */
23
+ export declare class ElevenLabsInstrumentor {
24
+ private _patched;
25
+ instrument(): void;
26
+ uninstrument(): void;
27
+ private _wrap;
28
+ }