bitfab 0.36.3 → 0.36.5

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.
package/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ var __version__;
51
51
  var init_version_generated = __esm({
52
52
  "src/version.generated.ts"() {
53
53
  "use strict";
54
- __version__ = "0.36.3";
54
+ __version__ = "0.36.5";
55
55
  }
56
56
  });
57
57
 
@@ -5777,7 +5777,7 @@ var Bitfab = class {
5777
5777
  }
5778
5778
  };
5779
5779
  executeWithContext = () => {
5780
- const result = fn(...args);
5780
+ const result = fn.apply(this, args);
5781
5781
  if (result instanceof Promise) {
5782
5782
  return result.then((resolvedResult) => {
5783
5783
  recordSpan(resolvedResult);
@@ -5807,7 +5807,7 @@ var Bitfab = class {
5807
5807
  `withSpan-setup:${traceFunctionKey}`,
5808
5808
  `tracing setup failed for "${traceFunctionKey}"; running it untraced. The function still runs and returns normally; no span is recorded.`
5809
5809
  );
5810
- return fn(...args);
5810
+ return fn.apply(this, args);
5811
5811
  }
5812
5812
  return runWithSpanStack(newStack, executeWithContext);
5813
5813
  };
@@ -5816,6 +5816,40 @@ var Bitfab = class {
5816
5816
  });
5817
5817
  return wrappedFn;
5818
5818
  }
5819
+ /**
5820
+ * Create a standard ECMAScript method decorator that records each invocation
5821
+ * as a span.
5822
+ *
5823
+ * It supports instance, static, and private methods; use
5824
+ * {@link Bitfab.withSpan} for standalone functions, class fields, and
5825
+ * accessors.
5826
+ *
5827
+ * @example
5828
+ * ```typescript
5829
+ * const bitfab = new Bitfab({ apiKey: process.env.BITFAB_API_KEY });
5830
+ *
5831
+ * class OrderService {
5832
+ * @bitfab.span("order-processing", { type: "agent" })
5833
+ * async process(orderId: string) {
5834
+ * return { orderId };
5835
+ * }
5836
+ * }
5837
+ * ```
5838
+ *
5839
+ * @param traceFunctionKey - A string identifier for grouping spans
5840
+ * @param options - Span configuration applied to the decorated method
5841
+ * @returns A standard ECMAScript method decorator
5842
+ */
5843
+ span(traceFunctionKey, options = {}) {
5844
+ return (originalMethod, context) => {
5845
+ if (context.kind !== "method") {
5846
+ throw new BitfabError(
5847
+ `Bitfab span decorators can only decorate methods; ${String(context.name)} is a ${context.kind}`
5848
+ );
5849
+ }
5850
+ return this.withSpan(traceFunctionKey, options, originalMethod);
5851
+ };
5852
+ }
5819
5853
  /**
5820
5854
  * Get a detached handle to a previously-created trace, looked up by the
5821
5855
  * canonical Bitfab trace ID.
@@ -6092,6 +6126,27 @@ var BitfabFunction = class {
6092
6126
  const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
6093
6127
  return this.client.withSpan(this.traceFunctionKey, options, fn);
6094
6128
  }
6129
+ /**
6130
+ * Create a standard ECMAScript method decorator bound to this function key.
6131
+ *
6132
+ * @example
6133
+ * ```typescript
6134
+ * const orders = client.getFunction("order-processing");
6135
+ *
6136
+ * class OrderService {
6137
+ * @orders.span({ type: "agent" })
6138
+ * async process(orderId: string) {
6139
+ * return { orderId };
6140
+ * }
6141
+ * }
6142
+ * ```
6143
+ *
6144
+ * @param options - Span configuration applied to the decorated method
6145
+ * @returns A standard ECMAScript method decorator
6146
+ */
6147
+ span(options = {}) {
6148
+ return this.client.span(this.traceFunctionKey, options);
6149
+ }
6095
6150
  /**
6096
6151
  * Get a Vercel AI SDK language-model middleware bound to this function's key.
6097
6152
  *