@dbx-tools/appkit-mastra 0.9.144 → 0.9.145
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 +17 -6
- package/index.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/src/chat.js +4 -1
- package/lib/src/config.d.ts +3 -2
- package/lib/src/config.js +1 -1
- package/lib/src/identity.d.ts +8 -7
- package/lib/src/identity.js +9 -8
- package/lib/src/mlflow.d.ts +5 -0
- package/lib/src/mlflow.js +49 -3
- package/lib/src/plugin.d.ts +2 -2
- package/lib/src/plugin.js +8 -3
- package/lib/src/server.d.ts +7 -8
- package/lib/src/server.js +12 -11
- package/lib/src/telemetry.js +5 -4
- package/package.json +16 -16
- package/src/chat.ts +3 -0
- package/src/config.ts +3 -2
- package/src/identity.ts +8 -7
- package/src/mlflow.ts +48 -3
- package/src/plugin.ts +7 -2
- package/src/server.ts +11 -10
- package/src/telemetry.ts +4 -2
package/src/plugin.ts
CHANGED
|
@@ -278,6 +278,11 @@ export class MastraPlugin extends Plugin<MastraPluginConfig> {
|
|
|
278
278
|
});
|
|
279
279
|
this.config.feedbackMode = this.resolvedFeedbackMode;
|
|
280
280
|
if (this.config.observability !== false) {
|
|
281
|
+
await appkitTelemetry.configureNativeHttpTelemetry({
|
|
282
|
+
// A low-level request without an active semantic span becomes a noisy
|
|
283
|
+
// standalone trace. Requests inside an agent/tool span remain visible.
|
|
284
|
+
outgoingFilter: appkitTelemetry.excludeUnparentedOutgoingHttpTelemetry,
|
|
285
|
+
});
|
|
281
286
|
await registerAppMlflowTraceInfoProcessor();
|
|
282
287
|
}
|
|
283
288
|
// Wait until sibling plugins (e.g. `lakebase`) finish `setup()` so
|
|
@@ -386,8 +391,8 @@ export class MastraPlugin extends Plugin<MastraPluginConfig> {
|
|
|
386
391
|
getMastra: () => this.mastra,
|
|
387
392
|
/**
|
|
388
393
|
* Build the `RequestContext` an agent turn driven from OUTSIDE this
|
|
389
|
-
* plugin's routes needs
|
|
390
|
-
*
|
|
394
|
+
* plugin's routes needs, such as another plugin's endpoint or a scheduled
|
|
395
|
+
* job.
|
|
391
396
|
*
|
|
392
397
|
* Mastra's user-scoped tools - `ask_genie` most visibly - read the AppKit
|
|
393
398
|
* user off the request context, which only the HTTP middleware stamps.
|
package/src/server.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
FOLLOW_UP_USER_TEXT_KEY,
|
|
36
36
|
} from "./follow-up-suggestions.ts";
|
|
37
37
|
import { requestUserEmail, requestUserId } from "./identity.ts";
|
|
38
|
+
import { initializeRequestMlflowTraceInfo } from "./mlflow.ts";
|
|
38
39
|
import { MASTRA_ORIGIN_KEY } from "./request-context.ts";
|
|
39
40
|
import {
|
|
40
41
|
extractModelOverride,
|
|
@@ -118,12 +119,11 @@ export interface AttributedIdentity {
|
|
|
118
119
|
* `requestContext`.
|
|
119
120
|
*
|
|
120
121
|
* Split out of {@link MastraServer} because the HTTP middleware is not the only
|
|
121
|
-
* caller that needs it: an out-of-band turn
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* request.
|
|
122
|
+
* caller that needs it: an out-of-band turn from another plugin route or a
|
|
123
|
+
* scheduled job drives `agent.generate` directly, and without this stamp every
|
|
124
|
+
* user-scoped tool - `ask_genie` above all - fails with "invoke the tool from an
|
|
125
|
+
* agent turn served by the mastra plugin". Those callers build a context with
|
|
126
|
+
* {@link createRequestContext} instead of a request.
|
|
127
127
|
*
|
|
128
128
|
* The Databricks credential always comes from the ambient execution context;
|
|
129
129
|
* `attributed` only changes WHO the turn is attributed to when that context is
|
|
@@ -138,6 +138,7 @@ export async function stampRequestContextUser(
|
|
|
138
138
|
): Promise<void> {
|
|
139
139
|
if ([MASTRA_USER_KEY, MASTRA_RESOURCE_ID_KEY].every((key) => requestContext.get(key))) return;
|
|
140
140
|
const executionContext = getExecutionContext();
|
|
141
|
+
await initializeRequestMlflowTraceInfo(executionContext.client);
|
|
141
142
|
const isUserContext = "isUserContext" in executionContext;
|
|
142
143
|
// The Databricks CREDENTIAL is always the ambient execution context's client
|
|
143
144
|
// (OBO in a user context, the service principal otherwise). WHO the turn is
|
|
@@ -185,8 +186,8 @@ export async function stampRequestContextUser(
|
|
|
185
186
|
* a request id so the turn's spans join up in traces. The result is passed as
|
|
186
187
|
* `requestContext` to `agent.generate` / `agent.stream`.
|
|
187
188
|
*
|
|
188
|
-
* This
|
|
189
|
-
*
|
|
189
|
+
* This gives an out-of-band turn the same data and tool capability as a chat
|
|
190
|
+
* turn.
|
|
190
191
|
*/
|
|
191
192
|
export async function createRequestContext(
|
|
192
193
|
options: { threadId?: string; resourceId?: string; requestId?: string } = {},
|
|
@@ -194,8 +195,8 @@ export async function createRequestContext(
|
|
|
194
195
|
const requestContext = new RequestContext();
|
|
195
196
|
await stampRequestContextUser(requestContext);
|
|
196
197
|
if (options.threadId) requestContext.set(MASTRA_THREAD_ID_KEY, options.threadId);
|
|
197
|
-
// Stamped AFTER the user so an explicit resource id
|
|
198
|
-
//
|
|
198
|
+
// Stamped AFTER the user so an explicit resource id wins over the ambient
|
|
199
|
+
// identity `stampRequestContextUser` defaulted to.
|
|
199
200
|
if (options.resourceId) requestContext.set(MASTRA_RESOURCE_ID_KEY, options.resourceId);
|
|
200
201
|
requestContext.set(MASTRA_REQUEST_ID_KEY, options.requestId ?? hash.id());
|
|
201
202
|
return requestContext;
|
package/src/telemetry.ts
CHANGED
|
@@ -42,6 +42,7 @@ import type express from "express";
|
|
|
42
42
|
import { MASTRA_AUTH_MODE_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_NAME_KEY } from "./config.ts";
|
|
43
43
|
import { USER_EMAIL_HEADER, USER_ID_HEADER } from "./identity.ts";
|
|
44
44
|
import {
|
|
45
|
+
appMlflowTraceInfoConfigured,
|
|
45
46
|
directMlflowTracingActive,
|
|
46
47
|
initializeAppMlflowTraceInfo,
|
|
47
48
|
persistAppMlflowTraceInfo,
|
|
@@ -118,7 +119,7 @@ export const GEN_AI_OPERATION_NAME_ATTR = "gen_ai.operation.name";
|
|
|
118
119
|
* Root-span user id the MLflow experiment UI's User column reads from OTel
|
|
119
120
|
* traces. Prefer the forwarded email when present so the column is human.
|
|
120
121
|
*/
|
|
121
|
-
export const MLFLOW_USER_ATTR =
|
|
122
|
+
export const MLFLOW_USER_ATTR = appkitTelemetry.USER_TRACE_ATTRIBUTE;
|
|
122
123
|
/** Root-span session id that enables the MLflow Sessions tab. */
|
|
123
124
|
export const MLFLOW_SESSION_ATTR = "session.id";
|
|
124
125
|
/** Root-span type for a Mastra agent turn. */
|
|
@@ -507,7 +508,8 @@ let appMlflowTraceInfoProcessorRegistered = false;
|
|
|
507
508
|
/** Register trace enrichment before AppKit constructs its native provider. */
|
|
508
509
|
export async function registerAppMlflowTraceInfoProcessor(): Promise<boolean> {
|
|
509
510
|
if (appMlflowTraceInfoProcessorRegistered) return true;
|
|
510
|
-
if (!(
|
|
511
|
+
if (!appMlflowTraceInfoConfigured()) return false;
|
|
512
|
+
await initializeAppMlflowTraceInfo();
|
|
511
513
|
await appkitTelemetry.registerNativeSpanProcessor(new AppMlflowTraceInfoSpanProcessor());
|
|
512
514
|
appMlflowTraceInfoProcessorRegistered = true;
|
|
513
515
|
return true;
|