@mastra/observability 0.0.0-sidebar-window-undefined-fix-20251029233656 → 0.0.0-top-level-fix-20251211103030
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 +200 -3
- package/README.md +99 -0
- package/dist/config.d.ts +445 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/default.d.ts +29 -0
- package/dist/default.d.ts.map +1 -0
- package/dist/exporters/base.d.ts +111 -0
- package/dist/exporters/base.d.ts.map +1 -0
- package/dist/exporters/cloud.d.ts +30 -0
- package/dist/exporters/cloud.d.ts.map +1 -0
- package/dist/exporters/console.d.ts +10 -0
- package/dist/exporters/console.d.ts.map +1 -0
- package/dist/exporters/default.d.ts +89 -0
- package/dist/exporters/default.d.ts.map +1 -0
- package/dist/exporters/index.d.ts +10 -0
- package/dist/exporters/index.d.ts.map +1 -0
- package/dist/exporters/test.d.ts +13 -0
- package/dist/exporters/test.d.ts.map +1 -0
- package/dist/index.cjs +2517 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2496 -0
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts +110 -0
- package/dist/instances/base.d.ts.map +1 -0
- package/dist/instances/default.d.ts +8 -0
- package/dist/instances/default.d.ts.map +1 -0
- package/dist/instances/index.d.ts +6 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/model-tracing.d.ts +43 -0
- package/dist/model-tracing.d.ts.map +1 -0
- package/dist/registry.d.ts +49 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/span_processors/index.d.ts +5 -0
- package/dist/span_processors/index.d.ts.map +1 -0
- package/dist/span_processors/sensitive-data-filter.d.ts +92 -0
- package/dist/span_processors/sensitive-data-filter.d.ts.map +1 -0
- package/dist/spans/base.d.ts +110 -0
- package/dist/spans/base.d.ts.map +1 -0
- package/dist/spans/default.d.ts +13 -0
- package/dist/spans/default.d.ts.map +1 -0
- package/dist/spans/index.d.ts +7 -0
- package/dist/spans/index.d.ts.map +1 -0
- package/dist/spans/no-op.d.ts +15 -0
- package/dist/spans/no-op.d.ts.map +1 -0
- package/dist/tracing-options.d.ts +27 -0
- package/dist/tracing-options.d.ts.map +1 -0
- package/dist/usage.d.ts +21 -0
- package/dist/usage.d.ts.map +1 -0
- package/package.json +18 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/instances/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Span Tracing
|
|
3
|
+
*
|
|
4
|
+
* Provides span tracking for Model generations, including:
|
|
5
|
+
* - MODEL_STEP spans (one per Model API call)
|
|
6
|
+
* - MODEL_CHUNK spans (individual streaming chunks within a step)
|
|
7
|
+
*
|
|
8
|
+
* Hierarchy: MODEL_GENERATION -> MODEL_STEP -> MODEL_CHUNK
|
|
9
|
+
*/
|
|
10
|
+
import { SpanType } from '@mastra/core/observability';
|
|
11
|
+
import type { Span, EndGenerationOptions, ErrorSpanOptions, TracingContext, UpdateSpanOptions } from '@mastra/core/observability';
|
|
12
|
+
export declare class ModelSpanTracker {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(modelSpan?: Span<SpanType.MODEL_GENERATION>);
|
|
15
|
+
/**
|
|
16
|
+
* Get the tracing context for creating child spans.
|
|
17
|
+
* Returns the current step span if active, otherwise the model span.
|
|
18
|
+
*/
|
|
19
|
+
getTracingContext(): TracingContext;
|
|
20
|
+
/**
|
|
21
|
+
* Report an error on the generation span
|
|
22
|
+
*/
|
|
23
|
+
reportGenerationError(options: ErrorSpanOptions<SpanType.MODEL_GENERATION>): void;
|
|
24
|
+
/**
|
|
25
|
+
* End the generation span with optional raw usage data.
|
|
26
|
+
* If usage is provided, it will be converted to UsageStats with cache token details.
|
|
27
|
+
*/
|
|
28
|
+
endGeneration(options?: EndGenerationOptions): void;
|
|
29
|
+
/**
|
|
30
|
+
* Update the generation span
|
|
31
|
+
*/
|
|
32
|
+
updateGeneration(options: UpdateSpanOptions<SpanType.MODEL_GENERATION>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Wraps a stream with model tracing transform to track MODEL_STEP and MODEL_CHUNK spans.
|
|
35
|
+
*
|
|
36
|
+
* This should be added to the stream pipeline to automatically
|
|
37
|
+
* create MODEL_STEP and MODEL_CHUNK spans for each semantic unit in the stream.
|
|
38
|
+
*/
|
|
39
|
+
wrapStream<T extends {
|
|
40
|
+
pipeThrough: Function;
|
|
41
|
+
}>(stream: T): T;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=model-tracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-tracing.d.ts","sourceRoot":"","sources":["../src/model-tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,KAAK,EACV,IAAI,EACJ,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAuBpC,qBAAa,gBAAgB;;gBAaf,SAAS,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IAcvD;;;OAGG;IACH,iBAAiB,IAAI,cAAc;IAMnC;;OAEG;IACH,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI;IAIjF;;;OAGG;IACH,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,IAAI;IAWnD;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI;IA+V7E;;;;;OAKG;IACH,UAAU,CAAC,CAAC,SAAS;QAAE,WAAW,EAAE,QAAQ,CAAA;KAAE,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC;CAwG9D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability Registry for Mastra
|
|
3
|
+
*
|
|
4
|
+
* Provides registry for Observability instances.
|
|
5
|
+
*/
|
|
6
|
+
import type { ObservabilityInstance, ConfigSelectorOptions, ConfigSelector } from '@mastra/core/observability';
|
|
7
|
+
/**
|
|
8
|
+
* Registry for Observability instances.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ObservabilityRegistry {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Register a tracing instance
|
|
14
|
+
*/
|
|
15
|
+
register(name: string, instance: ObservabilityInstance, isDefault?: boolean): void;
|
|
16
|
+
/**
|
|
17
|
+
* Get a tracing instance by name
|
|
18
|
+
*/
|
|
19
|
+
get(name: string): ObservabilityInstance | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Get the default tracing instance
|
|
22
|
+
*/
|
|
23
|
+
getDefault(): ObservabilityInstance | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Set the tracing selector function
|
|
26
|
+
*/
|
|
27
|
+
setSelector(selector: ConfigSelector): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get the selected tracing instance based on context
|
|
30
|
+
*/
|
|
31
|
+
getSelected(options: ConfigSelectorOptions): ObservabilityInstance | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Unregister a tracing instance
|
|
34
|
+
*/
|
|
35
|
+
unregister(name: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Shutdown all instances and clear the registry
|
|
38
|
+
*/
|
|
39
|
+
shutdown(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Clear all instances without shutdown
|
|
42
|
+
*/
|
|
43
|
+
clear(): void;
|
|
44
|
+
/**
|
|
45
|
+
* list all registered instances
|
|
46
|
+
*/
|
|
47
|
+
list(): ReadonlyMap<string, ObservabilityInstance>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAM/G;;GAEG;AACH,qBAAa,qBAAqB;;IAKhC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,qBAAqB,EAAE,SAAS,UAAQ,GAAG,IAAI;IAahF;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;IAIpD;;OAEG;IACH,UAAU,IAAI,qBAAqB,GAAG,SAAS;IAI/C;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAI3C;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,qBAAqB,GAAG,qBAAqB,GAAG,SAAS;IAa9E;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAYjC;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAU/B;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,IAAI,IAAI,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC;CAGnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/span_processors/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { SpanOutputProcessor, AnySpan } from '@mastra/core/observability';
|
|
2
|
+
export type RedactionStyle = 'full' | 'partial';
|
|
3
|
+
/**
|
|
4
|
+
* Options for configuring the SensitiveDataFilter.
|
|
5
|
+
*/
|
|
6
|
+
export interface SensitiveDataFilterOptions {
|
|
7
|
+
/**
|
|
8
|
+
* List of sensitive field names to redact.
|
|
9
|
+
* Matching is case-insensitive and normalizes separators (`api-key`, `api_key`, `Api Key` → `apikey`).
|
|
10
|
+
*
|
|
11
|
+
* Defaults include: password, token, secret, key, apikey, auth, authorization,
|
|
12
|
+
* bearer, bearertoken, jwt, credential, clientsecret, privatekey, refresh, ssn.
|
|
13
|
+
*/
|
|
14
|
+
sensitiveFields?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* The token used for full redaction.
|
|
17
|
+
* Default: "[REDACTED]"
|
|
18
|
+
*/
|
|
19
|
+
redactionToken?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Style of redaction to use:
|
|
22
|
+
* - "full": always replace with redactionToken.
|
|
23
|
+
* - "partial": show 3 characters from the start and end, redact the middle.
|
|
24
|
+
*
|
|
25
|
+
* Default: "full"
|
|
26
|
+
*/
|
|
27
|
+
redactionStyle?: RedactionStyle;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* SensitiveDataFilter
|
|
31
|
+
*
|
|
32
|
+
* An SpanOutputProcessor that redacts sensitive information from span fields.
|
|
33
|
+
*
|
|
34
|
+
* - Sensitive keys are matched case-insensitively, normalized to remove separators.
|
|
35
|
+
* - Sensitive values are redacted using either full or partial redaction.
|
|
36
|
+
* - Partial redaction always keeps 3 chars at the start and end.
|
|
37
|
+
* - JSON strings containing sensitive fields are parsed and redacted.
|
|
38
|
+
* - If filtering a field fails, the field is replaced with:
|
|
39
|
+
* `{ error: { processor: "sensitive-data-filter" } }`
|
|
40
|
+
*/
|
|
41
|
+
export declare class SensitiveDataFilter implements SpanOutputProcessor {
|
|
42
|
+
name: string;
|
|
43
|
+
private sensitiveFields;
|
|
44
|
+
private redactionToken;
|
|
45
|
+
private redactionStyle;
|
|
46
|
+
constructor(options?: SensitiveDataFilterOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Process a span by filtering sensitive data across its key fields.
|
|
49
|
+
* Fields processed: attributes, metadata, input, output, errorInfo.
|
|
50
|
+
*
|
|
51
|
+
* @param span - The input span to filter
|
|
52
|
+
* @returns A new span with sensitive values redacted
|
|
53
|
+
*/
|
|
54
|
+
process(span: AnySpan): AnySpan;
|
|
55
|
+
/**
|
|
56
|
+
* Recursively filter objects/arrays for sensitive keys.
|
|
57
|
+
* Handles circular references by replacing with a marker.
|
|
58
|
+
* Also attempts to parse and redact JSON strings.
|
|
59
|
+
*/
|
|
60
|
+
private deepFilter;
|
|
61
|
+
private tryFilter;
|
|
62
|
+
/**
|
|
63
|
+
* Normalize keys by lowercasing and stripping non-alphanumeric characters.
|
|
64
|
+
* Ensures consistent matching for variants like "api-key", "api_key", "Api Key".
|
|
65
|
+
*/
|
|
66
|
+
private normalizeKey;
|
|
67
|
+
/**
|
|
68
|
+
* Check whether a normalized key exactly matches any sensitive field.
|
|
69
|
+
* Both key and sensitive fields are normalized by removing all non-alphanumeric
|
|
70
|
+
* characters and converting to lowercase before comparison.
|
|
71
|
+
*
|
|
72
|
+
* Examples:
|
|
73
|
+
* - "api_key", "api-key", "ApiKey" all normalize to "apikey" → MATCHES "apikey"
|
|
74
|
+
* - "promptTokens", "prompt_tokens" normalize to "prompttokens" → DOES NOT MATCH "token"
|
|
75
|
+
*/
|
|
76
|
+
private isSensitive;
|
|
77
|
+
/**
|
|
78
|
+
* Attempt to parse a string as JSON and redact sensitive fields within it.
|
|
79
|
+
* If parsing fails or no sensitive data is found, returns the original string.
|
|
80
|
+
*/
|
|
81
|
+
private redactJsonString;
|
|
82
|
+
/**
|
|
83
|
+
* Redact a sensitive value.
|
|
84
|
+
* - Full style: replaces with a fixed token.
|
|
85
|
+
* - Partial style: shows 3 chars at start and end, hides the middle.
|
|
86
|
+
*
|
|
87
|
+
* Non-string values are converted to strings before partial redaction.
|
|
88
|
+
*/
|
|
89
|
+
private redactValue;
|
|
90
|
+
shutdown(): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=sensitive-data-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sensitive-data-filter.d.ts","sourceRoot":"","sources":["../../src/span_processors/sensitive-data-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE/E,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,mBAAoB,YAAW,mBAAmB;IAC7D,IAAI,SAA2B;IAC/B,OAAO,CAAC,eAAe,CAAW;IAClC,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,cAAc,CAAiB;gBAE3B,OAAO,GAAE,0BAA+B;IAyBpD;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO;IAS/B;;;;OAIG;IACH,OAAO,CAAC,UAAU;IAwClB,OAAO,CAAC,SAAS;IAQjB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAIpB;;;;;;;;OAQG;IACH,OAAO,CAAC,WAAW;IAOnB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IAab,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGhC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Span, SpanTypeMap, AnySpan, ChildSpanOptions, ChildEventOptions, EndSpanOptions, ErrorSpanOptions, UpdateSpanOptions, CreateSpanOptions, ObservabilityInstance, ExportedSpan, TraceState, IModelSpanTracker, AIModelGenerationSpan } from '@mastra/core/observability';
|
|
2
|
+
import { SpanType } from '@mastra/core/observability';
|
|
3
|
+
/**
|
|
4
|
+
* Get the external parent span ID from CreateSpanOptions.
|
|
5
|
+
*
|
|
6
|
+
* If the parent is internal, walks up the parent chain to find
|
|
7
|
+
* the closest external ancestor. If the parent is already external,
|
|
8
|
+
* returns its ID directly.
|
|
9
|
+
*
|
|
10
|
+
* This is useful when exporting spans to external observability systems
|
|
11
|
+
* that shouldn't include internal framework spans.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Span creation options
|
|
14
|
+
* @returns The external parent span ID, or undefined if no external parent exists
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Parent is external - returns parent.id
|
|
19
|
+
* const externalParent = { id: 'span-123', isInternal: false };
|
|
20
|
+
* const options = { parent: externalParent, ... };
|
|
21
|
+
* getExternalParentId(options); // 'span-123'
|
|
22
|
+
*
|
|
23
|
+
* // Parent is internal - walks up to find external ancestor
|
|
24
|
+
* const externalGrandparent = { id: 'span-456', isInternal: false };
|
|
25
|
+
* const internalParent = { id: 'span-123', isInternal: true, parent: externalGrandparent };
|
|
26
|
+
* const options = { parent: internalParent, ... };
|
|
27
|
+
* getExternalParentId(options); // 'span-456'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function getExternalParentId(options: CreateSpanOptions<any>): string | undefined;
|
|
31
|
+
export declare abstract class BaseSpan<TType extends SpanType = any> implements Span<TType> {
|
|
32
|
+
abstract id: string;
|
|
33
|
+
abstract traceId: string;
|
|
34
|
+
name: string;
|
|
35
|
+
type: TType;
|
|
36
|
+
attributes: SpanTypeMap[TType];
|
|
37
|
+
parent?: AnySpan;
|
|
38
|
+
startTime: Date;
|
|
39
|
+
endTime?: Date;
|
|
40
|
+
isEvent: boolean;
|
|
41
|
+
isInternal: boolean;
|
|
42
|
+
observabilityInstance: ObservabilityInstance;
|
|
43
|
+
input?: any;
|
|
44
|
+
output?: any;
|
|
45
|
+
errorInfo?: {
|
|
46
|
+
message: string;
|
|
47
|
+
id?: string;
|
|
48
|
+
domain?: string;
|
|
49
|
+
category?: string;
|
|
50
|
+
details?: Record<string, any>;
|
|
51
|
+
};
|
|
52
|
+
metadata?: Record<string, any>;
|
|
53
|
+
tags?: string[];
|
|
54
|
+
traceState?: TraceState;
|
|
55
|
+
/** Parent span ID (for root spans that are children of external spans) */
|
|
56
|
+
protected parentSpanId?: string;
|
|
57
|
+
constructor(options: CreateSpanOptions<TType>, observabilityInstance: ObservabilityInstance);
|
|
58
|
+
/** End the span */
|
|
59
|
+
abstract end(options?: EndSpanOptions<TType>): void;
|
|
60
|
+
/** Record an error for the span, optionally end the span as well */
|
|
61
|
+
abstract error(options: ErrorSpanOptions<TType>): void;
|
|
62
|
+
/** Update span attributes */
|
|
63
|
+
abstract update(options: UpdateSpanOptions<TType>): void;
|
|
64
|
+
createChildSpan(options: ChildSpanOptions<SpanType.MODEL_GENERATION>): AIModelGenerationSpan;
|
|
65
|
+
createEventSpan<TChildType extends SpanType>(options: ChildEventOptions<TChildType>): Span<TChildType>;
|
|
66
|
+
/**
|
|
67
|
+
* Create a ModelSpanTracker for this span (only works if this is a MODEL_GENERATION span)
|
|
68
|
+
* Returns undefined for non-MODEL_GENERATION spans
|
|
69
|
+
*/
|
|
70
|
+
createTracker(): IModelSpanTracker | undefined;
|
|
71
|
+
/** Returns `TRUE` if the span is the root span of a trace */
|
|
72
|
+
get isRootSpan(): boolean;
|
|
73
|
+
/** Returns `TRUE` if the span is a valid span (not a NO-OP Span) */
|
|
74
|
+
abstract get isValid(): boolean;
|
|
75
|
+
/** Get the closest parent spanId that isn't an internal span */
|
|
76
|
+
getParentSpanId(includeInternalSpans?: boolean): string | undefined;
|
|
77
|
+
/** Find the closest parent span of a specific type by walking up the parent chain */
|
|
78
|
+
findParent<T extends SpanType>(spanType: T): Span<T> | undefined;
|
|
79
|
+
/** Returns a lightweight span ready for export */
|
|
80
|
+
exportSpan(includeInternalSpans?: boolean): ExportedSpan<TType>;
|
|
81
|
+
get externalTraceId(): string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Execute an async function within this span's tracing context.
|
|
84
|
+
* Delegates to the bridge if available.
|
|
85
|
+
*/
|
|
86
|
+
executeInContext<T>(fn: () => Promise<T>): Promise<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Execute a synchronous function within this span's tracing context.
|
|
89
|
+
* Delegates to the bridge if available.
|
|
90
|
+
*/
|
|
91
|
+
executeInContextSync<T>(fn: () => T): T;
|
|
92
|
+
}
|
|
93
|
+
export interface DeepCleanOptions {
|
|
94
|
+
keysToStrip?: Set<string>;
|
|
95
|
+
maxDepth?: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Recursively cleans a value by removing circular references and stripping problematic or sensitive keys.
|
|
99
|
+
* Circular references are replaced with "[Circular]". Unserializable values are replaced with error messages.
|
|
100
|
+
* Keys like "logger" and "tracingContext" are stripped by default.
|
|
101
|
+
* A maximum recursion depth is enforced to avoid stack overflow or excessive memory usage.
|
|
102
|
+
*
|
|
103
|
+
* @param value - The value to clean (object, array, primitive, etc.)
|
|
104
|
+
* @param options - Optional configuration:
|
|
105
|
+
* - keysToStrip: Set of keys to remove from objects (default: logger, tracingContext)
|
|
106
|
+
* - maxDepth: Maximum recursion depth before values are replaced with "[MaxDepth]" (default: 10)
|
|
107
|
+
* @returns A cleaned version of the input with circular references, specified keys, and overly deep values handled
|
|
108
|
+
*/
|
|
109
|
+
export declare function deepClean(value: any, options?: DeepCleanOptions, _seen?: WeakSet<any>, _depth?: number): any;
|
|
110
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/spans/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,WAAW,EACX,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,gBA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AAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAU3D;;;OAGG;IACH,oBAAoB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;CASxC;AASD,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,GAAG,EACV,OAAO,GAAE,gBAAqB,EAC9B,KAAK,GAAE,OAAO,CAAC,GAAG,CAAiB,EACnC,MAAM,GAAE,MAAU,GACjB,GAAG,CA6CL"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SpanType, ObservabilityInstance, EndSpanOptions, ErrorSpanOptions, UpdateSpanOptions, CreateSpanOptions } from '@mastra/core/observability';
|
|
2
|
+
import { BaseSpan } from './base.js';
|
|
3
|
+
export declare class DefaultSpan<TType extends SpanType> extends BaseSpan<TType> {
|
|
4
|
+
id: string;
|
|
5
|
+
traceId: string;
|
|
6
|
+
constructor(options: CreateSpanOptions<TType>, observabilityInstance: ObservabilityInstance);
|
|
7
|
+
end(options?: EndSpanOptions<TType>): void;
|
|
8
|
+
error(options: ErrorSpanOptions<TType>): void;
|
|
9
|
+
update(options: UpdateSpanOptions<TType>): void;
|
|
10
|
+
get isValid(): boolean;
|
|
11
|
+
export(): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=default.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/spans/default.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAa,MAAM,QAAQ,CAAC;AAE7C,qBAAa,WAAW,CAAC,KAAK,SAAS,QAAQ,CAAE,SAAQ,QAAQ,CAAC,KAAK,CAAC;IAC/D,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAAE,qBAAqB,EAAE,qBAAqB;IAqC3F,GAAG,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IAiB1C,KAAK,CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAAG,IAAI;IAoC7C,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,IAAI;IAoB/C,IAAI,OAAO,IAAI,OAAO,CAErB;IAEK,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;CAUhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spans/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NoOpSpan Implementation for Mastra Observability
|
|
3
|
+
*/
|
|
4
|
+
import type { ObservabilityInstance, SpanType, CreateSpanOptions, EndSpanOptions, UpdateSpanOptions, ErrorSpanOptions } from '@mastra/core/observability';
|
|
5
|
+
import { BaseSpan } from './base.js';
|
|
6
|
+
export declare class NoOpSpan<TType extends SpanType = any> extends BaseSpan<TType> {
|
|
7
|
+
id: string;
|
|
8
|
+
traceId: string;
|
|
9
|
+
constructor(options: CreateSpanOptions<TType>, observabilityInstance: ObservabilityInstance);
|
|
10
|
+
end(_options?: EndSpanOptions<TType>): void;
|
|
11
|
+
error(_options: ErrorSpanOptions<TType>): void;
|
|
12
|
+
update(_options: UpdateSpanOptions<TType>): void;
|
|
13
|
+
get isValid(): boolean;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=no-op.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-op.d.ts","sourceRoot":"","sources":["../../src/spans/no-op.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,qBAAa,QAAQ,CAAC,KAAK,SAAS,QAAQ,GAAG,GAAG,CAAE,SAAQ,QAAQ,CAAC,KAAK,CAAC;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAAE,qBAAqB,EAAE,qBAAqB;IAM3F,GAAG,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IAE3C,KAAK,CAAC,QAAQ,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAAG,IAAI;IAE9C,MAAM,CAAC,QAAQ,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,IAAI;IAEhD,IAAI,OAAO,IAAI,OAAO,CAErB;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable Tracing Options Builder
|
|
3
|
+
*/
|
|
4
|
+
import type { TracingOptions } from '@mastra/core/observability';
|
|
5
|
+
/**
|
|
6
|
+
* A function that updates TracingOptions.
|
|
7
|
+
*/
|
|
8
|
+
export type TracingOptionsUpdater = (options: TracingOptions) => TracingOptions;
|
|
9
|
+
/**
|
|
10
|
+
* Builds TracingOptions by composing one or more updater functions.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { buildTracingOptions } from '@mastra/observability';
|
|
15
|
+
* import { withLangfusePrompt } from '@mastra/langfuse';
|
|
16
|
+
*
|
|
17
|
+
* const prompt = await langfuse.getPrompt('my-prompt');
|
|
18
|
+
*
|
|
19
|
+
* const agent = new Agent({
|
|
20
|
+
* defaultGenerateOptions: {
|
|
21
|
+
* tracingOptions: buildTracingOptions(withLangfusePrompt(prompt)),
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildTracingOptions(...updaters: TracingOptionsUpdater[]): TracingOptions;
|
|
27
|
+
//# sourceMappingURL=tracing-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing-options.d.ts","sourceRoot":"","sources":["../src/tracing-options.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,cAAc,CAAC;AAEhF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,QAAQ,EAAE,qBAAqB,EAAE,GAAG,cAAc,CAExF"}
|
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage extraction utilities for converting AI SDK usage to Mastra UsageStats
|
|
3
|
+
*/
|
|
4
|
+
import type { UsageStats } from '@mastra/core/observability';
|
|
5
|
+
import type { LanguageModelUsage, ProviderMetadata } from '@mastra/core/stream';
|
|
6
|
+
/**
|
|
7
|
+
* Extracts and normalizes token usage from AI SDK response, including
|
|
8
|
+
* provider-specific cache tokens from providerMetadata.
|
|
9
|
+
*
|
|
10
|
+
* Handles:
|
|
11
|
+
* - OpenAI: cachedInputTokens in usage object
|
|
12
|
+
* - Anthropic: cacheCreationInputTokens, cacheReadInputTokens in providerMetadata.anthropic
|
|
13
|
+
* - Google/Gemini: cachedContentTokenCount, thoughtsTokenCount in providerMetadata.google.usageMetadata
|
|
14
|
+
* - OpenRouter: Uses OpenAI-compatible structure (cache tokens in usage)
|
|
15
|
+
*
|
|
16
|
+
* @param usage - The LanguageModelV2Usage from AI SDK response
|
|
17
|
+
* @param providerMetadata - Optional provider-specific metadata
|
|
18
|
+
* @returns UsageStats with inputDetails and outputDetails
|
|
19
|
+
*/
|
|
20
|
+
export declare function extractUsageMetrics(usage?: LanguageModelUsage, providerMetadata?: ProviderMetadata): UsageStats;
|
|
21
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAyC,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAoBhF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,CAAC,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,UAAU,CA4E/G"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/observability",
|
|
3
|
-
"version": "0.0.0-
|
|
4
|
-
"description": "Core observability package for Mastra - includes
|
|
3
|
+
"version": "0.0.0-top-level-fix-20251211103030",
|
|
4
|
+
"description": "Core observability package for Mastra - includes tracing and scoring features",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -23,20 +23,26 @@
|
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
|
-
"dependencies": {},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@microsoft/api-extractor": "^7.52.8",
|
|
29
|
-
"@types/node": "
|
|
28
|
+
"@types/node": "22.13.17",
|
|
29
|
+
"@vitest/coverage-v8": "4.0.12",
|
|
30
|
+
"@vitest/ui": "4.0.12",
|
|
31
|
+
"ai": "^4.3.16",
|
|
32
|
+
"ai-v5": "npm:ai@5.0.97",
|
|
30
33
|
"eslint": "^9.37.0",
|
|
31
34
|
"tsup": "^8.5.0",
|
|
32
35
|
"typescript": "^5.8.3",
|
|
33
|
-
"vitest": "
|
|
34
|
-
"@internal/
|
|
35
|
-
"@mastra/core": "0.0.0-
|
|
36
|
-
"@internal/
|
|
36
|
+
"vitest": "4.0.12",
|
|
37
|
+
"@internal/types-builder": "0.0.0-top-level-fix-20251211103030",
|
|
38
|
+
"@mastra/core": "0.0.0-top-level-fix-20251211103030",
|
|
39
|
+
"@internal/lint": "0.0.0-top-level-fix-20251211103030"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"zod": "^3.25.76"
|
|
37
43
|
},
|
|
38
44
|
"peerDependencies": {
|
|
39
|
-
"@mastra/core": "0.0.0-
|
|
45
|
+
"@mastra/core": "0.0.0-top-level-fix-20251211103030"
|
|
40
46
|
},
|
|
41
47
|
"homepage": "https://mastra.ai",
|
|
42
48
|
"repository": {
|
|
@@ -47,6 +53,9 @@
|
|
|
47
53
|
"bugs": {
|
|
48
54
|
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
49
55
|
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=22.13.0"
|
|
58
|
+
},
|
|
50
59
|
"scripts": {
|
|
51
60
|
"build": "tsup --silent --config tsup.config.ts",
|
|
52
61
|
"build:watch": "pnpm build --watch",
|