Effect
Learn how to set up and configure Sentry in your Effect application, capture your first errors, and view them in Sentry.
Important
This SDK is currently in ALPHA. Alpha features are still in progress, may have bugs, and might include breaking changes. Please reach out on GitHub if you have any feedback or concerns.
This guide will show you how to integrate Sentry into your Effect project using the @sentry/effect SDK.
@sentry/effect supports Effect v3 and Effect v4. The integration automatically detects which version you have installed, but the Tracer and Logger layer APIs differ between major versions. Make sure to follow the correct code snippets for your version below.
You need:
Choose the features you want to configure, and this guide will show you how:
Run the command for your preferred package manager to add the Sentry SDK to your application.
npm install @sentry/effect --save
The SDK provides an effectLayer that initializes Sentry. You can compose it with additional Effect layers to enable tracing, logging, and metrics. The effectLayer, SentryEffectTracer, SentryEffectLogger, and SentryEffectMetricsLayer exports are the same for Effect v3 and v4. The only difference between versions is how you compose layers for tracing and logging, which is covered in the snippets below.
Available since: v10.44.0
- Node: Provide
SentryLivebefore launching your HTTP layer (for example, withNodeRuntime). - Browser: Provide
SentryLiveto your app layer.
In both cases, use Layer.setTracer to configure tracing and Logger.replace to configure logging.
main.tsimport * as Sentry from "@sentry/effect";
import { NodeRuntime } from "@effect/platform-node";
// ___PRODUCT_OPTION_START___ logs
import * as Logger from "effect/Logger";
// ___PRODUCT_OPTION_END___ logs
import * as Layer from "effect/Layer";
import { HttpLive } from "./Http.js";
const SentryLive = Layer.mergeAll(
Sentry.effectLayer({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production.
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
enableLogs: true,
// ___PRODUCT_OPTION_END___ logs
}),
// ___PRODUCT_OPTION_START___ performance
// Enable Effect tracing
Layer.setTracer(Sentry.SentryEffectTracer),
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ logs
// Forward Effect logs to Sentry
Logger.replace(Logger.defaultLogger, Sentry.SentryEffectLogger),
// ___PRODUCT_OPTION_END___ logs
// ___PRODUCT_OPTION_START___ metrics
// Forward Effect metrics to Sentry
Sentry.SentryEffectMetricsLayer,
// ___PRODUCT_OPTION_END___ metrics
);
const MainLive = HttpLive.pipe(Layer.provide(SentryLive));
MainLive.pipe(Layer.launch, NodeRuntime.runMain);
Available since: v10.50.0
Effect v4 changes how you install the default Tracer and Logger services. Use Layer.succeed(Tracer.Tracer, …) plus Logger.layer([…]).
main.tsimport * as Sentry from "@sentry/effect";
import { NodeRuntime } from "@effect/platform-node";
// ___PRODUCT_OPTION_START___ logs
import * as Logger from "effect/Logger";
// ___PRODUCT_OPTION_END___ logs
import * as Layer from "effect/Layer";
// ___PRODUCT_OPTION_START___ performance
import * as Tracer from "effect/Tracer";
// ___PRODUCT_OPTION_END___ performance
import { HttpLive } from "./Http.js";
const SentryLive = Layer.mergeAll(
Sentry.effectLayer({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production.
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
enableLogs: true,
// ___PRODUCT_OPTION_END___ logs
}),
// ___PRODUCT_OPTION_START___ performance
// Enable Effect tracing
Layer.succeed(Tracer.Tracer, Sentry.SentryEffectTracer),
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ logs
// Forward Effect logs to Sentry
Logger.layer([Sentry.SentryEffectLogger]),
// ___PRODUCT_OPTION_END___ logs
// ___PRODUCT_OPTION_START___ metrics
// Forward Effect metrics to Sentry
Sentry.SentryEffectMetricsLayer,
// ___PRODUCT_OPTION_END___ metrics
);
const MainLive = HttpLive.pipe(Layer.provide(SentryLive));
MainLive.pipe(Layer.launch, NodeRuntime.runMain);
The stack traces in your Sentry errors probably won't look like your actual code without unminifying them. To fix this, upload your source maps to Sentry. The easiest way to do this is by using the Sentry Wizard.
Alternatively, take a look at our Uploading Source Maps documentation.
npx @sentry/wizard@latest -i sourcemaps
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
To verify that Sentry captures errors and creates issues in your Sentry project, add a test error:
import { Effect } from "effect";
import * as Sentry from "@sentry/effect";
const program = Effect.gen(function* () {
yield* Effect.fail(new Error("Sentry Test Error"));
});
// Run with your layer that includes Sentry.effectLayer
To test your tracing configuration, update the previous code snippet to create a custom span:
import { Effect } from "effect";
import * as Sentry from "@sentry/effect";
const program = Effect.gen(function* () {
yield* Effect.gen(function* () {
// Simulate some work
yield* Effect.sleep("100 millis");
yield* Effect.fail(new Error("Sentry Test Error"));
}).pipe(
Effect.withSpan("My First Test Transaction", {
attributes: { op: "test" },
}),
);
});
To verify that Sentry catches your logs, add some log statements to your application:
import { Effect } from "effect";
import * as Sentry from "@sentry/effect";
const program = Effect.gen(function* () {
yield* Effect.log("User example action completed");
yield* Effect.logWarning("Slow operation detected").pipe(
Effect.annotateLogs({
operation: "data_fetch",
duration: "3500ms",
}),
);
yield* Effect.logError("Validation failed").pipe(
Effect.annotateLogs({
field: "email",
reason: "Invalid email",
}),
);
});
Now, head over to your project on Sentry.io to view the collected data (it takes a couple of moments for the data to appear).
- Explore practical guides on what to monitor, log, track, and investigate after setup
- Learn how to manually capture errors
- Continue to customize your configuration
- Get familiar with Sentry's product features like tracing, insights, and alerts
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").