Skip to content

feat(mastra): support Mastra v1 observability + map spans to gen_ai conventions#182

Merged
JayaSurya-27 merged 2 commits into
devfrom
feat/mastra-v1-observability
Jun 3, 2026
Merged

feat(mastra): support Mastra v1 observability + map spans to gen_ai conventions#182
JayaSurya-27 merged 2 commits into
devfrom
feat/mastra-v1-observability

Conversation

@NVJKKartik

@NVJKKartik NVJKKartik commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

@traceai/mastra was broken on Mastra v1 (@mastra/core >= 1.16): v1 removed the telemetry: config key the old FITraceExporter plugged into, so traces silently stopped exporting. This PR adds a v1-native integration.

What's included

  • createFIObservability() / createFIMastraExporter() — wire Future AGI into Mastra's v1 observability API. Bakes in the things that are easy to get wrong:
    • collector host api.futureagi.com (not app.futureagi.com, which is GET-only and 403s)
    • x-api-key / x-secret-key auth from FI_API_KEY / FI_SECRET_KEY
    • project_name / project_type resource attributes (without project_name, the trace is accepted but no project is created)
  • FIMastraSpanExporter — a custom ObservabilityExporter that reuses @mastra/otel-exporter's SpanConverter (Mastra span → OTLP gen_ai.*), then enriches each span with:
    • gen_ai.span.kind mapped from the Mastra span type (AGENT / LLM / TOOL / CHAIN) so spans aren't typed "unknown"
    • input.value / output.value (+ mime) so prompt/response/tool I/O renders in the trace UI
  • Excludes MODEL_CHUNK streaming spans by default.
  • Legacy v0.x FITraceExporter / isFISpan moved to the @traceai/mastra/legacy subpath so v1 users don't pull @traceai/vercel.
  • Unit tests for the enrichment + factory/resolver logic (33 tests).

Screenshot

image

Testing

  • pnpm --filter @traceai/mastra run build — clean
  • pnpm --filter @traceai/mastra run test — 33/33 passing
  • Verified end-to-end against api.futureagi.com: project created, trace + spans render with correct kinds (AGENT/LLM/TOOL/CHAIN) and input/output.

Docs

Companion PR updates the Mastra integration docs in the docs repo.

…onventions

Mastra v1 (>=1.16) removed the `telemetry:` config key that the old FITraceExporter
plugged into, so traces silently stopped exporting. This adds a v1-native path:

- createFIObservability() / createFIMastraExporter(): wire Future AGI into Mastra's
  v1 `observability` API with the correct collector host (api.futureagi.com),
  x-api-key/x-secret-key auth, and project_name/project_type resource attributes
  (without project_name the trace is accepted but no project is created).
- FIMastraSpanExporter: reuses @mastra/otel-exporter's SpanConverter, then enriches
  each span with gen_ai.span.kind (mapped from the Mastra span type) and
  input.value/output.value, so spans render with the right kind (not "unknown")
  and their I/O in Future AGI.
- Excludes MODEL_CHUNK streaming spans by default.
- Legacy v0.x FITraceExporter/isFISpan moved to the `@traceai/mastra/legacy`
  subpath so v1 users don't pull @traceai/vercel.
- Adds unit tests for the enrichment and factory/resolver logic.
Comment thread typescript/packages/traceai_mastra/src/FIObservability.ts
Comment thread typescript/packages/traceai_mastra/package.json
Comment thread typescript/packages/traceai_mastra/src/FIMastraSpanExporter.ts Outdated
@NVJKKartik NVJKKartik requested a review from JayaSurya-27 June 3, 2026 11:48
@JayaSurya-27 JayaSurya-27 merged commit 0456646 into dev Jun 3, 2026
@JayaSurya-27 JayaSurya-27 deleted the feat/mastra-v1-observability branch June 3, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants