@mastra/otel-exporter 1.0.0-beta.11 → 1.0.0-beta.12

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,41 @@
1
1
  # @mastra/otel-exporter
2
2
 
3
+ ## 1.0.0-beta.12
4
+
5
+ ### Minor Changes
6
+
7
+ - feat(observability): add zero-config environment variable support for all exporters ([#11686](https://github.com/mastra-ai/mastra/pull/11686))
8
+
9
+ All observability exporters now support zero-config setup via environment variables. Set the appropriate environment variables and instantiate exporters with no configuration:
10
+ - **Langfuse**: `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_BASE_URL`
11
+ - **Braintrust**: `BRAINTRUST_API_KEY`, `BRAINTRUST_ENDPOINT`
12
+ - **PostHog**: `POSTHOG_API_KEY`, `POSTHOG_HOST`
13
+ - **Arize/Phoenix**: `ARIZE_SPACE_ID`, `ARIZE_API_KEY`, `ARIZE_PROJECT_NAME`, `PHOENIX_ENDPOINT`, `PHOENIX_API_KEY`, `PHOENIX_PROJECT_NAME`
14
+ - **OTEL Providers**:
15
+ - Dash0: `DASH0_API_KEY`, `DASH0_ENDPOINT`, `DASH0_DATASET`
16
+ - SigNoz: `SIGNOZ_API_KEY`, `SIGNOZ_REGION`, `SIGNOZ_ENDPOINT`
17
+ - New Relic: `NEW_RELIC_LICENSE_KEY`, `NEW_RELIC_ENDPOINT`
18
+ - Traceloop: `TRACELOOP_API_KEY`, `TRACELOOP_DESTINATION_ID`, `TRACELOOP_ENDPOINT`
19
+ - Laminar: `LMNR_PROJECT_API_KEY`, `LAMINAR_ENDPOINT`, `LAMINAR_TEAM_ID`
20
+
21
+ Example usage:
22
+
23
+ ```typescript
24
+ // Zero-config - reads from environment variables
25
+ new LangfuseExporter();
26
+ new BraintrustExporter();
27
+ new PosthogExporter();
28
+ new ArizeExporter();
29
+ new OtelExporter({ provider: { signoz: {} } });
30
+ ```
31
+
32
+ Explicit configuration still works and takes precedence over environment variables.
33
+
34
+ ### Patch Changes
35
+
36
+ - 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)]:
37
+ - @mastra/core@1.0.0-beta.21
38
+
3
39
  ## 1.0.0-beta.11
4
40
 
5
41
  ### Patch Changes
package/README.md CHANGED
@@ -4,6 +4,18 @@ Export Mastra traces to any OpenTelemetry-compatible observability platform.
4
4
 
5
5
  > **⚠️ Important:** This package requires you to install an additional exporter package based on your provider. Each provider section below includes the specific installation command.
6
6
 
7
+ ## Environment Variables
8
+
9
+ All providers support zero-config setup via environment variables. Set the appropriate variables and the exporter will automatically use them:
10
+
11
+ | Provider | Environment Variables |
12
+ | --------- | ------------------------------------------------------------------------------------------- |
13
+ | Dash0 | `DASH0_API_KEY` (required), `DASH0_ENDPOINT` (required), `DASH0_DATASET` (optional) |
14
+ | SigNoz | `SIGNOZ_API_KEY` (required), `SIGNOZ_REGION` (optional), `SIGNOZ_ENDPOINT` (optional) |
15
+ | New Relic | `NEW_RELIC_LICENSE_KEY` (required), `NEW_RELIC_ENDPOINT` (optional) |
16
+ | Traceloop | `TRACELOOP_API_KEY` (required), `TRACELOOP_DESTINATION_ID`, `TRACELOOP_ENDPOINT` (optional) |
17
+ | Laminar | `LMNR_PROJECT_API_KEY` (required), `LAMINAR_ENDPOINT`, `LAMINAR_TEAM_ID` (optional) |
18
+
7
19
  ## Supported Providers
8
20
 
9
21
  ### Dash0
@@ -15,7 +27,16 @@ Export Mastra traces to any OpenTelemetry-compatible observability platform.
15
27
  npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-grpc @grpc/grpc-js
