npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@respan/instrumentation-mastra

v0.3.0

Published

Respan instrumentation plugin for Mastra observability

Readme

@respan/instrumentation-mastra

Connect Mastra's native observability events to the active OpenTelemetry provider and Respan tracing pipeline. Agent, model, tool, workflow, and RAG spans retain their native parent relationships. The adapter leaves Mastra results, streams, callbacks, and errors under Mastra's control.

Requires Node.js 22.13 or later, @mastra/core >=1.36.0, and @mastra/observability >=1.13.0. Tested with those exact minimum releases and with core 1.75.0 / observability 1.18.4.

import { Agent } from "@mastra/core/agent";
import { Mastra } from "@mastra/core/mastra";
import { createMockModel } from "@mastra/core/test-utils/llm-mock";
import { Observability, SamplingStrategyType } from "@mastra/observability";
import { InMemorySpanExporter } from "@opentelemetry/sdk-trace-base";
import { RespanTelemetry } from "@respan/tracing";
import { MastraInstrumentor } from "@respan/instrumentation-mastra";

const instrumentor = new MastraInstrumentor();
const telemetry = new RespanTelemetry({
  apiKey: "local-example",
  exporter: new InMemorySpanExporter(),
  disableBatch: true,
});
await telemetry.initialize();

const agent = new Agent({
  id: "assistant",
  name: "Assistant",
  instructions: "Be helpful.",
  model: createMockModel({ mockText: "Hello from Mastra" }),
});
const mastra = new Mastra({
  agents: { agent },
  observability: new Observability({
    configs: {
      default: {
        serviceName: "mastra-app",
        sampling: { type: SamplingStrategyType.ALWAYS },
        exporters: [instrumentor],
      },
    },
  }),
});

try {
  const result = await telemetry.withWorkflow(
    { name: "mastra_assistant" },
    () => mastra.getAgent("agent").generate("Hello"),
  );
  console.log(result.text);
} finally {
  await mastra.shutdown();
  await telemetry.shutdown();
}

This sample uses Mastra's released deterministic model and keeps spans in memory. To export to Respan, supply your Respan API key to RespanTelemetry and omit the in-memory exporter. The same exporter can be passed in Observability.configs.*.exporters when using the Respan facade.

new MastraInstrumentor({ traceContent: false }) omits inputs, outputs, tool definitions, metadata, and error messages. The adapter also honors RESPAN_TRACE_CONTENT=false, TRACELOOP_TRACE_CONTENT=false, the upstream content context, tracing suppression, and observed ancestor content vetoes. A denied decision cannot be re-enabled later. A RECORD_ONLY or DROP sampling decision prevents payload conversion. Actual recording spans remain guarded against payload changes made by late processors or while queued for export. Provider sampling runs before payload conversion.

excludeSpanTypes adds native span types to the default model_chunk exclusion. Descendants of excluded spans attach to the closest included parent. activate() enables future native spans; deactivate() and shutdown() close inflight spans without copying their pending content. flush() leaves active spans open; flush the tracing runtime to export completed spans. An ended-only event replay cannot create a span without an observed start event.

Complete native input and output envelopes are JSON encoded, including multimodal parts, structured results, tool history, scalar values, and embedding vectors when Mastra includes them. Model tool schemas come from native attributes.tools; older native events exposing only availableTools retain names only. Token totals and HTTP status are emitted only when actually supplied. Mastra can redact, filter, or truncate data before exporter events: its default serializer bounds arrays to 50 items and depth to 8. Configure Mastra's serializationOptions when larger native payloads are needed. The adapter cannot restore data already removed upstream. Ambient OpenTelemetry context supplies external parent relationships. Mastra exporter events do not carry remote OpenTelemetry trace flags, so an external parent ID without ambient context is retained in metadata rather than assigned an invented sampling flag.

Sessions

When you set no session id, the agent's memory thread id (memory: { thread }, which Mastra reports as the agent run's threadId) is sent as the run's Respan session id (respan.sessions.session_identifier), so every turn of one conversation lands in one session with no Respan-specific code.

A session, thread or trace group you set yourself always wins:

import { propagateAttributes } from "@respan/respan";

await propagateAttributes({ session_identifier: "my-session" }, () =>
  agent.generate("Hello", { memory: { thread, resource } }), // runs here keep "my-session"
);

An empty id or one longer than 255 characters is not sent; Respan then detects the session on the server. Unchanged: a threadId or thread_identifier in Mastra's request context is still sent as the thread id, and counts as yours, so it also wins.

RespanMastraExporter remains an alias of MastraInstrumentor.