@mastra/observability 0.0.0-1.x-tester-20251106055847

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 (46) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/LICENSE.md +15 -0
  3. package/README.md +99 -0
  4. package/dist/config.d.ts +343 -0
  5. package/dist/config.d.ts.map +1 -0
  6. package/dist/default.d.ts +29 -0
  7. package/dist/default.d.ts.map +1 -0
  8. package/dist/exporters/base.d.ts +111 -0
  9. package/dist/exporters/base.d.ts.map +1 -0
  10. package/dist/exporters/cloud.d.ts +30 -0
  11. package/dist/exporters/cloud.d.ts.map +1 -0
  12. package/dist/exporters/console.d.ts +10 -0
  13. package/dist/exporters/console.d.ts.map +1 -0
  14. package/dist/exporters/default.d.ts +89 -0
  15. package/dist/exporters/default.d.ts.map +1 -0
  16. package/dist/exporters/index.d.ts +9 -0
  17. package/dist/exporters/index.d.ts.map +1 -0
  18. package/dist/index.cjs +2193 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.ts +14 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +2174 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/instances/base.d.ts +106 -0
  25. package/dist/instances/base.d.ts.map +1 -0
  26. package/dist/instances/default.d.ts +8 -0
  27. package/dist/instances/default.d.ts.map +1 -0
  28. package/dist/instances/index.d.ts +6 -0
  29. package/dist/instances/index.d.ts.map +1 -0
  30. package/dist/model-tracing.d.ts +48 -0
  31. package/dist/model-tracing.d.ts.map +1 -0
  32. package/dist/registry.d.ts +49 -0
  33. package/dist/registry.d.ts.map +1 -0
  34. package/dist/span_processors/index.d.ts +5 -0
  35. package/dist/span_processors/index.d.ts.map +1 -0
  36. package/dist/span_processors/sensitive-data-filter.d.ts +85 -0
  37. package/dist/span_processors/sensitive-data-filter.d.ts.map +1 -0
  38. package/dist/spans/base.d.ts +71 -0
  39. package/dist/spans/base.d.ts.map +1 -0
  40. package/dist/spans/default.d.ts +13 -0
  41. package/dist/spans/default.d.ts.map +1 -0
  42. package/dist/spans/index.d.ts +7 -0
  43. package/dist/spans/index.d.ts.map +1 -0
  44. package/dist/spans/no-op.d.ts +15 -0
  45. package/dist/spans/no-op.d.ts.map +1 -0
  46. package/package.json +64 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Base Exporter for Observability
3
+ *
4
+ * Provides common functionality shared by all observability exporters:
5
+ * - Logger initialization with proper Mastra logger support
6
+ * - Disabled state management
7
+ * - Graceful shutdown lifecycle
8
+ */
9
+ import { LogLevel } from '@mastra/core/logger';
10
+ import type { IMastraLogger } from '@mastra/core/logger';
11
+ import type { TracingEvent, ObservabilityExporter, InitExporterOptions } from '@mastra/core/observability';
12
+ /**
13
+ * Base configuration that all exporters should support
14
+ */
15
+ export interface BaseExporterConfig {
16
+ /** Optional Mastra logger instance */
17
+ logger?: IMastraLogger;
18
+ /** Log level for the exporter (defaults to INFO) - accepts both enum and string */
19
+ logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error';
20
+ }
21
+ /**
22
+ * Abstract base class for observability exporters
23
+ *
24
+ * Handles common concerns:
25
+ * - Logger setup with proper Mastra logger
26
+ * - Disabled state management
27
+ * - Basic lifecycle methods
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * class MyExporter extends BaseExporter {
32
+ * name = 'my-exporter';
33
+ *
34
+ * constructor(config: MyExporterConfig) {
35
+ * super(config);
36
+ *
37
+ * if (!config.apiKey) {
38
+ * this.setDisabled('Missing API key');
39
+ * return;
40
+ * }
41
+ *
42
+ * // Initialize exporter-specific logic
43
+ * }
44
+ *
45
+ * async _exportEvent(event: TracingEvent): Promise<void> {
46
+ * // Export logic
47
+ * }
48
+ * }
49
+ * ```
50
+ */
51
+ export declare abstract class BaseExporter implements ObservabilityExporter {
52
+ /** Exporter name - must be implemented by subclasses */
53
+ abstract name: string;
54
+ /** Mastra logger instance */
55
+ protected logger: IMastraLogger;
56
+ /** Whether this exporter is disabled */
57
+ protected isDisabled: boolean;
58
+ /**
59
+ * Initialize the base exporter with logger
60
+ */
61
+ constructor(config?: BaseExporterConfig);
62
+ /**
63
+ * Set the logger for the exporter (called by Mastra/ObservabilityInstance during initialization)
64
+ */
65
+ __setLogger(logger: IMastraLogger): void;
66
+ /**
67
+ * Convert string log level to LogLevel enum
68
+ */
69
+ private resolveLogLevel;
70
+ /**
71
+ * Mark the exporter as disabled and log a message
72
+ *
73
+ * @param reason - Reason why the exporter is disabled
74
+ */
75
+ protected setDisabled(reason: string): void;
76
+ /**
77
+ * Export a tracing event
78
+ *
79
+ * This method checks if the exporter is disabled before calling _exportEvent.
80
+ * Subclasses should implement _exportEvent instead of overriding this method.
81
+ */
82
+ exportTracingEvent(event: TracingEvent): Promise<void>;
83
+ /**
84
+ * Export a tracing event - must be implemented by subclasses
85
+ *
86
+ * This method is called by exportTracingEvent after checking if the exporter is disabled.
87
+ */
88
+ protected abstract _exportTracingEvent(event: TracingEvent): Promise<void>;
89
+ /**
90
+ * Optional initialization hook called after Mastra is fully configured
91
+ */
92
+ init?(_options: InitExporterOptions): void;
93
+ /**
94
+ * Optional method to add scores to traces
95
+ */
96
+ addScoreToTrace?(_args: {
97
+ traceId: string;
98
+ spanId?: string;
99
+ score: number;
100
+ reason?: string;
101
+ scorerName: string;
102
+ metadata?: Record<string, any>;
103
+ }): Promise<void>;
104
+ /**
105
+ * Shutdown the exporter and clean up resources
106
+ *
107
+ * Default implementation just logs. Override to add custom cleanup.
108
+ */
109
+ shutdown(): Promise<void>;
110
+ }
111
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/exporters/base.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAiB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EA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AE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,GAAG,OAAO,CAAC,IAAI,CAAC;IAEjB;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGhC"}
@@ -0,0 +1,30 @@
1
+ import type { TracingEvent } from '@mastra/core/observability';
2
+ import { BaseExporter } from './base.js';
3
+ import type { BaseExporterConfig } from './base.js';
4
+ export interface CloudExporterConfig extends BaseExporterConfig {
5
+ maxBatchSize?: number;
6
+ maxBatchWaitMs?: number;
7
+ maxRetries?: number;
8
+ accessToken?: string;
9
+ endpoint?: string;
10
+ }
11
+ export declare class CloudExporter extends BaseExporter {
12
+ name: string;
13
+ private config;
14
+ private buffer;
15
+ private flushTimer;
16
+ constructor(config?: CloudExporterConfig);
17
+ protected _exportTracingEvent(event: TracingEvent): Promise<void>;
18
+ private addToBuffer;
19
+ private formatSpan;
20
+ private shouldFlush;
21
+ private scheduleFlush;
22
+ private flush;
23
+ /**
24
+ * Uploads spans to cloud API using fetchWithRetry for all retry logic
25
+ */
26
+ private batchUpload;
27
+ private resetBuffer;
28
+ shutdown(): Promise<void>;
29
+ }
30
+ //# sourceMappingURL=cloud.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../src/exporters/cloud.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAmB,MAAM,4BAA4B,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA0BD,qBAAa,aAAc,SAAQ,YAAY;IAC7C,IAAI,SAAyC;IAE7C,OAAO,CAAC,MAAM,CAAgC;IAC9C,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,UAAU,CAA+B;gBAErC,MAAM,GAAE,mBAAwB;cA8B5B,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBvE,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,UAAU;IAsBlB,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,aAAa;YAoBP,KAAK;IA8CnB;;OAEG;YACW,WAAW;IAezB,OAAO,CAAC,WAAW;IAMb,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAuChC"}
@@ -0,0 +1,10 @@
1
+ import type { TracingEvent } from '@mastra/core/observability';
2
+ import { BaseExporter } from './base.js';
3
+ import type { BaseExporterConfig } from './base.js';
4
+ export declare class ConsoleExporter extends BaseExporter {
5
+ name: string;
6
+ constructor(config?: BaseExporterConfig);
7
+ protected _exportTracingEvent(event: TracingEvent): Promise<void>;
8
+ shutdown(): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/exporters/console.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,IAAI,SAA8B;gBAEtB,MAAM,GAAE,kBAAuB;cAI3B,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA+EjE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGhC"}
@@ -0,0 +1,89 @@
1
+ import type { TracingEvent, InitExporterOptions, TracingStorageStrategy } from '@mastra/core/observability';
2
+ import type { BaseExporterConfig } from './base.js';
3
+ import { BaseExporter } from './base.js';
4
+ interface DefaultExporterConfig extends BaseExporterConfig {
5
+ maxBatchSize?: number;
6
+ maxBufferSize?: number;
7
+ maxBatchWaitMs?: number;
8
+ maxRetries?: number;
9
+ retryDelayMs?: number;
10
+ strategy?: TracingStorageStrategy | 'auto';
11
+ }
12
+ export declare class DefaultExporter extends BaseExporter {
13
+ #private;
14
+ name: string;
15
+ private buffer;
16
+ private allCreatedSpans;
17
+ constructor(config?: DefaultExporterConfig);
18
+ /**
19
+ * Initialize the exporter (called after all dependencies are ready)
20
+ */
21
+ init(options: InitExporterOptions): void;
22
+ /**
23
+ * Initialize the resolved strategy once storage is available
24
+ */
25
+ private initializeStrategy;
26
+ /**
27
+ * Builds a unique span key for tracking
28
+ */
29
+ private buildSpanKey;
30
+ /**
31
+ * Gets the next sequence number for a span
32
+ */
33
+ private getNextSequence;
34
+ /**
35
+ * Handles out-of-order span updates by logging and skipping
36
+ */
37
+ private handleOutOfOrderUpdate;
38
+ /**
39
+ * Adds an event to the appropriate buffer based on strategy
40
+ */
41
+ private addToBuffer;
42
+ /**
43
+ * Checks if buffer should be flushed based on size or time triggers
44
+ */
45
+ private shouldFlush;
46
+ /**
47
+ * Resets the buffer after successful flush
48
+ */
49
+ private resetBuffer;
50
+ /**
51
+ * Schedules a flush using setTimeout
52
+ */
53
+ private scheduleFlush;
54
+ /**
55
+ * Serializes span attributes to storage record format
56
+ * Handles all Span types and their specific attributes
57
+ */
58
+ private serializeAttributes;
59
+ private buildCreateRecord;
60
+ private buildUpdateRecord;
61
+ /**
62
+ * Handles realtime strategy - processes each event immediately
63
+ */
64
+ private handleRealtimeEvent;
65
+ /**
66
+ * Handles batch-with-updates strategy - buffers events and processes in batches
67
+ */
68
+ private handleBatchWithUpdatesEvent;
69
+ /**
70
+ * Handles insert-only strategy - only processes SPAN_ENDED events in batches
71
+ */
72
+ private handleInsertOnlyEvent;
73
+ /**
74
+ * Calculates retry delay using exponential backoff
75
+ */
76
+ private calculateRetryDelay;
77
+ /**
78
+ * Flushes the current buffer to storage with retry logic
79
+ */
80
+ private flush;
81
+ /**
82
+ * Attempts to flush with exponential backoff retry logic
83
+ */
84
+ private flushWithRetries;
85
+ _exportTracingEvent(event: TracingEvent): Promise<void>;
86
+ shutdown(): Promise<void>;
87
+ }
88
+ export {};
89
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/exporters/default.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EAEZ,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,UAAU,qBAAsB,SAAQ,kBAAkB;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAAC;CAC5C;AAwDD,qBAAa,eAAgB,SAAQ,YAAY;;IAC/C,IAAI,SAA2C;IAK/C,OAAO,CAAC,MAAM,CAAc;IAI5B,OAAO,CAAC,eAAe,CAA0B;gBAErC,MAAM,GAAE,qBAA0B;IAoC9C;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAUxC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAe1B;;OAEG;IACH,OAAO,CAAC,YAAY;IAIpB;;OAEG;IACH,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAS9B;;OAEG;IACH,OAAO,CAAC,WAAW;IAgFnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAsBnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAiBnB;;OAEG;IACH,OAAO,CAAC,aAAa;IAarB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAiC3B,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,iBAAiB;IAczB;;OAEG;YACW,mBAAmB;IAyCjC;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAgBnC;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAoB7B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;YACW,KAAK;IAsDnB;;OAEG;YACW,gBAAgB;IA2DxB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBvD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAuBhC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Mastra Tracing Exporters
3
+ */
4
+ export * from './base.js';
5
+ export { CloudExporter } from './cloud.js';
6
+ export type { CloudExporterConfig } from './cloud.js';
7
+ export * from './console.js';
8
+ export * from './default.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exporters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,QAAQ,CAAC;AAGvB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}