@mastra/braintrust 1.0.0-beta.11 → 1.0.0-beta.13

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/CHANGELOG.md CHANGED
@@ -1,5 +1,75 @@
1
1
  # @mastra/braintrust
2
2
 
3
+ ## 1.0.0-beta.13
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `TrackingExporter` base class with improved handling for: ([#11870](https://github.com/mastra-ai/mastra/pull/11870))
8
+ - **Out-of-order span processing**: Spans that arrive before their parents are now queued and processed once dependencies are available
9
+ - **Delayed cleanup**: Trace data is retained briefly after spans end to handle late-arriving updates
10
+ - **Memory management**: Configurable limits on pending and total traces to prevent memory leaks
11
+
12
+ New configuration options on `TrackingExporterConfig`:
13
+ - `earlyQueueMaxAttempts` - Max retry attempts for queued events (default: 5)
14
+ - `earlyQueueTTLMs` - TTL for queued events in ms (default: 30000)
15
+ - `traceCleanupDelayMs` - Delay before cleaning up completed traces (default: 30000)
16
+ - `maxPendingCleanupTraces` - Soft cap on traces awaiting cleanup (default: 100)
17
+ - `maxTotalTraces` - Hard cap on total traces (default: 500)
18
+
19
+ Updated @mastra/braintrust, @mastra/langfuse, @mastra/langsmith, @mastra/posthog to use the new TrackingExporter
20
+
21
+ ### Patch Changes
22
+
23
+ - Fix `logFeedback()` not working because span_id differs from row id. ([#11927](https://github.com/mastra-ai/mastra/pull/11927))
24
+
25
+ **Problem**: When using `BraintrustExporter`, user feedback intended for specific agent responses appeared as separate rows in Braintrust rather than being attached to the original generation. The `startSpan()` call passed `spanId: span.id` but omitted the `event: { id: span.id }` parameter, causing Braintrust to auto-generate a different UUID for the row `id` field.
26
+
27
+ **Solution**: Add `event: { id: span.id }` to the `startSpan()` call so that the Mastra span ID is used as both the Braintrust `span_id` and row `id`. This allows `logFeedback({ id: span.id })` to correctly attach feedback to existing records.
28
+
29
+ - Fix Thread view truncation in Braintrust when LLM generations include tool calls. ([#11984](https://github.com/mastra-ai/mastra/pull/11984))
30
+
31
+ The Braintrust exporter now reconstructs LLM output in OpenAI Chat Completion format by examining child `MODEL_STEP` and `TOOL_CALL` spans. This enables Braintrust's Thread view to properly display the full conversation flow including tool calls and their results.
32
+
33
+ - Updated dependencies [[`ebae12a`](https://github.com/mastra-ai/mastra/commit/ebae12a2dd0212e75478981053b148a2c246962d), [`c61a0a5`](https://github.com/mastra-ai/mastra/commit/c61a0a5de4904c88fd8b3718bc26d1be1c2ec6e7), [`69136e7`](https://github.com/mastra-ai/mastra/commit/69136e748e32f57297728a4e0f9a75988462f1a7), [`449aed2`](https://github.com/mastra-ai/mastra/commit/449aed2ba9d507b75bf93d427646ea94f734dfd1), [`eb648a2`](https://github.com/mastra-ai/mastra/commit/eb648a2cc1728f7678768dd70cd77619b448dab9), [`0131105`](https://github.com/mastra-ai/mastra/commit/0131105532e83bdcbb73352fc7d0879eebf140dc), [`9d5059e`](https://github.com/mastra-ai/mastra/commit/9d5059eae810829935fb08e81a9bb7ecd5b144a7), [`ef756c6`](https://github.com/mastra-ai/mastra/commit/ef756c65f82d16531c43f49a27290a416611e526), [`b00ccd3`](https://github.com/mastra-ai/mastra/commit/b00ccd325ebd5d9e37e34dd0a105caae67eb568f), [`3bdfa75`](https://github.com/mastra-ai/mastra/commit/3bdfa7507a91db66f176ba8221aa28dd546e464a), [`e770de9`](https://github.com/mastra-ai/mastra/commit/e770de941a287a49b1964d44db5a5763d19890a6), [`52e2716`](https://github.com/mastra-ai/mastra/commit/52e2716b42df6eff443de72360ae83e86ec23993), [`27b4040`](https://github.com/mastra-ai/mastra/commit/27b4040bfa1a95d92546f420a02a626b1419a1d6), [`610a70b`](https://github.com/mastra-ai/mastra/commit/610a70bdad282079f0c630e0d7bb284578f20151), [`8dc7f55`](https://github.com/mastra-ai/mastra/commit/8dc7f55900395771da851dc7d78d53ae84fe34ec), [`8379099`](https://github.com/mastra-ai/mastra/commit/8379099fc467af6bef54dd7f80c9bd75bf8bbddf), [`b06be72`](https://github.com/mastra-ai/mastra/commit/b06be7223d5ef23edc98c01a67ef713c6cc039f9), [`8c0ec25`](https://github.com/mastra-ai/mastra/commit/8c0ec25646c8a7df253ed1e5ff4863a0d3f1316c), [`ff4d9a6`](https://github.com/mastra-ai/mastra/commit/ff4d9a6704fc87b31a380a76ed22736fdedbba5a), [`69821ef`](https://github.com/mastra-ai/mastra/commit/69821ef806482e2c44e2197ac0b050c3fe3a5285), [`1ed5716`](https://github.com/mastra-ai/mastra/commit/1ed5716830867b3774c4a1b43cc0d82935f32b96), [`4186bdd`](https://github.com/mastra-ai/mastra/commit/4186bdd00731305726fa06adba0b076a1d50b49f), [`7aaf973`](https://github.com/mastra-ai/mastra/commit/7aaf973f83fbbe9521f1f9e7a4fd99b8de464617)]:
34
+ - @mastra/core@1.0.0-beta.22
35
+ - @mastra/observability@1.0.0-beta.11
36
+
37
+ ## 1.0.0-beta.12
38
+
39
+ ### Minor Changes
40
+
41
+ - feat(observability): add zero-config environment variable support for all exporters ([#11686](https://github.com/mastra-ai/mastra/pull/11686))
42
+
43
+ All observability exporters now support zero-config setup via environment variables. Set the appropriate environment variables and instantiate exporters with no configuration:
44
+ - **Langfuse**: `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_BASE_URL`
45
+ - **Braintrust**: `BRAINTRUST_API_KEY`, `BRAINTRUST_ENDPOINT`
46
+ - **PostHog**: `POSTHOG_API_KEY`, `POSTHOG_HOST`
47
+ - **Arize/Phoenix**: `ARIZE_SPACE_ID`, `ARIZE_API_KEY`, `ARIZE_PROJECT_NAME`, `PHOENIX_ENDPOINT`, `PHOENIX_API_KEY`, `PHOENIX_PROJECT_NAME`
48
+ - **OTEL Providers**:
49
+ - Dash0: `DASH0_API_KEY`, `DASH0_ENDPOINT`, `DASH0_DATASET`
50
+ - SigNoz: `SIGNOZ_API_KEY`, `SIGNOZ_REGION`, `SIGNOZ_ENDPOINT`
51
+ - New Relic: `NEW_RELIC_LICENSE_KEY`, `NEW_RELIC_ENDPOINT`
52
+ - Traceloop: `TRACELOOP_API_KEY`, `TRACELOOP_DESTINATION_ID`, `TRACELOOP_ENDPOINT`
53
+ - Laminar: `LMNR_PROJECT_API_KEY`, `LAMINAR_ENDPOINT`
54
+
55
+ Example usage:
56
+
57
+ ```typescript
58
+ // Zero-config - reads from environment variables
59
+ new LangfuseExporter();
60
+ new BraintrustExporter();
61
+ new PosthogExporter();
62
+ new ArizeExporter();
63
+ new OtelExporter({ provider: { signoz: {} } });
64
+ ```
65
+
66
+ Explicit configuration still works and takes precedence over environment variables.
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies [[`08766f1`](https://github.com/mastra-ai/mastra/commit/08766f15e13ac0692fde2a8bd366c2e16e4321df), [`ae8baf7`](https://github.com/mastra-ai/mastra/commit/ae8baf7d8adcb0ff9dac11880400452bc49b33ff), [`cfabdd4`](https://github.com/mastra-ai/mastra/commit/cfabdd4aae7a726b706942d6836eeca110fb6267), [`a0e437f`](https://github.com/mastra-ai/mastra/commit/a0e437fac561b28ee719e0302d72b2f9b4c138f0), [`bec5efd`](https://github.com/mastra-ai/mastra/commit/bec5efde96653ccae6604e68c696d1bc6c1a0bf5), [`9eedf7d`](https://github.com/mastra-ai/mastra/commit/9eedf7de1d6e0022a2f4e5e9e6fe1ec468f9b43c)]:
71
+ - @mastra/core@1.0.0-beta.21
72
+
3
73
  ## 1.0.0-beta.11
4
74
 
5
75
  ### Minor Changes
package/README.md CHANGED
@@ -10,21 +10,52 @@ npm install @mastra/braintrust
10
10
 
11
11
  ## Usage
12
12
 
13
+ ### Zero-Config Setup
14
+
15
+ The exporter automatically reads credentials from environment variables:
16
+
17
+ ```bash
18
+ # Required
19
+ BRAINTRUST_API_KEY=sk-...
20
+
21
+ # Optional
22
+ BRAINTRUST_ENDPOINT=https://api.braintrust.dev
23
+ ```
24
+
25
+ ```typescript
26
+ import { BraintrustExporter } from '@mastra/braintrust';
27
+
28
+ const mastra = new Mastra({
29
+ ...,
30
+ observability: {
31
+ configs: {
32
+ braintrust: {
33
+ serviceName: 'my-service',
34
+ exporters: [new BraintrustExporter()],
35
+ },
36
+ },
37
+ },
38
+ });
39
+ ```
40
+
41
+ ### Explicit Configuration
42
+
43
+ You can also pass credentials directly:
44
+
13
45
  ```typescript
14
46
  import { BraintrustExporter } from '@mastra/braintrust';
15
47
 
16
- // Use with Mastra
17
48
  const mastra = new Mastra({
18
49
  ...,
19
50
  observability: {
20
51
  configs: {
21
52
  braintrust: {
22
- serviceName: 'service',
53
+ serviceName: 'my-service',
23
54
  exporters: [
24
55
  new BraintrustExporter({
25
- apiKey: process.env.BRAINTRUST_API_KEY,
26
- projectName: "mastra-tracing", // optional
27
- endpoint: process.env.BRAINTRUST_ENDPOINT, // optional
56
+ apiKey: 'sk-...',
57
+ projectName: 'mastra-tracing', // Optional, defaults to 'mastra-tracing'
58
+ endpoint: 'https://api.braintrust.dev', // Optional
28
59
  }),
29
60
  ],
30
61
  },
@@ -33,6 +64,16 @@ const mastra = new Mastra({
33
64
  });
34
65
  ```
35
66
 
67
+ ### Configuration Options
68
+
69
+ | Option | Type | Description |
70
+ | ------------------ | -------------------- | -------------------------------------------------------------- |
71
+ | `apiKey` | `string` | Braintrust API key. Defaults to `BRAINTRUST_API_KEY` env var |
72
+ | `endpoint` | `string` | Custom endpoint URL. Defaults to `BRAINTRUST_ENDPOINT` env var |
73
+ | `projectName` | `string` | Project name. Defaults to `'mastra-tracing'` |
74
+ | `braintrustLogger` | `Logger<true>` | Optional Braintrust logger instance for context integration |
75
+ | `tuningParameters` | `Record<string,any>` | Support tuning parameters |
76
+
36
77
  ## Features
37
78
 
38
79
  ### Tracing
@@ -42,3 +83,4 @@ const mastra = new Mastra({
42
83
  - **Error tracking**: Automatic error status and message tracking
43
84
  - **Hierarchical traces**: Maintains parent-child relationships
44
85
  - **Event span support**: Zero-duration spans for event-type traces
86
+ - **Context integration**: Attach to existing Braintrust spans from `logger.traced()` or `Eval()`
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Message format conversion utilities for Braintrust.
3
+ *
4
+ * Converts AI SDK message format (v4/v5) to OpenAI Chat Completion format,
5
+ * which Braintrust requires for proper rendering of threads.
6
+ */
7
+ /**
8
+ * Remove null and undefined values from an object (shallow)
9
+ */
10
+ export declare function removeNullish<T extends Record<string, unknown>>(obj: T): Partial<T>;
11
+ /**
12
+ * AI SDK content part types (both v4 and v5)
13
+ */
14
+ interface AISDKTextPart {
15
+ type: 'text';
16
+ text: string;
17
+ }
18
+ interface AISDKImagePart {
19
+ type: 'image';
20
+ image?: string | Uint8Array | URL;
21
+ mimeType?: string;
22
+ }
23
+ interface AISDKFilePart {
24
+ type: 'file';
25
+ data?: string | Uint8Array | URL;
26
+ filename?: string;
27
+ name?: string;
28
+ mimeType?: string;
29
+ }
30
+ interface AISDKReasoningPart {
31
+ type: 'reasoning';
32
+ text?: string;
33
+ }
34
+ interface AISDKToolCallPart {
35
+ type: 'tool-call';
36
+ toolCallId: string;
37
+ toolName: string;
38
+ args?: unknown;
39
+ input?: unknown;
40
+ }
41
+ interface AISDKToolResultPart {
42
+ type: 'tool-result';
43
+ toolCallId: string;
44
+ result?: unknown;
45
+ output?: unknown;
46
+ }
47
+ type AISDKContentPart = AISDKTextPart | AISDKImagePart | AISDKFilePart | AISDKReasoningPart | AISDKToolCallPart | AISDKToolResultPart | {
48
+ type: string;
49
+ [key: string]: unknown;
50
+ };
51
+ /**
52
+ * AI SDK message format (input format for conversion)
53
+ */
54
+ interface AISDKMessage {
55
+ role: 'user' | 'assistant' | 'system' | 'tool';
56
+ content: string | AISDKContentPart[];
57
+ [key: string]: unknown;
58
+ }
59
+ /**
60
+ * OpenAI Chat Completion tool call format
61
+ */
62
+ export interface OpenAIToolCall {
63
+ id: string;
64
+ type: 'function';
65
+ function: {
66
+ name: string;
67
+ arguments: string;
68
+ };
69
+ }
70
+ /**
71
+ * OpenAI Chat Completion message format (output format)
72
+ */
73
+ export interface OpenAIMessage {
74
+ role: 'user' | 'assistant' | 'system' | 'tool';
75
+ content: string;
76
+ tool_calls?: OpenAIToolCall[];
77
+ tool_call_id?: string;
78
+ [key: string]: unknown;
79
+ }
80
+ /**
81
+ * Converts AI SDK message format to OpenAI Chat Completion format for Braintrust.
82
+ *
83
+ * Supports both AI SDK v4 and v5 formats:
84
+ * - v4 uses 'args' for tool calls and 'result' for tool results
85
+ * - v5 uses 'input' for tool calls and 'output' for tool results
86
+ *
87
+ * AI SDK format:
88
+ * { role: "user", content: [{ type: "text", text: "hello" }] }
89
+ * { role: "assistant", content: [{ type: "text", text: "..." }, { type: "tool-call", toolCallId: "...", toolName: "...", args: {...} }] }
90
+ * { role: "tool", content: [{ type: "tool-result", toolCallId: "...", result: {...} }] }
91
+ *
92
+ * OpenAI format (what Braintrust expects):
93
+ * { role: "user", content: "hello" }
94
+ * { role: "assistant", content: "...", tool_calls: [{ id: "...", type: "function", function: { name: "...", arguments: "..." } }] }
95
+ * { role: "tool", content: "result", tool_call_id: "..." }
96
+ */
97
+ export declare function convertAISDKMessage(message: AISDKMessage | OpenAIMessage | unknown): OpenAIMessage | unknown;
98
+ export {};
99
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEnF;AAMD;;GAEG;AACH,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,GAAG,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,aAAa;IACr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