@mastra/otel-exporter 0.0.0-suspendRuntimeContextTypeFix-20250930142630 → 0.0.0-top-level-fix-20251211111608

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # OtelExporter - OpenTelemetry AI Tracing Exporter
1
+ # OtelExporter - OpenTelemetry Tracing Exporter
2
2
 
3
- Export Mastra AI traces to any OpenTelemetry-compatible observability platform.
3
+ 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
 
@@ -19,7 +19,7 @@ npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-grpc @grpc/
19
19
 
20
20
  ```typescript
21
21
  import { OtelExporter } from '@mastra/otel-exporter';
22
- import { Mastra } from '@mastra/core';
22
+ import { Mastra } from '@mastra/core/mastra';
23
23
 
24
24
  const mastra = new Mastra({
25
25
  ...,
@@ -58,7 +58,7 @@ npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-proto
58
58
 
59
59
  ```typescript
60
60
  import { OtelExporter } from '@mastra/otel-exporter';
61
- import { Mastra } from '@mastra/core';
61
+ import { Mastra } from '@mastra/core/mastra';
62
62
 
63
63
  const mastra = new Mastra({
64
64
  ...,
@@ -95,7 +95,7 @@ npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-proto
95
95
 
96
96
  ```typescript
97
97
  import { OtelExporter } from '@mastra/otel-exporter';
98
- import { Mastra } from '@mastra/core';
98
+ import { Mastra } from '@mastra/core/mastra';
99
99
 
100
100
  const mastra = new Mastra({
101
101
  ...,
@@ -132,7 +132,7 @@ npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-http
132
132
 
133
133
  ```typescript
134
134
  import { OtelExporter } from '@mastra/otel-exporter';
135
- import { Mastra } from '@mastra/core';
135
+ import { Mastra } from '@mastra/core/mastra';
136
136
 
137
137
  const mastra = new Mastra({
138
138
  ...,
@@ -169,7 +169,7 @@ npm install @mastra/otel-exporter @opentelemetry/exporter-trace-otlp-proto
169
169
 
170
170
  ```typescript
171
171
  import { OtelExporter } from '@mastra/otel-exporter';
172
- import { Mastra } from '@mastra/core';
172
+ import { Mastra } from '@mastra/core/mastra';
173
173
 
174
174
  const mastra = new Mastra({
175
175
  ...,
@@ -208,7 +208,7 @@ npm install @mastra/otel-exporter @opentelemetry/exporter-zipkin
208
208
 
209
209
  ```typescript
210
210
  import { OtelExporter } from '@mastra/otel-exporter';
211
- import { Mastra } from '@mastra/core';
211
+ import { Mastra } from '@mastra/core/mastra';
212
212
 
213
213
  const mastra = new Mastra({
214
214
  ...,
@@ -258,7 +258,7 @@ Most providers recommend HTTP/Protobuf for production use.
258
258
 
259
259
  ```typescript
260
260
  import { OtelExporter } from '@mastra/otel-exporter';
261
- import { Mastra } from '@mastra/core';
261
+ import { Mastra } from '@mastra/core/mastra';
262
262
 
263
263
  const mastra = new Mastra({
264
264
  ...,
@@ -359,17 +359,17 @@ Spans are named following OTEL conventions:
359
359
 
360
360
  - **LLM Operations**: `chat {model}` or `tool_selection {model}`
361
361
  - **Tool Execution**: `tool.execute {tool_name}`
362
- - **Agent Runs**: `agent.{agent_id}`
362
+ - **Agent Runs**: `invoke_agent {agent_name}`
363
363
  - **Workflow Runs**: `workflow.{workflow_id}`
364
364
 
365
365
  ### Attributes
366
366
 
367
- The exporter maps Mastra's AI tracing data to OTEL-compliant attributes:
367
+ The exporter maps Mastra's tracing data to OTEL-compliant attributes:
368
368
 
369
369
  #### Core Attributes
370
370
 
371
371
  - `gen_ai.operation.name` - Operation type (chat, tool.execute, agent.run, workflow.run)
372
- - `gen_ai.system` - AI provider (openai, anthropic, etc.)
372
+ - `gen_ai.provider.name` - AI provider (openai, anthropic, etc.)
373
373
  - `gen_ai.request.model` - Model identifier
374
374
 
375
375
  #### LLM-Specific Attributes
@@ -382,8 +382,12 @@ The exporter maps Mastra's AI tracing data to OTEL-compliant attributes:
382
382
  - `gen_ai.request.top_p` - Top-p sampling parameter
383
383
  - `gen_ai.request.top_k` - Top-k sampling parameter
384
384
  - `gen_ai.response.finish_reasons` - Reason for completion
385
- - `gen_ai.prompt` - Input prompt (for LLM spans)
386
- - `gen_ai.completion` - Model output (for LLM spans)
385
+ - `gen_ai.response.model` - Actual model used in response (may differ from request)
386
+ - `gen_ai.response.id` - Unique response identifier
387
+ - `gen_ai.prompt` - Input prompt (for Model spans)
388
+ - `gen_ai.completion` - Model output (for Model spans)
389
+ - `server.address` - Server address for the model endpoint
390
+ - `server.port` - Server port for the model endpoint
387
391
 
388
392
  #### Tool Attributes
389
393
 
@@ -395,7 +399,10 @@ The exporter maps Mastra's AI tracing data to OTEL-compliant attributes:
395
399
 
396
400
  #### Agent & Workflow Attributes
397
401
 
398
- - `agent.id` - Agent identifier
402
+ - `gen_ai.agent.id` - Agent identifier
403
+ - `gen_ai.agent.name` - Human-readable agent name
404
+ - `gen_ai.conversation.id` - Conversation/thread/session identifier
405
+ - `agent.id` - Agent identifier (also included for compatibility)
399
406
  - `agent.max_steps` - Maximum agent steps
400
407
  - `workflow.id` - Workflow identifier
401
408
  - `workflow.status` - Workflow execution status
@@ -407,6 +414,43 @@ The exporter maps Mastra's AI tracing data to OTEL-compliant attributes:
407
414
  - `error.message` - Error description
408
415
  - `error.domain` - Error domain/category
409
416
 
417
+ ### Opt-In Content Attributes
418
+
419
+ For enhanced observability, you can enable additional content attributes that capture detailed message data. These attributes may contain sensitive information and should only be enabled with proper consent and security considerations.
420
+
421
+ To enable content attributes:
422
+
423
+ ```typescript
424
+ new OtelExporter({
425
+ provider: {
426
+ /* your provider config */
427
+ },
428
+ genAiConventions: {
429
+ includeContentAttributes: true, // Default: false
430
+ },
431
+ });
432
+ ```
433
+
434
+ When enabled, the following additional attributes are captured:
435
+
436
+ #### Model Content Attributes
437
+
438
+ - `gen_ai.input.messages` - Structured input messages in OpenTelemetry format
439
+ - `gen_ai.output.messages` - Structured output messages in OpenTelemetry format
440
+
441
+ These attributes convert Mastra's message format to the OpenTelemetry GenAI standard message schema, providing detailed conversation history and tool interactions.
442
+
443
+ #### Agent Content Attributes
444
+
445
+ - `gen_ai.system_instructions` - Agent system instructions/prompts
446
+
447
+ **Privacy Considerations:**
448
+
449
+ - These attributes may contain user data, prompts, and model responses
450
+ - Only enable in environments where data privacy and compliance requirements are met
451
+ - Consider using span processors to filter sensitive data before export
452
+ - Review your organization's data retention and privacy policies before enabling
453
+
410
454
  ## Troubleshooting
411
455
 
412
456
  ### Missing Dependency Error
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Utilities for converting Mastra messages to OpenTelemetry gen_ai message format
3
+ * Based on OpenTelemetry GenAI semantic conventions
4
+ * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-input-messages
5
+ * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-input-messages.json
6
+ */
7
+ /**
8
+ * Convert an Input/Output string from a MastraSpan into a jsonified string that adheres to
9
+ * OpenTelemetry gen_ai.input.messages and gen_ai.output.messages schema.
10
+ * If parsing fails at any step, the original inputOutputString is returned unmodified.
11
+ *
12
+ * This conversion is best effort; It assumes a consistent shape for mastra messages, and converts
13
+ * into the gen_ai input and output schemas as of October 20th, 2025.
14
+ *
15
+ * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-input-messages
16
+ * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-input-messages.json
17
+ * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-output-messages
18
+ * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-output-messages.json
19
+ *
20
+ * @param inputOutputString a jsonified string that contains messages adhering to what appears to be
21
+ * Mastra's message shape.
22
+ * @returns a jsonified string that contains messages adhering to the OpenTelemetry gen_ai.input.messages and gen_ai.output.messages schema.
23
+ * If parsing fails at any step, the original inputOutputString is returned unmodified.
24
+ */
25
+ export declare const convertMastraMessagesToGenAIMessages: (inputOutputString: string) => string;
26
+ //# sourceMappingURL=gen-ai-messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gen-ai-messages.d.ts","sourceRoot":"","sources":["../src/gen-ai-messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oCAAoC,GAAI,mBAAmB,MAAM,KAAG,MAyEhF,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Utilities for converting Mastra Spans to OTel Spans
3
+ * with Semantic conventions for generative AI systems
4
+ * @see https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/gen-ai/README.md
5
+ * @see https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/gen-ai/gen-ai-events.md
6
+ * @see https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/gen-ai/gen-ai-spans.md
7
+ * @see https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/gen-ai/gen-ai-agent-spans.md
8
+ * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/non-normative/examples-llm-calls/
9
+ * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/
10
+ */
11
+ import type { AnyExportedSpan, UsageStats } from '@mastra/core/observability';
12
+ import type { Attributes } from '@opentelemetry/api';
13
+ import { ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS } from '@opentelemetry/semantic-conventions/incubating';
14
+ /**
15
+ * Token usage attributes following OTel GenAI semantic conventions.
16
+ * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/
17
+ */
18
+ export interface OtelUsageMetrics {
19
+ [ATTR_GEN_AI_USAGE_INPUT_TOKENS]?: number;
20
+ [ATTR_GEN_AI_USAGE_OUTPUT_TOKENS]?: number;
21
+ 'gen_ai.usage.reasoning_tokens'?: number;
22
+ 'gen_ai.usage.cached_input_tokens'?: number;
23
+ 'gen_ai.usage.cache_write_tokens'?: number;
24
+ 'gen_ai.usage.audio_input_tokens'?: number;
25
+ 'gen_ai.usage.audio_output_tokens'?: number;
26
+ }
27
+ /**
28
+ * Formats UsageStats to OTel GenAI semantic convention attributes.
29
+ */
30
+ export declare function formatUsageMetrics(usage?: UsageStats): OtelUsageMetrics;
31
+ /**
32
+ * Get an OTEL-compliant span name based on span type and attributes
33
+ */
34
+ export declare function getSpanName(span: AnyExportedSpan): string;
35
+ /**
36
+ * Gets OpenTelemetry attributes from Mastra Span
37
+ * Following OTEL Semantic Conventions for GenAI
38
+ */
39
+ export declare function getAttributes(span: AnyExportedSpan): Attributes;
40
+ //# sourceMappingURL=gen-ai-semantics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gen-ai-semantics.d.ts","sourceRoot":"","sources":["../src/gen-ai-semantics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAEV,eAAe,EAIf,UAAU,EAEX,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAgBL,8BAA8B,EAC9B,+BAA+B,EAYhC,MAAM,gDAAgD,CAAC;AAGxD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,CAAC,8BAA8B,CAAC,CAAC,EAAE,MAAM,CAAC;IAC1C,CAAC,+BAA+B,CAAC,CAAC,EAAE,MAAM,CAAC;IAC3C,+BAA+B,CAAC,EAAE,MAAM,CAAC;IACzC,kCAAkC,CAAC,EAAE,MAAM,CAAC;IAC5C,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C,kCAAkC,CAAC,EAAE,MAAM,CAAC;CAC7C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,gBAAgB,CAqCvE;AAuDD;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAUzD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,UAAU,CA8K/D"}