16
28
  ```
17
29
 
18
- #### Configuration
30
+ #### Zero-Config Setup
31
+
32
+ ```bash
33
+ # Required
34
+ DASH0_API_KEY=your-api-key
35
+ DASH0_ENDPOINT=ingress.us-west-2.aws.dash0.com:4317
36
+
37
+ # Optional
38
+ DASH0_DATASET=production
39
+ ```
19
40
 
20
41
  ```typescript
21
42
  import { OtelExporter } from '@mastra/otel-exporter';
@@ -26,24 +47,28 @@ const mastra = new Mastra({
26
47
  observability: {
27
48
  configs: {
28
49
  otel: {
29
- serviceName: 'mastra-service',
30
- exporters: [
31
- new OtelExporter({
32
- provider: {
33
- dash0: {
34
- apiKey: process.env.DASH0_API_KEY, // Required at runtime
35
- endpoint: 'ingress.us-west-2.aws.dash0.com:4317', // Required at runtime
36
- dataset: 'production', // Optional: dataset name
37
- }
38
- },
39
- })
40
- ],
50
+ serviceName: 'my-service',
51
+ exporters: [new OtelExporter({ provider: { dash0: {} } })],
41
52
  },
42
53
  },
43
54
  },
44
55
  });
45
56
  ```
46
57
 
58
+ #### Explicit Configuration
59
+
60
+ ```typescript
61
+ new OtelExporter({
62
+ provider: {
63
+ dash0: {
64
+ apiKey: 'your-api-key',
65
+ endpoint: 'ingress.us-west-2.aws.dash0.com:4317',
66
+ dataset: 'production', // Optional
67
+ },
68
+ },
69
+ });
70
+ ```
71
+
47
72
  **Note:** Get your endpoint from your Dash0 dashboard. It should be in the format `ingress.{region}.aws.dash0.com:4317`.
48
73
 
49
74
  ### SigNoz
@@ -54,7 +79,16 @@ const mastra = new Mastra({
54
79
  npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-proto
55
80
  ```
56
81
 
57
- #### Configuration
82
+ #### Zero-Config Setup
83
+
84
+ ```bash
85
+ # Required
86
+ SIGNOZ_API_KEY=your-api-key
87
+
88
+ # Optional
89
+ SIGNOZ_REGION=us # 'us' | 'eu' | 'in'
90
+ SIGNOZ_ENDPOINT=https://my-signoz.example.com # For self-hosted
91
+ ```
58
92
 
59
93
  ```typescript
60
94
  import { OtelExporter } from '@mastra/otel-exporter';
@@ -65,24 +99,28 @@ const mastra = new Mastra({
65
99
  observability: {
66
100
  configs: {
67
101
  otel: {
68
- serviceName: 'mastra-service',
69
- exporters: [
70
- new OtelExporter({
71
- provider: {
72
- signoz: {
73
- apiKey: process.env.SIGNOZ_API_KEY, // Required at runtime
74
- region: 'us', // Optional: 'us' | 'eu' | 'in', defaults to 'us'
75
- // endpoint: 'https://my-signoz.example.com', // Optional: for self-hosted
76
- }
77
- },
78
- })
79
- ],
102
+ serviceName: 'my-service',
103
+ exporters: [new OtelExporter({ provider: { signoz: {} } })],
80
104
  },
81
105
  },
82
106
  },
83
107
  });
84
108
  ```
85
109
 
110
+ #### Explicit Configuration
111
+
112
+ ```typescript
113
+ new OtelExporter({
114
+ provider: {
115
+ signoz: {
116
+ apiKey: 'your-api-key',
117
+ region: 'us', // Optional: 'us' | 'eu' | 'in'
118
+ endpoint: 'https://my-signoz.example.com', // Optional: for self-hosted
119
+ },
120
+ },
121
+ });
122
+ ```
123
+
86
124
  ### New Relic
87
125
 
88
126
  #### Installation
