src/telemetry
Copy each Mastra chat turn’s request/response onto its OTel root span so Databricks-managed MLflow can display them.
Why this exists: MLflow’s UC <target>_trace_unified view picks the
one span whose parent_span_id is empty and reads request/response
from mlflow.spanInputs / mlflow.spanOutputs (or the gen_ai.*
equivalents) on THAT span only. Mastra records the turn on its
invoke_agent child under mastra.agent_run.input / .output, keys
the view never reads, so chat traces arrive with both columns null
even when the spans themselves look healthy.
AppKit’s HTTP instrumentation records the server span in OTel RPC metadata, which remains available even when Express makes a middleware-layer child active. When instrumentation is unavailable, this module creates one request-lifetime server span and runs Mastra under it.
Interfaces
Section titled “Interfaces”Type Aliases
Section titled “Type Aliases”Variables
Section titled “Variables”- CHAT_GENIE_USED_ATTR
- CHAT_IDENTITY_ATTR
- CHAT_MESSAGES_ATTR
- CHAT_RESPONSE_ATTR
- GEN_AI_OPERATION_NAME_ATTR
- MLFLOW_SESSION_ATTR
- MLFLOW_SPAN_INPUTS_ATTR
- MLFLOW_SPAN_OUTPUTS_ATTR
- MLFLOW_SPAN_TYPE_AGENT
- MLFLOW_SPAN_TYPE_ATTR
- MLFLOW_SPAN_TYPE_GENIE
- MLFLOW_USER_ATTR
- TRACE_IO_LIMIT
Functions
Section titled “Functions”- assistantTextFromJson
- assistantTextFromSse
- attachChatTurnTelemetry
- chatTurnTelemetryMiddleware
- recordActiveTraceAuth
- recordActiveTraceModel
- recordActiveTraceTag
- recordActiveTraceTags
- recordActiveTraceUser
- stampGenieToolSpan
- textOnlyChatInput
References
Section titled “References”APPKIT_AGENT_TRACE_ROOT_ATTR
Section titled “APPKIT_AGENT_TRACE_ROOT_ATTR”Re-exports APPKIT_AGENT_TRACE_ROOT_ATTR
MLFLOW_AGENT_TAG
Section titled “MLFLOW_AGENT_TAG”Re-exports MLFLOW_AGENT_TAG
MLFLOW_AGENT_TAG_ATTR
Section titled “MLFLOW_AGENT_TAG_ATTR”Re-exports MLFLOW_AGENT_TAG_ATTR
MLFLOW_GENIE_TAG
Section titled “MLFLOW_GENIE_TAG”Re-exports MLFLOW_GENIE_TAG
MLFLOW_GENIE_TAG_ATTR
Section titled “MLFLOW_GENIE_TAG_ATTR”Re-exports MLFLOW_GENIE_TAG_ATTR
MLFLOW_LOCAL_TAG
Section titled “MLFLOW_LOCAL_TAG”Re-exports MLFLOW_LOCAL_TAG
MLFLOW_LOCAL_TAG_ATTR
Section titled “MLFLOW_LOCAL_TAG_ATTR”Re-exports MLFLOW_LOCAL_TAG_ATTR
MLFLOW_OBO_AUTH_TAG
Section titled “MLFLOW_OBO_AUTH_TAG”Re-exports MLFLOW_OBO_AUTH_TAG
MLFLOW_OBO_AUTH_TAG_ATTR
Section titled “MLFLOW_OBO_AUTH_TAG_ATTR”Re-exports MLFLOW_OBO_AUTH_TAG_ATTR
MLFLOW_SP_AUTH_TAG
Section titled “MLFLOW_SP_AUTH_TAG”Re-exports MLFLOW_SP_AUTH_TAG
MLFLOW_SP_AUTH_TAG_ATTR
Section titled “MLFLOW_SP_AUTH_TAG_ATTR”Re-exports MLFLOW_SP_AUTH_TAG_ATTR
MLFLOW_TRACE_TAG_PREFIX
Section titled “MLFLOW_TRACE_TAG_PREFIX”Re-exports MLFLOW_TRACE_TAG_PREFIX