@countly/ai-sdk-mastra 0.0.1
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/dist/adapter.d.ts +118 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +114 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/span-aggregator.d.ts +7 -0
- package/dist/span-aggregator.d.ts.map +1 -0
- package/dist/span-aggregator.js +190 -0
- package/dist/span-aggregator.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type CountlyAIConfig } from "@countly/ai-sdk-core";
|
|
2
|
+
/**
|
|
3
|
+
* Extended config for the Mastra exporter that supports reading a device ID
|
|
4
|
+
* from Mastra's per-request context (`requestContext`).
|
|
5
|
+
*/
|
|
6
|
+
export interface CountlyMastraExporterConfig extends CountlyAIConfig {
|
|
7
|
+
/** Key under requestContext for device_id. Default: "countlyDeviceId". Set null to disable. */
|
|
8
|
+
requestContextDeviceIdKey?: string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Key under requestContext for the workflow name (mirrors the deviceId pattern).
|
|
11
|
+
* Default: "workflowName". Set null to disable workflow_name extraction entirely.
|
|
12
|
+
* The consumer is expected to call `requestContext.set("workflowName", "<my-workflow>")`
|
|
13
|
+
* inside each workflow step that should be tagged.
|
|
14
|
+
*/
|
|
15
|
+
requestContextWorkflowNameKey?: string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Key under requestContext for the conversation/thread id used to group multiple
|
|
18
|
+
* traces produced by a single user message into one chat journey.
|
|
19
|
+
* Default: "threadId". Set null to disable.
|
|
20
|
+
*/
|
|
21
|
+
requestContextThreadIdKey?: string | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* TracingEvent mirrors the Mastra v1 ObservabilityExporter event type.
|
|
25
|
+
* Defined inline to avoid requiring @mastra/observability as a direct dependency.
|
|
26
|
+
*/
|
|
27
|
+
export interface TracingEvent {
|
|
28
|
+
type: "span_started" | "span_updated" | "span_ended";
|
|
29
|
+
exportedSpan: {
|
|
30
|
+
id: string;
|
|
31
|
+
traceId: string;
|
|
32
|
+
parentSpanId?: string;
|
|
33
|
+
isRootSpan?: boolean;
|
|
34
|
+
name: string;
|
|
35
|
+
type?: string;
|
|
36
|
+
entityName?: string;
|
|
37
|
+
entityType?: string;
|
|
38
|
+
attributes?: Record<string, any>;
|
|
39
|
+
startTime?: Date | number;
|
|
40
|
+
endTime?: Date | number;
|
|
41
|
+
input?: any;
|
|
42
|
+
output?: any;
|
|
43
|
+
errorInfo?: {
|
|
44
|
+
message: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
stack?: string;
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
};
|
|
49
|
+
metadata?: Record<string, any>;
|
|
50
|
+
tags?: string[];
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* ObservabilityExporter interface defined inline to match the Mastra v1
|
|
56
|
+
* exporter contract without requiring @mastra/core or @mastra/observability
|
|
57
|
+
* as direct dependencies.
|
|
58
|
+
*/
|
|
59
|
+
interface ObservabilityExporter {
|
|
60
|
+
name: string;
|
|
61
|
+
init?(options: any): void;
|
|
62
|
+
exportTracingEvent(event: TracingEvent): Promise<void>;
|
|
63
|
+
addScoreToTrace?(params: {
|
|
64
|
+
traceId: string;
|
|
65
|
+
spanId: string;
|
|
66
|
+
score: number;
|
|
67
|
+
reason?: string;
|
|
68
|
+
scorerName: string;
|
|
69
|
+
metadata?: Record<string, any>;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
flush(): Promise<void>;
|
|
72
|
+
shutdown(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* CountlyMastraExporter collects Mastra tracing events and sends
|
|
76
|
+
* them to Countly as AI interaction events.
|
|
77
|
+
*
|
|
78
|
+
* Implements the Mastra v1 ObservabilityExporter interface. Events are
|
|
79
|
+
* buffered per-traceId and processed when a root span (no parentSpanId)
|
|
80
|
+
* ends, or when flush()/shutdown() is called.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { Mastra } from "@mastra/core/mastra";
|
|
85
|
+
* import { Observability } from "@mastra/observability";
|
|
86
|
+
* import { CountlyMastraExporter } from "@countly/ai-sdk-mastra";
|
|
87
|
+
*
|
|
88
|
+
* new Mastra({
|
|
89
|
+
* observability: new Observability({
|
|
90
|
+
* configs: {
|
|
91
|
+
* default: {
|
|
92
|
+
* serviceName: "my-ai-app",
|
|
93
|
+
* exporters: [new CountlyMastraExporter({
|
|
94
|
+
* appKey: "YOUR_APP_KEY",
|
|
95
|
+
* url: "https://your-countly-server.com",
|
|
96
|
+
* })],
|
|
97
|
+
* },
|
|
98
|
+
* },
|
|
99
|
+
* }),
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare class CountlyMastraExporter implements ObservabilityExporter {
|
|
104
|
+
readonly name = "countly";
|
|
105
|
+
private readonly config;
|
|
106
|
+
private readonly transport;
|
|
107
|
+
private readonly buffer;
|
|
108
|
+
private readonly contextKey;
|
|
109
|
+
private readonly workflowKey;
|
|
110
|
+
private readonly threadKey;
|
|
111
|
+
constructor(userConfig: CountlyMastraExporterConfig);
|
|
112
|
+
exportTracingEvent(event: TracingEvent): Promise<void>;
|
|
113
|
+
flush(): Promise<void>;
|
|
114
|
+
shutdown(): Promise<void>;
|
|
115
|
+
private processTrace;
|
|
116
|
+
}
|
|
117
|
+
export {};
|
|
118
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,eAA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CrB"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { resolveConfig, createTransport, buildAllEvents, generatePromptId, } from "@countly/ai-sdk-core";
|
|
2
|
+
import { aggregateSpans } from "./span-aggregator";
|
|
3
|
+
/**
|
|
4
|
+
* CountlyMastraExporter collects Mastra tracing events and sends
|
|
5
|
+
* them to Countly as AI interaction events.
|
|
6
|
+
*
|
|
7
|
+
* Implements the Mastra v1 ObservabilityExporter interface. Events are
|
|
8
|
+
* buffered per-traceId and processed when a root span (no parentSpanId)
|
|
9
|
+
* ends, or when flush()/shutdown() is called.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { Mastra } from "@mastra/core/mastra";
|
|
14
|
+
* import { Observability } from "@mastra/observability";
|
|
15
|
+
* import { CountlyMastraExporter } from "@countly/ai-sdk-mastra";
|
|
16
|
+
*
|
|
17
|
+
* new Mastra({
|
|
18
|
+
* observability: new Observability({
|
|
19
|
+
* configs: {
|
|
20
|
+
* default: {
|
|
21
|
+
* serviceName: "my-ai-app",
|
|
22
|
+
* exporters: [new CountlyMastraExporter({
|
|
23
|
+
* appKey: "YOUR_APP_KEY",
|
|
24
|
+
* url: "https://your-countly-server.com",
|
|
25
|
+
* })],
|
|
26
|
+
* },
|
|
27
|
+
* },
|
|
28
|
+
* }),
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class CountlyMastraExporter {
|
|
33
|
+
name = "countly";
|
|
34
|
+
config;
|
|
35
|
+
transport;
|
|
36
|
+
buffer = new Map();
|
|
37
|
+
contextKey;
|
|
38
|
+
workflowKey;
|
|
39
|
+
threadKey;
|
|
40
|
+
constructor(userConfig) {
|
|
41
|
+
this.config = resolveConfig(userConfig);
|
|
42
|
+
this.transport = createTransport(this.config);
|
|
43
|
+
this.contextKey = userConfig.requestContextDeviceIdKey === null
|
|
44
|
+
? null
|
|
45
|
+
: (userConfig.requestContextDeviceIdKey ?? "countlyDeviceId");
|
|
46
|
+
this.workflowKey = userConfig.requestContextWorkflowNameKey === null
|
|
47
|
+
? null
|
|
48
|
+
: (userConfig.requestContextWorkflowNameKey ?? "workflowName");
|
|
49
|
+
this.threadKey = userConfig.requestContextThreadIdKey === null
|
|
50
|
+
? null
|
|
51
|
+
: (userConfig.requestContextThreadIdKey ?? "threadId");
|
|
52
|
+
}
|
|
53
|
+
async exportTracingEvent(event) {
|
|
54
|
+
const traceId = event.exportedSpan.traceId;
|
|
55
|
+
const existing = this.buffer.get(traceId);
|
|
56
|
+
if (existing) {
|
|
57
|
+
existing.push(event);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.buffer.set(traceId, [event]);
|
|
61
|
+
}
|
|
62
|
+
// On span_ended for root span, process the trace
|
|
63
|
+
const isRoot = event.exportedSpan.isRootSpan ?? !event.exportedSpan.parentSpanId;
|
|
64
|
+
if (event.type === "span_ended" && isRoot) {
|
|
65
|
+
const events = this.buffer.get(traceId);
|
|
66
|
+
this.buffer.delete(traceId);
|
|
67
|
+
if (events) {
|
|
68
|
+
this.processTrace(events);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async flush() {
|
|
73
|
+
// Process all remaining buffered traces
|
|
74
|
+
for (const [traceId, events] of this.buffer) {
|
|
75
|
+
this.processTrace(events);
|
|
76
|
+
}
|
|
77
|
+
this.buffer.clear();
|
|
78
|
+
await this.transport.flush();
|
|
79
|
+
}
|
|
80
|
+
async shutdown() {
|
|
81
|
+
await this.flush();
|
|
82
|
+
await this.transport.shutdown();
|
|
83
|
+
}
|
|
84
|
+
processTrace(events) {
|
|
85
|
+
const raw = aggregateSpans(events, { contextKey: this.contextKey, workflowKey: this.workflowKey });
|
|
86
|
+
// Extract thread_id from root span's requestContext (mirrors the device/workflow pattern).
|
|
87
|
+
let threadId;
|
|
88
|
+
if (this.threadKey) {
|
|
89
|
+
const rootEnded = events.find((e) => e.type === "span_ended" && (e.exportedSpan.isRootSpan === true || !e.exportedSpan.parentSpanId));
|
|
90
|
+
const rc = rootEnded?.exportedSpan.requestContext;
|
|
91
|
+
const candidate = rc?.[this.threadKey];
|
|
92
|
+
if (typeof candidate === "string" && candidate.length > 0) {
|
|
93
|
+
threadId = candidate;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const context = {
|
|
97
|
+
prompt_id: generatePromptId(),
|
|
98
|
+
sdk_adapter: "mastra",
|
|
99
|
+
};
|
|
100
|
+
if (threadId) {
|
|
101
|
+
context.thread_id = threadId;
|
|
102
|
+
}
|
|
103
|
+
const builtEvents = buildAllEvents(raw, this.config, context);
|
|
104
|
+
if (builtEvents.length > 0) {
|
|
105
|
+
this.transport.enqueue(builtEvents);
|
|
106
|
+
}
|
|
107
|
+
this.transport.reportTrace(raw, context);
|
|
108
|
+
this.transport.reportUserData(raw);
|
|
109
|
+
if (raw.status === "error" && raw.error) {
|
|
110
|
+
this.transport.reportError(raw.error, raw);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EACf,cAAc,EACd,gBAAgB,GAIjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAwEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,qBAAqB;IACvB,IAAI,GAAG,SAAS,CAAC;IAET,MAAM,CAAiB;IACvB,SAAS,CAAY;IACrB,MAAM,GAAgC,IAAI,GAAG,EAAE,CAAC;IAChD,UAAU,CAAgB;IAC1B,WAAW,CAAgB;IAC3B,SAAS,CAAgB;IAE1C,YAAY,UAAuC;QACjD,IAAI,CAAC,MAAM,GAAG,aAAa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,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1D,QAAQ,GAAG,SAAS,CAAC;YACvB,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAmE;YAC9E,SAAS,EAAE,gBAAgB,EAAE;YAC7B,WAAW,EAAE,QAAQ;SACtB,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC/B,CAAC;QAED,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE9D,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QAEnC,IAAI,GAAG,CAAC,MAAM,KAAK,OAAO,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;YACxC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RawExtractionResult } from "@countly/ai-sdk-core";
|
|
2
|
+
import type { TracingEvent } from "./adapter";
|
|
3
|
+
export declare function aggregateSpans(events: TracingEvent[], options?: {
|
|
4
|
+
contextKey?: string | null;
|
|
5
|
+
workflowKey?: string | null;
|
|
6
|
+
}): RawExtractionResult;
|
|
7
|
+
//# sourceMappingURL=span-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span-aggregator.d.ts","sourceRoot":"","sources":["../src/span-aggregator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAe,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAuB9C,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,EAAE,EACtB,OAAO,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACpE,mBAAmB,CAgMrB"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aggregates an array of Mastra TracingEvents from a single trace into a
|
|
3
|
+
* RawExtractionResult suitable for Countly event building.
|
|
4
|
+
*
|
|
5
|
+
* Reads structured fields from ExportedSpan (Mastra v1 types):
|
|
6
|
+
* - attributes.model, attributes.provider, attributes.usage, attributes.finishReason
|
|
7
|
+
* - span.input, span.output, span.errorInfo, span.entityName
|
|
8
|
+
* - span.isRootSpan, span.startTime (Date), span.endTime (Date)
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Convert various time representations to milliseconds.
|
|
12
|
+
* Handles Date objects, numeric ms timestamps, and OpenTelemetry [seconds, nanos] tuples.
|
|
13
|
+
*/
|
|
14
|
+
function toMs(t) {
|
|
15
|
+
if (t == null)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (t instanceof Date)
|
|
18
|
+
return t.getTime();
|
|
19
|
+
if (typeof t === "number")
|
|
20
|
+
return t;
|
|
21
|
+
if (Array.isArray(t) && t.length === 2)
|
|
22
|
+
return t[0] * 1000 + Math.floor(t[1] / 1e6);
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
export function aggregateSpans(events, options) {
|
|
26
|
+
let totalInputTokens = 0;
|
|
27
|
+
let totalOutputTokens = 0;
|
|
28
|
+
let modelName = "unknown";
|
|
29
|
+
let modelProvider = "unknown";
|
|
30
|
+
let finishReason;
|
|
31
|
+
let hasError = false;
|
|
32
|
+
let errorMessage;
|
|
33
|
+
const tools = [];
|
|
34
|
+
let stepCount = 0;
|
|
35
|
+
let responseId;
|
|
36
|
+
let responseModel;
|
|
37
|
+
let cacheRead;
|
|
38
|
+
let cacheWrite;
|
|
39
|
+
let reasoningTokens;
|
|
40
|
+
let providerMetadata;
|
|
41
|
+
// Extract spans from events
|
|
42
|
+
const spans = events.map((e) => e.exportedSpan);
|
|
43
|
+
// Find the span_ended event for the root span (has both startTime and endTime)
|
|
44
|
+
const rootEndedEvent = events.find((e) => e.type === "span_ended" && (e.exportedSpan.isRootSpan === true || !e.exportedSpan.parentSpanId));
|
|
45
|
+
const rootSpan = rootEndedEvent?.exportedSpan ??
|
|
46
|
+
spans.find((s) => s.isRootSpan === true) ??
|
|
47
|
+
spans.find((s) => !s.parentSpanId) ??
|
|
48
|
+
spans[0];
|
|
49
|
+
// Process each span by type
|
|
50
|
+
for (const span of spans) {
|
|
51
|
+
const attrs = span.attributes ?? {};
|
|
52
|
+
const spanType = span.type ?? attrs["mastra.span.type"] ?? span.name;
|
|
53
|
+
if (spanType === "model_generation") {
|
|
54
|
+
const usage = attrs.usage ?? {};
|
|
55
|
+
totalInputTokens += Number(usage.inputTokens ?? 0);
|
|
56
|
+
totalOutputTokens += Number(usage.outputTokens ?? 0);
|
|
57
|
+
// Cache + reasoning token breakdowns (provider-rich detail Mastra exposes via OTel-shaped attrs).
|
|
58
|
+
const inDetails = usage.inputTokenDetails ?? {};
|
|
59
|
+
const outDetails = usage.outputTokenDetails ?? {};
|
|
60
|
+
if (typeof inDetails.cacheRead === "number") {
|
|
61
|
+
cacheRead = (cacheRead ?? 0) + inDetails.cacheRead;
|
|
62
|
+
}
|
|
63
|
+
if (typeof inDetails.cacheWrite === "number") {
|
|
64
|
+
cacheWrite = (cacheWrite ?? 0) + inDetails.cacheWrite;
|
|
65
|
+
}
|
|
66
|
+
if (typeof outDetails.reasoning === "number") {
|
|
67
|
+
reasoningTokens = (reasoningTokens ?? 0) + outDetails.reasoning;
|
|
68
|
+
}
|
|
69
|
+
// Provider response identity (latest non-empty wins; spans may set on either start or end).
|
|
70
|
+
if (typeof attrs.responseId === "string" && attrs.responseId.length > 0) {
|
|
71
|
+
responseId = attrs.responseId;
|
|
72
|
+
}
|
|
73
|
+
if (typeof attrs.responseModel === "string" && attrs.responseModel.length > 0) {
|
|
74
|
+
responseModel = attrs.responseModel;
|
|
75
|
+
}
|
|
76
|
+
// Provider-specific rich metadata (system_fingerprint, stop_sequence, safety, etc.)
|
|
77
|
+
if (attrs.providerMetadata && typeof attrs.providerMetadata === "object") {
|
|
78
|
+
providerMetadata = { ...(providerMetadata ?? {}), ...attrs.providerMetadata };
|
|
79
|
+
}
|
|
80
|
+
// Model name + provider: first span (set at start, doesn't change mid-run)
|
|
81
|
+
if (modelName === "unknown") {
|
|
82
|
+
modelName = String(attrs.model ?? "unknown");
|
|
83
|
+
modelProvider = String(attrs.provider ?? "unknown");
|
|
84
|
+
}
|
|
85
|
+
// Finish reason: latest non-empty wins (only present on span_ended)
|
|
86
|
+
const candidate = String(attrs.finishReason ??
|
|
87
|
+
attrs["ai.response.finishReason"] ??
|
|
88
|
+
attrs.providerMetadata?.google?.finishReason ??
|
|
89
|
+
attrs.providerMetadata?.openai?.finishReason ??
|
|
90
|
+
attrs.providerMetadata?.anthropic?.stopReason ??
|
|
91
|
+
"").trim();
|
|
92
|
+
if (candidate)
|
|
93
|
+
finishReason = candidate;
|
|
94
|
+
}
|
|
95
|
+
if (spanType === "tool_call" ||
|
|
96
|
+
spanType === "mcp_tool_call") {
|
|
97
|
+
const toolType = spanType === "mcp_tool_call" ? "mcp_tool_call" : "function_call";
|
|
98
|
+
tools.push({
|
|
99
|
+
name: String(span.entityName ?? span.name ?? "unknown"),
|
|
100
|
+
type: toolType,
|
|
101
|
+
arguments: span.input ?? undefined,
|
|
102
|
+
status: span.errorInfo != null ? "error" : "success",
|
|
103
|
+
...(span.errorInfo && { error: String(span.errorInfo.message) }),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Check for error via errorInfo on any span
|
|
107
|
+
if (span.errorInfo != null) {
|
|
108
|
+
hasError = true;
|
|
109
|
+
if (!errorMessage) {
|
|
110
|
+
errorMessage = String(span.errorInfo.message);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Count model_step span_ended events (multi-step LLM generations).
|
|
115
|
+
for (const e of events) {
|
|
116
|
+
if (e.type === "span_ended" && e.exportedSpan.type === "model_step") {
|
|
117
|
+
stepCount++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Calculate latency from root span using robust time conversion
|
|
121
|
+
const startMs = toMs(rootSpan?.startTime);
|
|
122
|
+
const endMs = toMs(rootSpan?.endTime);
|
|
123
|
+
const latencyMs = (startMs != null && endMs != null) ? endMs - startMs : 0;
|
|
124
|
+
// Get text input/output from root span (direct fields, not attributes)
|
|
125
|
+
const rawInput = rootSpan?.input;
|
|
126
|
+
const rawOutput = rootSpan?.output;
|
|
127
|
+
const textInput = rawInput
|
|
128
|
+
? typeof rawInput === "string"
|
|
129
|
+
? rawInput
|
|
130
|
+
: JSON.stringify(rawInput)
|
|
131
|
+
: undefined;
|
|
132
|
+
const textOutput = rawOutput
|
|
133
|
+
? typeof rawOutput === "string"
|
|
134
|
+
? rawOutput
|
|
135
|
+
: JSON.stringify(rawOutput)
|
|
136
|
+
: undefined;
|
|
137
|
+
// Extract deviceId from root span's requestContext if contextKey is set
|
|
138
|
+
let deviceId;
|
|
139
|
+
const contextKey = options?.contextKey;
|
|
140
|
+
if (contextKey != null && rootEndedEvent) {
|
|
141
|
+
const rc = rootEndedEvent.exportedSpan.requestContext;
|
|
142
|
+
const candidate = rc?.[contextKey];
|
|
143
|
+
if (typeof candidate === "string" && candidate.length > 0) {
|
|
144
|
+
deviceId = candidate;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Extract agent_name from root agent_run span's entityName.
|
|
148
|
+
let agentName;
|
|
149
|
+
if (rootSpan && (rootSpan.type === "agent_run") && typeof rootSpan.entityName === "string" && rootSpan.entityName.length > 0) {
|
|
150
|
+
agentName = rootSpan.entityName;
|
|
151
|
+
}
|
|
152
|
+
// Extract workflow_name from root span's requestContext (mirrors deviceId pattern).
|
|
153
|
+
let workflowName;
|
|
154
|
+
const workflowKey = options?.workflowKey;
|
|
155
|
+
if (workflowKey != null && rootEndedEvent) {
|
|
156
|
+
const rc = rootEndedEvent.exportedSpan.requestContext;
|
|
157
|
+
const candidate = rc?.[workflowKey];
|
|
158
|
+
if (typeof candidate === "string" && candidate.length > 0) {
|
|
159
|
+
workflowName = candidate;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
model: modelName,
|
|
164
|
+
provider: modelProvider,
|
|
165
|
+
usage_input: totalInputTokens,
|
|
166
|
+
usage_output: totalOutputTokens,
|
|
167
|
+
usage_total: totalInputTokens + totalOutputTokens,
|
|
168
|
+
finish_reason: finishReason,
|
|
169
|
+
tools: tools.length > 0 ? tools : undefined,
|
|
170
|
+
text_input: textInput,
|
|
171
|
+
text_output: textOutput,
|
|
172
|
+
latency_total: latencyMs,
|
|
173
|
+
status: hasError ? "error" : "success",
|
|
174
|
+
...(errorMessage && { error: errorMessage }),
|
|
175
|
+
...(deviceId && { deviceId }),
|
|
176
|
+
...(agentName && { agent_name: agentName }),
|
|
177
|
+
...(workflowName && { workflow_name: workflowName }),
|
|
178
|
+
...(stepCount > 0 && { step_count: stepCount }),
|
|
179
|
+
...(rootSpan?.traceId && { trace_id: String(rootSpan.traceId) }),
|
|
180
|
+
...(rootSpan?.id && { span_id: String(rootSpan.id) }),
|
|
181
|
+
...(rootSpan?.parentSpanId && { parent_span_id: String(rootSpan.parentSpanId) }),
|
|
182
|
+
...(responseId && { response_id: responseId }),
|
|
183
|
+
...(responseModel && { response_model: responseModel }),
|
|
184
|
+
...(cacheRead != null && { usage_cache_read: cacheRead }),
|
|
185
|
+
...(cacheWrite != null && { usage_cache_write: cacheWrite }),
|
|
186
|
+
...(reasoningTokens != null && { usage_reasoning: reasoningTokens }),
|
|
187
|
+
...(providerMetadata && Object.keys(providerMetadata).length > 0 && { provider_metadata: providerMetadata }),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=span-aggregator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span-aggregator.js","sourceRoot":"","sources":["../src/span-aggregator.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH;;;GAGG;AACH,SAAS,IAAI,CAAC,CAA+C;IAC3D,IAAI,CAAC,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IAChC,IAAI,CAAC,YAAY,IAAI;QAAE,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;IAC1C,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAA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,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAChF,GAAG,CAAC,UAAU,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;QAC9C,GAAG,CAAC,aAAa,IAAI,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;QACvD,GAAG,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC;QACzD,GAAG,CAAC,UAAU,IAAI,IAAI,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC;QAC5D,GAAG,CAAC,eAAe,IAAI,IAAI,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC;QACpE,GAAG,CAAC,gBAAgB,IAAI,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;KAC7G,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@countly/ai-sdk-mastra",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Countly AI observability adapter for Mastra",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@countly/ai-sdk-core": "0.0.1"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@mastra/core": ">=1.0.0",
|
|
23
|
+
"@mastra/observability": ">=0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependenciesMeta": {
|
|
26
|
+
"@mastra/core": {
|
|
27
|
+
"optional": false
|
|
28
|
+
},
|
|
29
|
+
"@mastra/observability": {
|
|
30
|
+
"optional": false
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"@countly/ai-sdk-tsconfig": "0.0.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc --project tsconfig.build.json",
|
|
39
|
+
"dev": "tsc --project tsconfig.build.json --watch",
|
|
40
|
+
"lint": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run"
|
|
42
|
+
}
|
|
43
|
+
}
|