@@ -91,7 +129,15 @@ const mastra = new Mastra({
91
129
  npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-proto
92
130
  ```
93
131
 
94
- #### Configuration
132
+ #### Zero-Config Setup
133
+
134
+ ```bash
135
+ # Required
136
+ NEW_RELIC_LICENSE_KEY=your-license-key
137
+
138
+ # Optional
139
+ NEW_RELIC_ENDPOINT=https://otlp.eu01.nr-data.net # For EU region
140
+ ```
95
141
 
96
142
  ```typescript
97
143
  import { OtelExporter } from '@mastra/otel-exporter';
@@ -102,23 +148,27 @@ const mastra = new Mastra({
102
148
  observability: {
103
149
  configs: {
104
150
  otel: {
105
- serviceName: 'mastra-service',
106
- exporters: [
107
- new OtelExporter({
108
- provider: {
109
- newrelic: {
110
- apiKey: process.env.NEW_RELIC_LICENSE_KEY, // Required at runtime
111
- // endpoint: 'https://otlp.eu01.nr-data.net', // Optional: for EU region
112
- }
113
- },
114
- })
115
- ],
151
+ serviceName: 'my-service',
152
+ exporters: [new OtelExporter({ provider: { newrelic: {} } })],
116
153
  },
117
154
  },
118
155
  },
119
156
  });
120
157
  ```
121
158
 
159
+ #### Explicit Configuration
160
+
161
+ ```typescript
162
+ new OtelExporter({
163
+ provider: {
164
+ newrelic: {
165
+ apiKey: 'your-license-key',
166
+ endpoint: 'https://otlp.eu01.nr-data.net', // Optional: for EU region
167
+ },
168
+ },
169
+ });
170
+ ```
171
+
122
172
  ### Traceloop
123
173
 
124
174
  #### Installation
@@ -128,7 +178,16 @@ const mastra = new Mastra({
128
178
  npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-http
129
179
  ```
130
180
 
131
- #### Configuration
181
+ #### Zero-Config Setup
182
+
183
+ ```bash
184
+ # Required
185
+ TRACELOOP_API_KEY=your-api-key
186
+
187
+ # Optional
188
+ TRACELOOP_DESTINATION_ID=my-destination
189
+ TRACELOOP_ENDPOINT=https://custom.traceloop.com
190
+ ```
132
191
 
133
192
  ```typescript
134
193
  import { OtelExporter } from '@mastra/otel-exporter';
@@ -139,24 +198,28 @@ const mastra = new Mastra({
139
198
  observability: {
140
199
  configs: {
141
200
  otel: {
142
- serviceName: 'mastra-service',
143
- exporters: [
144
- new OtelExporter({
145
- provider: {
146
- traceloop: {
147
- apiKey: process.env.TRACELOOP_API_KEY, // Required at runtime
148
- destinationId: 'my-destination', // Optional
149
- // endpoint: 'https://custom.traceloop.com', // Optional
150
- }
151
- },
152
- })
153
- ],
201
+ serviceName: 'my-service',
202
+ exporters: [new OtelExporter({ provider: { traceloop: {} } })],
154
203
  },
155
204
  },
156
205
  },
157
206
  });
158
207
  ```
159
208
 
209
+ #### Explicit Configuration
210
+
211
+ ```typescript
212
+ new OtelExporter({
213
+ provider: {
214
+ traceloop: {
215
+ apiKey: 'your-api-key',
216
+ destinationId: 'my-destination', // Optional
217
+ endpoint: 'https://custom.traceloop.com', // Optional
218
+ },
219
+ },
220
+ });
221
+ ```
222
+
160
223
  ### Laminar
161
224
 
162
225
  #### Installation
@@ -165,7 +228,16 @@ const mastra = new Mastra({
165
228
  npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-proto
166
229
  ```
167
230
 
168
- #### Configuration
231
+ #### Zero-Config Setup
232
+
233
+ ```bash
234
+ # Required
235
+ LMNR_PROJECT_API_KEY=your-api-key
236
+
237
+ # Optional
238
+ LAMINAR_ENDPOINT=https://api.lmnr.ai/v1/traces
239
+ LAMINAR_TEAM_ID=your-team-id # For backwards compatibility
240
+ ```
169
241
 
170
242
  ```typescript
171
243
  import { OtelExporter } from '@mastra/otel-exporter';
@@ -176,24 +248,28 @@ const mastra = new Mastra({
176
248
  observability: {
177
249
  configs: {
178
250
  otel: {
179
- serviceName: 'mastra-service',
180
- exporters: [
181
- new OtelExporter({
182
- provider: {
183
- laminar: {
184
- apiKey: process.env.LMNR_PROJECT_API_KEY, // Required at runtime
185
- // teamId: process.env.LAMINAR_TEAM_ID, // Optional, for backwards compatibility
186
- // endpoint: 'https://api.lmnr.ai/v1/traces', // Optional
187
- }
188
- },
189
- })
190
- ],
251
+ serviceName: 'my-service',
252
+ exporters: [new OtelExporter({ provider: { laminar: {} } })],
191
253
  },
192
254
  },
193
255
  },
194
256
  });
195
257
  ```
196
258
 
259
+ #### Explicit Configuration
260
+
261
+ ```typescript
262
+ new OtelExporter({
263
+ provider: {
264
+ laminar: {
265
+ apiKey: 'your-api-key',
266
+ teamId: 'your-team-id', // Optional, for backwards compatibility
267
+ endpoint: 'https://api.lmnr.ai/v1/traces', // Optional
268
+ },
269
+ },
270
+ });
271
+ ```
272
+
197
273
  **Note:** Laminar now only requires the `LMNR_PROJECT_API_KEY`. The `teamId` is optional.
198
274
 
199
275
  ### Zipkin
@@ -340,7 +416,7 @@ The OtelExporter uses OpenTelemetry's `BatchSpanProcessor` for efficient span ex
340
416
  - **Default batch size**: 512 spans (configurable via `batchSize`)
341
417
  - **Export interval**: Every 5 seconds or when batch is full
342
418
  - **Queue size**: Up to 2048 spans queued in memory
343
- - **Production-ready**: Optimized for high-throughput applications
419
+ - **High-throughput support**: Handles large volumes of spans efficiently
344
420
 
345
421
  This approach ensures:
346
422
 
package/dist/index.cjs CHANGED
@@ -106,24 +106,31 @@ function resolveProviderConfig(config) {
106
106
  }
107
107
  }
108
108
  function resolveDash0Config(config) {
109
- if (!config.apiKey) {
110
- console.error("[OtelExporter] Dash0 configuration requires apiKey. Tracing will be disabled.");
109
+ const apiKey = config.apiKey ?? process.env.DASH0_API_KEY;
110
+ const configEndpoint = config.endpoint ?? process.env.DASH0_ENDPOINT;
111
+ const dataset = config.dataset ?? process.env.DASH0_DATASET;
112
+ if (!apiKey) {
113
+ console.error(
114
+ "[OtelExporter] Dash0 configuration requires apiKey. Set DASH0_API_KEY environment variable or pass it in config. Tracing will be disabled."
115
+ );
111
116
  return null;
112
117
  }
113
- if (!config.endpoint) {
114
- console.error("[OtelExporter] Dash0 configuration requires endpoint. Tracing will be disabled.");
118
+ if (!configEndpoint) {
119
+ console.error(
120
+ "[OtelExporter] Dash0 configuration requires endpoint. Set DASH0_ENDPOINT environment variable or pass it in config. Tracing will be disabled."
121
+ );
115
122
  return null;
116
123
  }
117
- let endpoint = config.endpoint;
124
+ let endpoint = configEndpoint;
118
125
  if (!endpoint.includes("/v1/traces")) {
119
126
  endpoint = `${endpoint}/v1/traces`;
120
127
  }
121
128
  const headers = {
122
- authorization: `Bearer ${config.apiKey}`
129
+ authorization: `Bearer ${apiKey}`
123
130
  // lowercase for gRPC metadata
124
131
  };
125
- if (config.dataset) {
126
- headers["dash0-dataset"] = config.dataset;
132
+ if (dataset) {
133
+ headers["dash0-dataset"] = dataset;
127
134
  }
128
135
  return {
129
136
  endpoint,
@@ -133,44 +140,58 @@ function resolveDash0Config(config) {
133
140
  };
134
141
  }
135
142
  function resolveSignozConfig(config) {
136
- if (!config.apiKey) {
137
- console.error("[OtelExporter] SigNoz configuration requires apiKey. Tracing will be disabled.");
143
+ const apiKey = config.apiKey ?? process.env.SIGNOZ_API_KEY;
144
+ const region = config.region ?? process.env.SIGNOZ_REGION;
145
+ const configEndpoint = config.endpoint ?? process.env.SIGNOZ_ENDPOINT;
146
+ if (!apiKey) {
147
+ console.error(
148
+ "[OtelExporter] SigNoz configuration requires apiKey. Set SIGNOZ_API_KEY environment variable or pass it in config. Tracing will be disabled."
149
+ );
138
150
  return null;
139
151
  }
140
- const endpoint = config.endpoint || `https://ingest.${config.region || "us"}.signoz.cloud:443/v1/traces`;
152
+ const endpoint = configEndpoint || `https://ingest.${region || "us"}.signoz.cloud:443/v1/traces`;
141
153
  return {
142
154
  endpoint,
143
155
  headers: {
144
- "signoz-ingestion-key": config.apiKey
156
+ "signoz-ingestion-key": apiKey
145
157
  },
146
158
  protocol: "http/protobuf"
147
159
  };
148
160
  }
149
161
  function resolveNewRelicConfig(config) {
150
- if (!config.apiKey) {
151
- console.error("[OtelExporter] New Relic configuration requires apiKey (license key). Tracing will be disabled.");
162
+ const apiKey = config.apiKey ?? process.env.NEW_RELIC_LICENSE_KEY;
163
+ const configEndpoint = config.endpoint ?? process.env.NEW_RELIC_ENDPOINT;
164
+ if (!apiKey) {
165
+ console.error(
166
+ "[OtelExporter] New Relic configuration requires apiKey (license key). Set NEW_RELIC_LICENSE_KEY environment variable or pass it in config. Tracing will be disabled."
167
+ );
152
168
  return null;
153
169
  }
154
- const endpoint = config.endpoint || "https://otlp.nr-data.net:443/v1/traces";
170
+ const endpoint = configEndpoint || "https://otlp.nr-data.net:443/v1/traces";
155
171
  return {
156
172
  endpoint,
157
173
  headers: {
158
- "api-key": config.apiKey
174
+ "api-key": apiKey
159
175
  },
160
176
  protocol: "http/protobuf"
161
177
  };
162
178
  }
163
179
  function resolveTraceloopConfig(config) {
164
- if (!config.apiKey) {
165
- console.error("[OtelExporter] Traceloop configuration requires apiKey. Tracing will be disabled.");
180
+ const apiKey = config.apiKey ?? process.env.TRACELOOP_API_KEY;
181
+ const destinationId = config.destinationId ?? process.env.TRACELOOP_DESTINATION_ID;
182
+ const configEndpoint = config.endpoint ?? process.env.TRACELOOP_ENDPOINT;
183
+ if (!apiKey) {
184
+ console.error(
185
+ "[OtelExporter] Traceloop configuration requires apiKey. Set TRACELOOP_API_KEY environment variable or pass it in config. Tracing will be disabled."
186
+ );
166
187
  return null;
167
188
  }
168
- const endpoint = config.endpoint || "https://api.traceloop.com/v1/traces";
189
+ const endpoint = configEndpoint || "https://api.traceloop.com/v1/traces";
169
190
  const headers = {
170
- Authorization: `Bearer ${config.apiKey}`
191
+ Authorization: `Bearer ${apiKey}`
171
192
  };
172
- if (config.destinationId) {
173
- headers["x-traceloop-destination-id"] = config.destinationId;
193
+ if (destinationId) {
194
+ headers["x-traceloop-destination-id"] = destinationId;
174
195
  }
175
196
  return {
176
197
  endpoint,
@@ -179,16 +200,21 @@ function resolveTraceloopConfig(config) {
179
200
  };
180
201
  }
181
202
  function resolveLaminarConfig(config) {
182
- if (!config.apiKey) {
183
- console.error("[OtelExporter] Laminar configuration requires apiKey. Tracing will be disabled.");
203
+ const apiKey = config.apiKey ?? process.env.LMNR_PROJECT_API_KEY;
204
+ const teamId = config.teamId ?? process.env.LAMINAR_TEAM_ID;
205
+ const configEndpoint = config.endpoint ?? process.env.LAMINAR_ENDPOINT;
206
+ if (!apiKey) {
207
+ console.error(
208
+ "[OtelExporter] Laminar configuration requires apiKey. Set LMNR_PROJECT_API_KEY environment variable or pass it in config. Tracing will be disabled."
209
+ );
184
210
  return null;
185
211
  }
186
- const endpoint = config.endpoint || "https://api.lmnr.ai/v1/traces";
212
+ const endpoint = configEndpoint || "https://api.lmnr.ai/v1/traces";
187
213
  const headers = {
188
- Authorization: `Bearer ${config.apiKey}`
214
+ Authorization: `Bearer ${apiKey}`
189
215
  };
190
- if (config.teamId) {
191
- headers["x-laminar-team-id"] = config.teamId;
216
+ if (teamId) {
217
+ headers["x-laminar-team-id"] = teamId;
192
218
  }
193
219
  return {
194
220
  endpoint,