braintrust 3.25.0 → 3.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 (78) hide show
  1. package/NOTICE +6 -0
  2. package/dev/dist/index.d.mts +130 -2
  3. package/dev/dist/index.d.ts +130 -2
  4. package/dev/dist/index.js +2455 -1116
  5. package/dev/dist/index.mjs +1599 -260
  6. package/dist/apply-auto-instrumentation.js +439 -398
  7. package/dist/apply-auto-instrumentation.mjs +242 -201
  8. package/dist/auto-instrumentations/bundler/esbuild.cjs +853 -337
  9. package/dist/auto-instrumentations/bundler/esbuild.d.mts +4 -4
  10. package/dist/auto-instrumentations/bundler/esbuild.d.ts +4 -4
  11. package/dist/auto-instrumentations/bundler/esbuild.mjs +5 -8
  12. package/dist/auto-instrumentations/bundler/next.cjs +852 -356
  13. package/dist/auto-instrumentations/bundler/next.mjs +6 -29
  14. package/dist/auto-instrumentations/bundler/rollup.cjs +853 -337
  15. package/dist/auto-instrumentations/bundler/rollup.d.mts +4 -4
  16. package/dist/auto-instrumentations/bundler/rollup.d.ts +4 -4
  17. package/dist/auto-instrumentations/bundler/rollup.mjs +5 -8
  18. package/dist/auto-instrumentations/bundler/vite.cjs +853 -337
  19. package/dist/auto-instrumentations/bundler/vite.d.mts +4 -4
  20. package/dist/auto-instrumentations/bundler/vite.d.ts +4 -4
  21. package/dist/auto-instrumentations/bundler/vite.mjs +5 -8
  22. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1006 -266
  23. package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +20 -12
  24. package/dist/auto-instrumentations/bundler/webpack.cjs +853 -337
  25. package/dist/auto-instrumentations/bundler/webpack.d.mts +4 -4
  26. package/dist/auto-instrumentations/bundler/webpack.d.ts +4 -4
  27. package/dist/auto-instrumentations/bundler/webpack.mjs +5 -4
  28. package/dist/auto-instrumentations/{chunk-JPVCUKTY.mjs → chunk-6E22MYSW.mjs} +165 -73
  29. package/dist/auto-instrumentations/{chunk-VT6DDNKM.mjs → chunk-AKKPLXTP.mjs} +631 -194
  30. package/dist/auto-instrumentations/chunk-NRE4QUQR.mjs +509 -0
  31. package/dist/auto-instrumentations/{chunk-7P6563SW.mjs → chunk-V5LEODRX.mjs} +2 -6
  32. package/dist/auto-instrumentations/{chunk-M6DLIJ2Z.mjs → chunk-XYN63IG5.mjs} +124 -194
  33. package/dist/auto-instrumentations/{chunk-CZ24KNHT.mjs → chunk-XZHHE4Y3.mjs} +77 -68
  34. package/dist/auto-instrumentations/hook.mjs +247 -182
  35. package/dist/auto-instrumentations/index.cjs +557 -48
  36. package/dist/auto-instrumentations/index.d.mts +6 -2
  37. package/dist/auto-instrumentations/index.d.ts +6 -2
  38. package/dist/auto-instrumentations/index.mjs +6 -1
  39. package/dist/auto-instrumentations/loader/cjs-patch.cjs +492 -195
  40. package/dist/auto-instrumentations/loader/cjs-patch.d.mts +2 -2
  41. package/dist/auto-instrumentations/loader/cjs-patch.d.ts +2 -2
  42. package/dist/auto-instrumentations/loader/cjs-patch.mjs +3 -2
  43. package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
  44. package/dist/auto-instrumentations/plugin-B-aZh7EP.d.ts +30 -0
  45. package/dist/auto-instrumentations/plugin-Bnj4E_6B.d.mts +30 -0
  46. package/dist/auto-instrumentations/{types-RNPaKi9o.d.mts → types-C1fVeiCp.d.mts} +1 -1
  47. package/dist/auto-instrumentations/{types-RNPaKi9o.d.ts → types-C1fVeiCp.d.ts} +1 -1
  48. package/dist/browser.d.mts +817 -197
  49. package/dist/browser.d.ts +817 -197
  50. package/dist/browser.js +1883 -265
  51. package/dist/browser.mjs +1883 -265
  52. package/dist/{chunk-ABR2QWDP.mjs → chunk-PN7EWK66.mjs} +581 -133
  53. package/dist/{chunk-GSIDVFE6.js → chunk-VRZZQPAA.js} +1670 -736
  54. package/dist/{chunk-P25IOOU4.js → chunk-VYNNEKSA.js} +586 -138
  55. package/dist/{chunk-2SANLSWX.mjs → chunk-XIZOM2HO.mjs} +1052 -118
  56. package/dist/cli.js +1601 -263
  57. package/dist/edge-light.d.mts +1 -1
  58. package/dist/edge-light.d.ts +1 -1
  59. package/dist/edge-light.js +1883 -268
  60. package/dist/edge-light.mjs +1883 -268
  61. package/dist/index.d.mts +817 -197
  62. package/dist/index.d.ts +817 -197
  63. package/dist/index.js +695 -435
  64. package/dist/index.mjs +264 -4
  65. package/dist/instrumentation/index.d.mts +130 -6
  66. package/dist/instrumentation/index.d.ts +130 -6
  67. package/dist/instrumentation/index.js +1510 -80
  68. package/dist/instrumentation/index.mjs +1510 -80
  69. package/dist/vitest-evals-reporter.js +16 -16
  70. package/dist/vitest-evals-reporter.mjs +2 -2
  71. package/dist/workerd.d.mts +1 -1
  72. package/dist/workerd.d.ts +1 -1
  73. package/dist/workerd.js +1883 -268
  74. package/dist/workerd.mjs +1883 -268
  75. package/licenses/node-diagnostics-channel/LICENSE +19 -0
  76. package/package.json +34 -35
  77. package/dist/auto-instrumentations/plugin-D0KHwSJv.d.mts +0 -44
  78. package/dist/auto-instrumentations/plugin-G6fgxk1b.d.ts +0 -44
