NOTICE: This package is in alpha state and may be subject to breaking changes.
@sentry/effect supports both Effect v3 and Effect v4 (beta). The integration
auto-detects the installed Effect version at runtime, but the layer composition
APIs differ between the two major versions, so the setup code is slightly
different.
This SDK does not have docs yet. Stay tuned.
import * as Sentry from '@sentry/effect/server';
import { NodeRuntime } from '@effect/platform-node';
import { Layer, Logger } from 'effect';
import { HttpLive } from './Http.js';
const SentryLive = Layer.mergeAll(
Sentry.effectLayer({
dsn: '__DSN__',
tracesSampleRate: 1.0,
}),
Layer.setTracer(Sentry.SentryEffectTracer),
Logger.replace(Logger.defaultLogger, Sentry.SentryEffectLogger),
Sentry.SentryEffectMetricsLayer,
);
const MainLive = HttpLive.pipe(Layer.provide(SentryLive));
MainLive.pipe(Layer.launch, NodeRuntime.runMain);Effect v4 reorganized the Tracer and Logger layer APIs, so the wiring looks
slightly different. The effectLayer, SentryEffectTracer,
SentryEffectLogger, and SentryEffectMetricsLayer exports themselves are the
same.
import * as Sentry from '@sentry/effect/server';
import { NodeHttpServer, NodeRuntime } from '@effect/platform-node';
import * as Layer from 'effect/Layer';
import * as Logger from 'effect/Logger';
import * as Tracer from 'effect/Tracer';
import { HttpRouter } from 'effect/unstable/http';
import { createServer } from 'http';
import { Routes } from './Routes.js';
const SentryLive = Layer.mergeAll(
Sentry.effectLayer({
dsn: '__DSN__',
tracesSampleRate: 1.0,
}),
Layer.succeed(Tracer.Tracer, Sentry.SentryEffectTracer),
Logger.layer([Sentry.SentryEffectLogger]),
Sentry.SentryEffectMetricsLayer,
);
const HttpLive = HttpRouter.serve(Routes).pipe(
Layer.provide(NodeHttpServer.layer(() => createServer(), { port: 3030 })),
Layer.provide(SentryLive),
);
NodeRuntime.runMain(Layer.launch(HttpLive));On Effect v4, Sentry.effectLayer registers a Sentry ErrorReporter. Failures
that pass through Effect.withErrorReporting, ErrorReporter.report or the
built-in HTTP and RPC reporting boundaries are captured automatically. The
ErrorReporter.ignore, ErrorReporter.severity and ErrorReporter.attributes
annotations are respected: ignored errors are skipped, the severity becomes the
event level and the attributes are attached as extra data.
import { Data, Effect, ErrorReporter } from 'effect';
class RateLimitError extends Data.TaggedError('RateLimitError')<{ readonly retryAfter: number }> {
readonly [ErrorReporter.severity] = 'Warn' as const;
readonly [ErrorReporter.attributes] = { retryAfter: this.retryAfter };
}
const program = Effect.fail(new RateLimitError({ retryAfter: 60 })).pipe(Effect.withErrorReporting);Reporters registered with ErrorReporter.layer replace the current set, so add
your own reporters with mergeWithExisting: true or provide them below the
Sentry layer to keep the Sentry reporter:
const SentryLive = Sentry.effectLayer({ dsn: '__DSN__' }).pipe(Layer.provide(ErrorReporter.layer([consoleReporter])));