@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/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 (a Teams activity on another plugin's endpoint, a
390
- * scheduled job).
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 (a Teams activity arriving on
122
- * another plugin's route, a scheduled job) drives `agent.generate` directly, and
123
- * without this stamp every user-scoped tool - `ask_genie` above all - fails with
124
- * "invoke the tool from an agent turn served by the mastra plugin". Those
125
- * callers build a context with {@link createRequestContext} instead of a
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 is what makes a card turn answer with the SAME data a chat turn does: the
189
- * difference between the two endpoints is presentation, not capability.
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 (a channel member, say)
198
- // wins over the ambient identity `stampRequestContextUser` defaulted to.
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 = "user.id";
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 (!(await initializeAppMlflowTraceInfo())) return false;
511
+ if (!appMlflowTraceInfoConfigured()) return false;
512
+ await initializeAppMlflowTraceInfo();
511
513
  await appkitTelemetry.registerNativeSpanProcessor(new AppMlflowTraceInfoSpanProcessor());
512
514
  appMlflowTraceInfoProcessorRegistered = true;
513
515
  return true;