Skip to main content
The Effect agent is experimental and under active development. APIs may change between releases.
This guide covers how to add Monocle observability to your Effect application.

Prerequisites

  • Effect 3.21+
  • @effect/opentelemetry 0.63+
  • A Monocle account with an API key (not required for Monocle Studio)

Installation

Peer dependencies: effect >= 3.21.0, @effect/opentelemetry >= 0.63.0

Setup

MonocleLayer returns an Effect Layer that you compose with the rest of your application layers. It configures OTLP exporters for traces, metrics, and logs.
src/main.ts
That’s it. All spans (Effect.withSpan), logs (Effect.log), and metrics are automatically exported to Monocle.

Configuration

When no apiKey is provided (neither in config nor in MONOCLE_API_KEY) and dev mode is off, MonocleLayer returns an empty layer. No telemetry is sent.

Auto-Instrumentations

MonocleLayer handles the OTLP export and exception enrichment, but does not register OpenTelemetry auto-instrumentations (HTTP, PostgreSQL, Redis, etc.). These need to be set up separately. The simplest approach is the @opentelemetry/auto-instrumentations-node meta-package, which patches all supported libraries automatically:
src/register.ts
The import order is critical.This file must be imported before any library it instruments (http, pg, redis, etc.). Import it as the very first line in your entrypoint:
src/main.ts
You can also install individual instrumentations if you prefer to keep dependencies minimal:
src/register.ts

User Context

To associate telemetry data with authenticated users, use Monocle.setUser(). This lets you filter traces and exceptions by user in the dashboard.
The name field takes priority in the Monocle UI, falling back to email, then id. You can also pass custom attributes:
Custom attributes are stored as user.<key> on the span. Monocle.setUser is a no-op when called outside of a span. It will never throw.
Do not include sensitive data (passwords, tokens, API keys) in user attributes. These values are sent to Monocle and will be visible in trace viewers.

Dev Mode (Monocle Studio)

Enable dev: true to send telemetry to Monocle Studio running locally. Dev mode uses faster batch delays (100ms) and points to localhost:4200 by default. No API key required.
See the Monocle Studio docs to get started with local development.