@@ -1,10 +1,13 @@
1
1
  import {
2
+ GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
2
3
  applySpecialCasePatch,
3
4
  create,
4
5
  getPackageName,
5
6
  getPackageVersion,
6
- installMastraExporterFactory
7
- } from "./chunk-VT6DDNKM.mjs";
7
+ installMastraExporterFactory,
8
+ newGlobalTracingChannel,
9
+ setGlobalHookErrorReporter
10
+ } from "./chunk-AKKPLXTP.mjs";
8
11
 
9
12
  // src/auto-instrumentations/hook.mts
10
13
  import { register } from "module";
@@ -26,6 +29,9 @@ var envIntegrationAliases = {
26
29
  strandsagentsdk: "strandsAgentSDK",
27
30
  "strands-agent-sdk": "strandsAgentSDK",
28
31
  "@strands-agents/sdk": "strandsAgentSDK",
32
+ agents: "cloudflareAgents",
33
+ "cloudflare-agents": "cloudflareAgents",
34
+ cloudflareagents: "cloudflareAgents",
29
35
  anthropic: "anthropic",
30
36
  aisdk: "aisdk",
31
37
  "ai-sdk": "aisdk",
@@ -33,6 +39,9 @@ var envIntegrationAliases = {
33
39
  vercel: "vercel",
34
40
  claudeagentsdk: "claudeAgentSDK",
35
41
  "claude-agent-sdk": "claudeAgentSDK",
42
+ cloudflareaichat: "cloudflareAIChat",
43
+ "cloudflare-ai-chat": "cloudflareAIChat",
44
+ "@cloudflare/ai-chat": "cloudflareAIChat",
36
45
  cursor: "cursor",
37
46
  "cursor-sdk": "cursorSDK",
38
47
  cursorsdk: "cursorSDK",
@@ -47,6 +56,8 @@ var envIntegrationAliases = {
47
56
  "google-genai": "googleGenAI",
48
57
  googlegenai: "googleGenAI",
49
58
  huggingface: "huggingface",
59
+ "@huggingface/transformers": "huggingface",
60
+ transformers: "huggingface",
50
61
  openrouter: "openrouter",
51
62
  openrouteragent: "openrouterAgent",
52
63
  "openrouter-agent": "openrouterAgent",
@@ -103,73 +114,6 @@ var DefaultAsyncLocalStorage = class {
103
114
  return void 0;
104
115
  }
105
116
  };
106
- var DefaultChannel = class {
107
- constructor(name) {
108
- this.name = name;
109
- }
110
- name;
111
- hasSubscribers = false;
112
- subscribe(_subscription) {
113
- }
114
- unsubscribe(_subscription) {
115
- return false;
116
- }
117
- bindStore(_store, _transform) {
118
- }
119
- unbindStore(_store) {
120
- return false;
121
- }
122
- publish(_message) {
123
- }
124
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
125
- runStores(_message, fn, thisArg, ...args) {
126
- return fn.apply(thisArg, args);
127
- }
128
- };
129
- var DefaultTracingChannel = class {
130
- start;
131
- end;
132
- asyncStart;
133
- asyncEnd;
134
- error;
135
- constructor(nameOrChannels) {
136
- if (typeof nameOrChannels === "string") {
137
- this.start = new DefaultChannel(`tracing:${nameOrChannels}:start`);
138
- this.end = new DefaultChannel(`tracing:${nameOrChannels}:end`);
139
- this.asyncStart = new DefaultChannel(
140
- `tracing:${nameOrChannels}:asyncStart`
141
- );
142
- this.asyncEnd = new DefaultChannel(`tracing:${nameOrChannels}:asyncEnd`);
143
- this.error = new DefaultChannel(`tracing:${nameOrChannels}:error`);
144
- return;
145
- }
146
- this.start = nameOrChannels.start ?? new DefaultChannel("tracing:start");
147
- this.end = nameOrChannels.end ?? new DefaultChannel("tracing:end");
148
- this.asyncStart = nameOrChannels.asyncStart ?? new DefaultChannel("tracing:asyncStart");
149
- this.asyncEnd = nameOrChannels.asyncEnd ?? new DefaultChannel("tracing:asyncEnd");
150
- this.error = nameOrChannels.error ?? new DefaultChannel("tracing:error");
151
- }
152
- get hasSubscribers() {
153
- return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
154
- }
155
- subscribe(_handlers) {
156
- }
157
- unsubscribe(_handlers) {
158
- return false;
159
- }
160
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
- traceSync(fn, _message, thisArg, ...args) {
162
- return fn.apply(thisArg, args);
163
- }
164
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
- tracePromise(fn, _message, thisArg, ...args) {
166
- return fn.apply(thisArg, args);
167
- }
168
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
- traceCallback(fn, _position, _message, thisArg, ...args) {
170
- return fn.apply(thisArg, args);
171
- }
172
- };
173
117
  var iso = {
174
118
  buildType: "unknown",
175
119
  // Will be set by configureBrowser() or configureNode()
@@ -180,7 +124,7 @@ var iso = {
180
124
  getCallerLocation: () => void 0,
181
125
  newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
182
126
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
- newTracingChannel: (nameOrChannels) => new DefaultTracingChannel(nameOrChannels),
127
+ newTracingChannel: (nameOrChannels) => newGlobalTracingChannel(nameOrChannels),
184
128
  processOn: (_0, _1) => {
185
129
  },
186
130
  basename: (filepath) => filepath.split(/[\\/]/).pop() || filepath,
@@ -293,6 +237,9 @@ var debugLogger = {
293
237
  return createDebugLogger(state2);
294
238
  }
295
239
  };
240
+ setGlobalHookErrorReporter((error) => {
241
+ debugLogger.error("Global instrumentation hook error:", error);
242
+ });
296
243
 
297
244
  // src/logger.ts
298
245
  import { v4 as uuidv42 } from "uuid";
@@ -1935,7 +1882,8 @@ var ApiKey = z6.object({
1935
1882
  user_email: z6.union([z6.string(), z6.null()]).optional(),
1936
1883
  user_given_name: z6.union([z6.string(), z6.null()]).optional(),
1937
1884
  user_family_name: z6.union([z6.string(), z6.null()]).optional(),
1938
- org_id: z6.union([z6.string(), z6.null()]).optional()
1885
+ org_id: z6.union([z6.string(), z6.null()]).optional(),
1886
+ expires_at: z6.union([z6.string(), z6.null()]).optional()
1939
1887
  });
1940
1888
  var TriggeredFunctionState = z6.object({
1941
1889
  triggered_xact_id: z6.string(),
@@ -2055,6 +2003,7 @@ var TopicMapData = z6.object({
2055
2003
  topic_names: z6.record(z6.string()).optional(),
2056
2004
  generation_settings: TopicMapGenerationSettings.optional(),
2057
2005
  disable_reconciliation: z6.boolean().optional(),
2006
+ reconcile_mode: z6.enum(["evolve", "names_only"]).optional(),
2058
2007
  distance_threshold: z6.number().optional(),
2059
2008
  btql_filter: z6.string().optional(),
2060
2009
  automation_btql_filter: z6.string().optional()
@@ -2635,7 +2584,12 @@ var ModelParams = z6.union([
2635
2584
  }).partial().passthrough()
2636
2585
  ]);
2637
2586
  var PromptOptionsNullish = z6.union([
2638
- z6.object({ model: z6.string(), params: ModelParams, position: z6.string() }).partial(),
2587
+ z6.object({
2588
+ model: z6.string(),
2589
+ params: ModelParams,
2590
+ position: z6.string(),
2591
+ endpoint_name: z6.union([z6.string(), z6.null()])
2592
+ }).partial(),
2639
2593
  z6.null()
2640
2594
  ]);
2641
2595
  var PromptParserNullish = z6.union([
@@ -2649,11 +2603,25 @@ var PromptParserNullish = z6.union([
2649
2603
  }),
2650
2604
  z6.null()
2651
2605
  ]);
2606
+ var PreprocessorSavedFunctionId = z6.union([
2607
+ z6.object({
2608
+ type: z6.literal("function"),
2609
+ id: z6.string(),
2610
+ version: z6.string().optional()
2611
+ }),
2612
+ z6.object({
2613
+ type: z6.literal("global"),
2614
+ name: z6.string(),
2615
+ function_type: z6.literal("preprocessor").optional().default("preprocessor")
2616
+ }),
2617
+ z6.null()
2618
+ ]);
2652
2619
  var PromptDataNullish = z6.union([
2653
2620
  z6.object({
2654
2621
  prompt: PromptBlockDataNullish,
2655
2622
  options: PromptOptionsNullish,
2656
2623
  parser: PromptParserNullish,
2624
+ preprocessor: PreprocessorSavedFunctionId,
2657
2625
  tool_functions: z6.union([z6.array(SavedFunctionId), z6.null()]),
2658
2626
  template_format: z6.union([
2659
2627
  z6.enum(["mustache", "nunjucks", "none"]),
@@ -2855,6 +2823,7 @@ var PromptData = z6.object({
2855
2823
  prompt: PromptBlockDataNullish,
2856
2824
  options: PromptOptionsNullish,
2857
2825
  parser: PromptParserNullish,
2826
+ preprocessor: PreprocessorSavedFunctionId,
2858
2827
  tool_functions: z6.union([z6.array(SavedFunctionId), z6.null()]),
2859
2828
  template_format: z6.union([
2860
2829
  z6.enum(["mustache", "nunjucks", "none"]),
@@ -3017,7 +2986,8 @@ var InvokeFunction = FunctionId.and(
3017
2986
  mode: StreamingMode,
3018
2987
  strict: z6.union([z6.boolean(), z6.null()]),
3019
2988
  mcp_auth: z6.record(z6.object({ oauth_token: z6.string() }).partial()),
3020
- overrides: z6.union([z6.object({}).partial().passthrough(), z6.null()])
2989
+ overrides: z6.union([z6.object({}).partial().passthrough(), z6.null()]),
2990
+ endpoint_name: z6.union([z6.string(), z6.null()])
3021
2991
  }).partial()
3022
2992
  );
3023
2993
  var MCPServer = z6.object({
@@ -3081,6 +3051,24 @@ var Organization = z6.object({
3081
3051
  created: z6.union([z6.string(), z6.null()]).optional(),
3082
3052
  image_rendering_mode: ImageRenderingMode.optional()
3083
3053
  });
3054
+ var RetentionObjectType = z6.enum([
3055
+ "project_logs",
3056
+ "experiment",
3057
+ "dataset"
3058
+ ]);
3059
+ var OrgAutomation = z6.object({
3060
+ id: z6.string().uuid(),
3061
+ org_id: z6.string().uuid(),
3062
+ user_id: z6.union([z6.string(), z6.null()]).optional(),
3063
+ created: z6.union([z6.string(), z6.null()]).optional(),
3064
+ name: z6.string(),
3065
+ description: z6.union([z6.string(), z6.null()]).optional(),
3066
+ config: z6.object({
3067
+ event_type: z6.literal("retention"),
3068
+ object_type: RetentionObjectType,
3069
+ retention_days: z6.number().int().gte(0)
3070
+ })
3071
+ });
3084
3072
  var ProjectSettings = z6.union([
3085
3073
  z6.object({
3086
3074
  comparison_key: z6.union([z6.string(), z6.null()]),
@@ -3107,6 +3095,7 @@ var ProjectSettings = z6.union([
3107
3095
  z6.null()
3108
3096
  ]),
3109
3097
  disable_realtime_queries: z6.union([z6.boolean(), z6.null()]),
3098
+ monitor_charts_use_metrics_start: z6.union([z6.boolean(), z6.null()]),
3110
3099
  default_preprocessor: NullableSavedFunctionId
3111
3100
  }).partial(),
3112
3101
  z6.null()
@@ -3121,11 +3110,6 @@ var Project = z6.object({
3121
3110
  user_id: z6.union([z6.string(), z6.null()]).optional(),
3122
3111
  settings: ProjectSettings.optional()
3123
3112
  });
3124
- var RetentionObjectType = z6.enum([
3125
- "project_logs",
3126
- "experiment",
3127
- "dataset"
3128
- ]);
3129
3113
  var TopicAutomationFacetModel = z6.union([
3130
3114
  z6.enum(["brain-facet-latest", "brain-facet-1", "brain-facet-2"]),
3131
3115
  z6.null()
@@ -3236,7 +3220,7 @@ var ProjectAutomation = z6.object({
3236
3220
  z6.object({
3237
3221
  event_type: z6.literal("retention"),
3238
3222
  object_type: RetentionObjectType,
3239
- retention_days: z6.number().gte(0)
3223
+ retention_days: z6.number().int().gte(0)
3240
3224
  }),
3241
3225
  z6.object({
3242
3226
  event_type: z6.literal("environment_update"),
@@ -3408,7 +3392,12 @@ var Prompt = z6.object({
3408
3392
  metadata: z6.union([z6.object({}).partial().passthrough(), z6.null()]).optional(),
3409
3393
  function_type: FunctionTypeEnumNullish.optional()
3410
3394
  });
3411
- var PromptOptions = z6.object({ model: z6.string(), params: ModelParams, position: z6.string() }).partial();
3395
+ var PromptOptions = z6.object({
3396
+ model: z6.string(),
3397
+ params: ModelParams,
3398
+ position: z6.string(),
3399
+ endpoint_name: z6.union([z6.string(), z6.null()])
3400
+ }).partial();
3412
3401
  var PromptSessionEvent = z6.object({
3413
3402
  id: z6.string(),
3414
3403
  _xact_id: z6.string(),
@@ -3491,7 +3480,8 @@ var RunEval = z6.object({
3491
3480
  stop_token: z6.union([z6.string(), z6.null()]).optional(),
3492
3481
  extra_messages: z6.string().optional(),
3493
3482
  tags: z6.array(z6.string()).optional(),
3494
- mcp_auth: z6.record(z6.object({ oauth_token: z6.string() }).partial()).optional()
3483
+ mcp_auth: z6.record(z6.object({ oauth_token: z6.string() }).partial()).optional(),
3484
+ endpoint_name: z6.union([z6.string(), z6.null()]).optional()
3495
3485
  });
3496
3486
  var ServiceToken = z6.object({
3497
3487
  id: z6.string().uuid(),
@@ -3501,7 +3491,8 @@ var ServiceToken = z6.object({
3501
3491
  service_account_id: z6.union([z6.string(), z6.null()]).optional(),
3502
3492
  service_account_email: z6.union([z6.string(), z6.null()]).optional(),
3503
3493
  service_account_name: z6.union([z6.string(), z6.null()]).optional(),
3504
- org_id: z6.union([z6.string(), z6.null()]).optional()
3494
+ org_id: z6.union([z6.string(), z6.null()]).optional(),
3495
+ expires_at: z6.union([z6.string(), z6.null()]).optional()
3505
3496
  });
3506
3497
  var SpanIFrame = z6.object({
3507
3498
  id: z6.string().uuid(),
@@ -3623,6 +3614,13 @@ var ViewOptions = z6.union([
3623
3614
  }),
3624
3615
  z6.null()
3625
3616
  ]),
3617
+ pointSizeMetric: z6.union([
3618
+ z6.object({
3619
+ type: z6.enum(["none", "score", "metric", "metadata"]),
3620
+ value: z6.string()
3621
+ }),
3622
+ z6.null()
3623
+ ]),
3626
3624
  xAxisAggregation: z6.union([z6.string(), z6.null()]),
3627
3625
  chartAnnotations: z6.union([
3628
3626
  z6.array(z6.object({ id: z6.string(), text: z6.string() })),
@@ -4738,6 +4736,8 @@ var INSTRUMENTATION_NAMES = {
4738
4736
  BEDROCK_RUNTIME: "bedrock-runtime",
4739
4737
  BRAINTRUST_JS_LOGGER: "braintrust-js-logger",
4740
4738
  CLAUDE_AGENT_SDK: "claude-agent-sdk",
4739
+ CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
4740
+ CLOUDFLARE_AGENTS: "cloudflare-agents",
4741
4741
  COHERE: "cohere",
4742
4742
  CURSOR_SDK: "cursor-sdk",
4743
4743
  EVE: "eve",
@@ -4763,7 +4763,7 @@ var INSTRUMENTATION_NAMES = {
4763
4763
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
4764
4764
  "braintrust.spanInstrumentationName"
4765
4765
  );
4766
- var SDK_VERSION = true ? "3.25.0" : "0.0.0";
4766
+ var SDK_VERSION = true ? "3.26.0" : "0.0.0";
4767
4767
  function withSpanInstrumentationName(args, instrumentationName) {
4768
4768
  return {
4769
4769
  ...args,
@@ -4958,12 +4958,13 @@ function applyMaskingToField(maskingFunction, data, fieldName) {
4958
4958
  var INITIAL_SPAN_WRITE_AS_MERGE = /* @__PURE__ */ Symbol(
4959
4959
  "braintrust.initial-span-write-as-merge"
4960
4960
  );
4961
+ var INTERNAL_SPAN_CONTEXT = /* @__PURE__ */ Symbol("braintrust.internal-span-context");
4961
4962
  var BRAINTRUST_CURRENT_SPAN_STORE = /* @__PURE__ */ Symbol.for(
4962
4963
  "braintrust.currentSpanStore"
4963
4964
  );
4964
4965
  var ContextManager = class {
4965
4966
  /**
4966
- * Returns the value to store in the ALS bound to a TracingChannel's start event.
4967
+ * Returns the value to store in the ALS bound to a global hook's start event.
4967
4968
  * In default mode this is the Span itself; in OTEL mode it is the OTEL Context
4968
4969
  * containing the span so that OTEL's own ALS stores a proper Context object.
4969
4970
  */
@@ -8229,7 +8230,7 @@ var SpanImpl = class _SpanImpl {
8229
8230
  start: args.startTime ?? getCurrentUnixTimestamp()
8230
8231
  },
8231
8232
  context: mergeSpanOriginContext(
8232
- { ...callerLocation },
8233
+ { ...callerLocation, ...args[INTERNAL_SPAN_CONTEXT] },
8233
8234
  instrumentationName,
8234
8235
  this._state.spanOriginEnvironment
8235
8236
  ),
@@ -9970,6 +9971,74 @@ var claudeAgentSDKConfigs = [
9970
9971
  }
9971
9972
  ];
9972
9973
 
9974
+ // src/instrumentation/plugins/cloudflare-ai-chat-channels.ts
9975
+ var cloudflareAIChatChannels = defineChannels(
9976
+ "@cloudflare/ai-chat",
9977
+ {
9978
+ runExclusiveChatTurn: channel({
9979
+ channelName: "AIChatAgent._runExclusiveChatTurn",
9980
+ kind: "async"
9981
+ }),
9982
+ onChatResponse: channel({
9983
+ channelName: "AIChatAgent.onChatResponse",
9984
+ kind: "sync-stream"
9985
+ })
9986
+ },
9987
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AI_CHAT }
9988
+ );
9989
+
9990
+ // src/auto-instrumentations/configs/cloudflare-ai-chat.ts
9991
+ var cloudflareAIChatVersionRange = ">=0.9.0 <0.10.0";
9992
+ var cloudflareAIChatConfigs = [
9993
+ {
9994
+ // AIChatAgent subclasses replace onChatMessage, so there is no stable
9995
+ // public implementation for the transformer to target. This runner is
9996
+ // the narrowest shared boundary around every chat turn; keep the version
9997
+ // range tight because it is an internal method.
9998
+ channelName: cloudflareAIChatChannels.runExclusiveChatTurn.channelName,
9999
+ module: {
10000
+ name: "@cloudflare/ai-chat",
10001
+ versionRange: cloudflareAIChatVersionRange,
10002
+ filePath: "dist/index.js"
10003
+ },
10004
+ functionQuery: {
10005
+ className: "AIChatAgent",
10006
+ methodName: "_runExclusiveChatTurn",
10007
+ kind: "Async"
10008
+ }
10009
+ }
10010
+ ];
10011
+
10012
+ // src/instrumentation/plugins/cloudflare-agents-channels.ts
10013
+ var cloudflareAgentsChannels = defineChannels(
10014
+ "agents",
10015
+ {
10016
+ runAgentTool: channel({
10017
+ channelName: "Agent.runAgentTool",
10018
+ kind: "async"
10019
+ })
10020
+ },
10021
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AGENTS }
10022
+ );
10023
+
10024
+ // src/auto-instrumentations/configs/cloudflare-agents.ts
10025
+ var cloudflareAgentsVersionRange = ">=0.17.0 <0.18.0";
10026
+ var cloudflareAgentsConfigs = [
10027
+ {
10028
+ channelName: cloudflareAgentsChannels.runAgentTool.channelName,
10029
+ module: {
10030
+ name: "agents",
10031
+ versionRange: cloudflareAgentsVersionRange,
10032
+ filePath: "dist/index.js"
10033
+ },
10034
+ functionQuery: {
10035
+ className: "Agent",
10036
+ methodName: "runAgentTool",
10037
+ kind: "Async"
10038
+ }
10039
+ }
10040
+ ];
10041
+
9973
10042
  // src/instrumentation/plugins/cohere-channels.ts
9974
10043
  var cohereChannels = defineChannels(
9975
10044
  "cohere-ai",
@@ -11332,6 +11401,83 @@ var huggingFaceConfigs = [
11332
11401
  }
11333
11402
  ];
11334
11403
 
11404
+ // src/instrumentation/plugins/huggingface-transformers-channels.ts
11405
+ var huggingFaceTransformersChannels = defineChannels(
11406
+ "@huggingface/transformers",
11407
+ {
11408
+ pipeline: channel({
11409
+ channelName: "pipeline",
11410
+ kind: "async"
11411
+ }),
11412
+ pipelineCall: channel({
11413
+ channelName: "pipeline.call",
11414
+ kind: "async"
11415
+ })
11416
+ },
11417
+ { instrumentationName: INSTRUMENTATION_NAMES.HUGGINGFACE }
11418
+ );
11419
+
11420
+ // src/auto-instrumentations/configs/huggingface-transformers.ts
11421
+ var moduleFiles = [
11422
+ {
11423
+ filePath: "dist/transformers.mjs",
11424
+ versionRange: ">=3.0.0 <3.4.0"
11425
+ },
11426
+ {
11427
+ filePath: "dist/transformers.cjs",
11428
+ versionRange: ">=3.0.0 <3.4.0"
11429
+ },
11430
+ {
11431
+ filePath: "dist/transformers.js",
11432
+ versionRange: ">=3.0.0 <3.4.0"
11433
+ },
11434
+ {
11435
+ filePath: "dist/transformers.node.mjs",
11436
+ versionRange: ">=3.4.0 <5.0.0"
11437
+ },
11438
+ {
11439
+ filePath: "dist/transformers.node.cjs",
11440
+ versionRange: ">=3.4.0 <5.0.0"
11441
+ },
11442
+ {
11443
+ filePath: "dist/transformers.web.js",
11444
+ versionRange: ">=3.4.0 <5.0.0"
11445
+ }
11446
+ ];
11447
+ var pipelineClasses = [
11448
+ "TextGenerationPipeline",
11449
+ "Text2TextGenerationPipeline",
11450
+ "FeatureExtractionPipeline",
11451
+ "QuestionAnsweringPipeline"
11452
+ ];
11453
+ var huggingFaceTransformersConfigs = moduleFiles.flatMap(({ filePath, versionRange: versionRange2 }) => [
11454
+ {
11455
+ channelName: huggingFaceTransformersChannels.pipeline.channelName,
11456
+ module: {
11457
+ name: "@huggingface/transformers",
11458
+ versionRange: versionRange2,
11459
+ filePath
11460
+ },
11461
+ functionQuery: {
11462
+ functionName: "pipeline",
11463
+ kind: "Async"
11464
+ }
11465
+ },
11466
+ ...pipelineClasses.map((className) => ({
11467
+ channelName: huggingFaceTransformersChannels.pipelineCall.channelName,
11468
+ module: {
11469
+ name: "@huggingface/transformers",
11470
+ versionRange: versionRange2,
11471
+ filePath
11472
+ },
11473
+ functionQuery: {
11474
+ className,
11475
+ methodName: "_call",
11476
+ kind: "Async"
11477
+ }
11478
+ }))
11479
+ ]);
11480
+
11335
11481
  // src/instrumentation/plugins/langchain-channels.ts
11336
11482
  var langChainChannels = defineChannels(
11337
11483
  "@langchain/core",
@@ -12350,6 +12496,14 @@ var defaultInstrumentationConfigGroups = [
12350
12496
  integrations: ["claudeAgentSDK"],
12351
12497
  configs: claudeAgentSDKConfigs
12352
12498
  },
12499
+ {
12500
+ integrations: ["cloudflareAIChat"],
12501
+ configs: cloudflareAIChatConfigs
12502
+ },
12503
+ {
12504
+ integrations: ["cloudflareAgents"],
12505
+ configs: cloudflareAgentsConfigs
12506
+ },
12353
12507
  { integrations: ["cursor", "cursorSDK"], configs: cursorSDKConfigs },
12354
12508
  {
12355
12509
  integrations: ["openAIAgents"],
@@ -12359,7 +12513,10 @@ var defaultInstrumentationConfigGroups = [
12359
12513
  integrations: ["google", "googleGenAI"],
12360
12514
  configs: googleGenAIConfigs
12361
12515
  },
12362
- { integrations: ["huggingface"], configs: huggingFaceConfigs },
12516
+ {
12517
+ integrations: ["huggingface"],
12518
+ configs: [...huggingFaceConfigs, ...huggingFaceTransformersConfigs]
12519
+ },
12363
12520
  {
12364
12521
  integrations: ["langchain", "langgraph"],
12365
12522
  configs: langchainConfigs
@@ -12446,7 +12603,7 @@ var ModulePatch = class {
12446
12603
  /**
12447
12604
  * Patches the Node.js module class method that is responsible for compiling code.
12448
12605
  * If a module is found that has an instrumentator, it will transform the code before compiling it
12449
- * with tracing channel methods.
12606
+ * with global hook calls.
12450
12607
  */
12451
12608
  patch() {
12452
12609
  const self = this;
@@ -12504,103 +12661,11 @@ function resolveModulePrototype() {
12504
12661
  return NodeModule.prototype;
12505
12662
  }
12506
12663
 
12507
- // src/auto-instrumentations/patch-tracing-channel.ts
12508
- function patchTracingChannel(tracingChannelFn) {
12509
- const dummyChannel = tracingChannelFn("__braintrust_probe__");
12510
- const TracingChannel = dummyChannel?.constructor;
12511
- if (!TracingChannel?.prototype) {
12512
- return;
12513
- }
12514
- if (!Object.getOwnPropertyDescriptor(TracingChannel.prototype, "hasSubscribers")) {
12515
- Object.defineProperty(TracingChannel.prototype, "hasSubscribers", {
12516
- configurable: true,
12517
- enumerable: false,
12518
- get() {
12519
- return Boolean(
12520
- this.start?.hasSubscribers || this.end?.hasSubscribers || this.asyncStart?.hasSubscribers || this.asyncEnd?.hasSubscribers || this.error?.hasSubscribers
12521
- );
12522
- }
12523
- });
12524
- }
12525
- if (TracingChannel.prototype.tracePromise) {
12526
- TracingChannel.prototype.tracePromise = function(fn, context = {}, thisArg, ...args) {
12527
- const start = this.start;
12528
- const end = this.end;
12529
- const asyncStart = this.asyncStart;
12530
- const asyncEnd = this.asyncEnd;
12531
- const error = this.error;
12532
- function publishRejected(err) {
12533
- context.error = err;
12534
- error?.publish(context);
12535
- asyncStart?.publish(context);
12536
- asyncEnd?.publish(context);
12537
- }
12538
- function publishResolved(result) {
12539
- context.result = result;
12540
- asyncStart?.publish(context);
12541
- asyncEnd?.publish(context);
12542
- }
12543
- return start.runStores(context, () => {
12544
- try {
12545
- const result = Reflect.apply(fn, thisArg, args);
12546
- end?.publish(context);
12547
- if (result && (typeof result === "object" || typeof result === "function") && typeof result.then === "function") {
12548
- if (result.constructor === Promise) {
12549
- return result.then(
12550
- (res) => {
12551
- publishResolved(res);
12552
- return res;
12553
- },
12554
- (err) => {
12555
- publishRejected(err);
12556
- return Promise.reject(err);
12557
- }
12558
- );
12559
- }
12560
- void result.then(
12561
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12562
- (resolved) => {
12563
- try {
12564
- publishResolved(resolved);
12565
- } catch {
12566
- }
12567
- },
12568
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12569
- (err) => {
12570
- try {
12571
- publishRejected(err);
12572
- } catch {
12573
- }
12574
- }
12575
- );
12576
- return result;
12577
- }
12578
- context.result = result;
12579
- asyncStart?.publish(context);
12580
- asyncEnd?.publish(context);
12581
- return result;
12582
- } catch (err) {
12583
- context.error = err;
12584
- error?.publish(context);
12585
- end?.publish(context);
12586
- throw err;
12587
- }
12588
- });
12589
- };
12590
- }
12591
- }
12592
-
12593
12664
  // src/auto-instrumentations/hook.mts
12594
- var state = globalThis[/* @__PURE__ */ Symbol.for("braintrust.applyAutoInstrumentation")] ??= {};
12665
+ var state = globalThis[/* @__PURE__ */ Symbol.for(
12666
+ `braintrust.applyAutoInstrumentation.global-hooks.v${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION}`
12667
+ )] ??= {};
12595
12668
  var alreadyApplied = state.applied;
12596
- if (!alreadyApplied) {
12597
- const dcPath = ["node", "diagnostics_channel"].join(":");
12598
- const dc = await import(
12599
- /* @vite-ignore */
12600
- dcPath
12601
- );
12602
- patchTracingChannel(dc.tracingChannel);
12603
- }
12604
12669
  if (!alreadyApplied) {
12605
12670
  const allConfigs = getDefaultAutoInstrumentationConfigs();
12606
12671
  const disabled = readDisabledInstrumentationEnvConfig(