Prerequisites
- Effect 3.21+
@effect/opentelemetry0.63+- A Monocle account with an API key (not required for Monocle Studio)
Installation
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
Effect.withSpan), logs (Effect.log), and metrics are automatically exported to Monocle.
Configuration
| Option | Description | Required |
|---|---|---|
serviceName | Service name for identification in Monocle | Yes |
apiKey | Monocle API key. Falls back to MONOCLE_API_KEY env var | No |
environment | Environment name. Falls back to MONOCLE_ENVIRONMENT, NODE_ENV, then development | No |
serviceVersion | Service version (e.g., git sha, semver). Defaults to 0.0.0 | No |
endpoint | OTLP endpoint URL. Defaults to https://ingest.monocle.sh | No |
dev | Enable dev mode for Monocle Studio (see below) | 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
src/register.ts
Dev Mode (Monocle Studio)
Enabledev: 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.