Skip to content

Mastra

Export OpenTelemetry GenAI spans from Mastra to Coralogix for full visibility into agent runs, model generations, and tool calls. The @mastra/coralogix exporter integrates with Mastra's observability layer and supports both simple agent workflows and nested multi-agent architectures.

What you need

  • Node.js 22.13.0 or newer.
  • A Coralogix API key.
  • A Mastra application.

Installation

pnpm add @mastra/coralogix
# or
npm install @mastra/coralogix

Configuration

Configure the exporter using environment variables or pass options directly to CoralogixExporter.

Environment variables

VariableRequiredDescription
CX_TOKENYesYour Coralogix API key
CX_ENDPOINTYesSelect the ingress.:443 endpoint that corresponds to your Coralogix domain using the domain selector at the top of the page.
CX_APPLICATION_NAMENoApplication name (defaults to Unknown)
CX_SUBSYSTEM_NAMENoSubsystem name (defaults to Unknown)

Constructor options

Pass configuration directly to CoralogixExporter:

import { CoralogixExporter } from '@mastra/coralogix';

const exporter = new CoralogixExporter({
  token: process.env.CX_TOKEN,
  endpoint: process.env.CX_ENDPOINT,
  applicationName: 'ai-application',
  subsystemName: 'ai-subsystem',
  debug: false,
});

Usage

The exporter supports two integration modes depending on your agent architecture.

Exporter mode

Use exporter mode for simple, single-agent workflows. Pass the exporter to Mastra's Observability class:

import { Mastra } from '@mastra/core';
import { CoralogixExporter } from '@mastra/coralogix';

const exporter = new CoralogixExporter({
  token: process.env.CX_TOKEN,
  endpoint: process.env.CX_ENDPOINT,
  applicationName: 'ai-application',
  subsystemName: 'ai-subsystem',
});

const mastra = new Mastra({
  observability: {
    exporters: [exporter],
  },
});

Bridge mode

Use bridge mode for nested agent calls where multiple agents coordinate. The bridge automatically propagates OpenTelemetry trace context through executeInContext() calls, so all agent activity is collected under a single unified trace.

import { CoralogixExporter } from '@mastra/coralogix';

const exporter = new CoralogixExporter({
  token: process.env.CX_TOKEN,
  endpoint: process.env.CX_ENDPOINT,
});

// Pass exporter as an ObservabilityBridge in your Mastra setup

Span structure

Each agent execution produces a flat span structure exported to Coralogix:

  • Agent run span — One per agent invocation. Root of the trace. Aggregates model name, provider, and token usage from descendant model generation spans.
  • Model generation spans — One per LLM call. Includes model name, provider, temperature, and token usage. Appears as a sibling under the root agent run span.
  • Tool call spans — One per tool invocation. Includes tool name, arguments, result, and success status.

Internal workflow spans are excluded by default. All exported spans are flattened as siblings under the root agent run span and ordered chronologically.

GenAI attributes

AttributeTypeDescription
gen_ai.operation.namestringOperation type: agent_run, model_generation, or tool_call
gen_ai.agent.namestringName of the agent
gen_ai.agent.instructionsstringInstructions passed to the agent
gen_ai.agent.toolsstringTools available to the agent
gen_ai.request.modelstringModel requested by the agent
gen_ai.provider.namestringLLM provider name
gen_ai.request.temperaturefloatTemperature parameter
gen_ai.usage.input_tokensintTokens consumed by the prompt
gen_ai.usage.output_tokensintTokens generated in the response
gen_ai.promptstringPrompt sent to the model
gen_ai.completionstringModel response
tool.namestringName of the invoked tool
tool.argumentsstringArguments passed to the tool
tool.resultstringResult returned by the tool
tool.successbooleanWhether the tool call succeeded