|
| 1 | +--- |
| 2 | +title: Effect |
| 3 | +sdk: sentry.javascript.effect |
| 4 | +description: Learn how to set up Sentry in your Effect application with first-class integration for tracing, logging, and metrics. |
| 5 | +--- |
| 6 | + |
| 7 | +<Alert> |
| 8 | + |
| 9 | +This SDK is currently in **ALPHA**. Alpha features are still in progress, may have bugs, and might include breaking changes. |
| 10 | +Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have any feedback or concerns. |
| 11 | + |
| 12 | +</Alert> |
| 13 | + |
| 14 | +This guide will show you how to integrate Sentry into your [Effect](https://effect.website/) project using the `@sentry/effect` SDK. |
| 15 | + |
| 16 | +<PlatformContent includePath="getting-started-prerequisites" /> |
| 17 | + |
| 18 | +## Step 1: Install |
| 19 | + |
| 20 | +Choose the features you want to configure, and this guide will show you how: |
| 21 | + |
| 22 | +<OnboardingOptionButtons |
| 23 | + options={[ |
| 24 | + "error-monitoring", |
| 25 | + "performance", |
| 26 | + "logs", |
| 27 | + "metrics", |
| 28 | + ]} |
| 29 | +/> |
| 30 | + |
| 31 | +<PlatformContent includePath="getting-started-features-expandable" /> |
| 32 | + |
| 33 | +### Install the Sentry SDK |
| 34 | + |
| 35 | +```bash {tabTitle:npm} |
| 36 | +npm install @sentry/effect --save |
| 37 | +``` |
| 38 | + |
| 39 | +```bash {tabTitle:yarn} |
| 40 | +yarn add @sentry/effect |
| 41 | +``` |
| 42 | + |
| 43 | +```bash {tabTitle:pnpm} |
| 44 | +pnpm add @sentry/effect |
| 45 | +``` |
| 46 | + |
| 47 | +## Step 2: Configure |
| 48 | + |
| 49 | +The SDK provides an `effectLayer` that initializes Sentry. You can compose it with additional Effect layers to enable tracing, logging, and metrics. |
| 50 | + |
| 51 | +### Server Usage |
| 52 | + |
| 53 | +```typescript {filename:main.ts} |
| 54 | +import * as Sentry from "@sentry/effect/server"; |
| 55 | +import { NodeRuntime } from "@effect/platform-node"; |
| 56 | +// ___PRODUCT_OPTION_START___ logs |
| 57 | +import * as Logger from "effect/Logger"; |
| 58 | +// ___PRODUCT_OPTION_END___ logs |
| 59 | +import * as Layer from "effect/Layer"; |
| 60 | +import { HttpLive } from "./Http.js"; |
| 61 | + |
| 62 | +const SentryLive = Layer.mergeAll( |
| 63 | + Sentry.effectLayer({ |
| 64 | + dsn: "___PUBLIC_DSN___", |
| 65 | + // ___PRODUCT_OPTION_START___ performance |
| 66 | + |
| 67 | + // Set tracesSampleRate to 1.0 to capture 100% |
| 68 | + // of transactions for tracing. |
| 69 | + // We recommend adjusting this value in production. |
| 70 | + tracesSampleRate: 1.0, |
| 71 | + // ___PRODUCT_OPTION_END___ performance |
| 72 | + // ___PRODUCT_OPTION_START___ logs |
| 73 | + |
| 74 | + // Enable logs to be sent to Sentry |
| 75 | + enableLogs: true, |
| 76 | + // ___PRODUCT_OPTION_END___ logs |
| 77 | + }), |
| 78 | + // ___PRODUCT_OPTION_START___ performance |
| 79 | + |
| 80 | + // Enable Effect tracing |
| 81 | + Layer.setTracer(Sentry.SentryEffectTracer), |
| 82 | + // ___PRODUCT_OPTION_END___ performance |
| 83 | + // ___PRODUCT_OPTION_START___ logs |
| 84 | + |
| 85 | + // Forward Effect logs to Sentry |
| 86 | + Logger.replace(Logger.defaultLogger, Sentry.SentryEffectLogger), |
| 87 | + // ___PRODUCT_OPTION_END___ logs |
| 88 | + // ___PRODUCT_OPTION_START___ metrics |
| 89 | + |
| 90 | + // Forward Effect metrics to Sentry |
| 91 | + Sentry.SentryEffectMetricsLayer, |
| 92 | + // ___PRODUCT_OPTION_END___ metrics |
| 93 | +); |
| 94 | + |
| 95 | +const MainLive = HttpLive.pipe(Layer.provide(SentryLive)); |
| 96 | + |
| 97 | +MainLive.pipe(Layer.launch, NodeRuntime.runMain); |
| 98 | +``` |
| 99 | + |
| 100 | +### Client Usage |
| 101 | + |
| 102 | +```typescript {filename:main.ts} |
| 103 | +import * as Sentry from "@sentry/effect/client"; |
| 104 | +// ___PRODUCT_OPTION_START___ logs |
| 105 | +import { Logger } from "effect"; |
| 106 | +// ___PRODUCT_OPTION_END___ logs |
| 107 | +import { Layer } from "effect"; |
| 108 | + |
| 109 | +const SentryLive = Layer.mergeAll( |
| 110 | + Sentry.effectLayer({ |
| 111 | + dsn: "___PUBLIC_DSN___", |
| 112 | + // ___PRODUCT_OPTION_START___ performance |
| 113 | + |
| 114 | + // Set tracesSampleRate to 1.0 to capture 100% |
| 115 | + // of transactions for tracing. |
| 116 | + // We recommend adjusting this value in production. |
| 117 | + tracesSampleRate: 1.0, |
| 118 | + integrations: [Sentry.browserTracingIntegration()], |
| 119 | + // ___PRODUCT_OPTION_END___ performance |
| 120 | + // ___PRODUCT_OPTION_START___ logs |
| 121 | + |
| 122 | + // Enable logs to be sent to Sentry |
| 123 | + enableLogs: true, |
| 124 | + // ___PRODUCT_OPTION_END___ logs |
| 125 | + }), |
| 126 | + // ___PRODUCT_OPTION_START___ performance |
| 127 | + |
| 128 | + // Enable Effect tracing |
| 129 | + Layer.setTracer(Sentry.SentryEffectTracer), |
| 130 | + // ___PRODUCT_OPTION_END___ performance |
| 131 | + // ___PRODUCT_OPTION_START___ logs |
| 132 | + |
| 133 | + // Forward Effect logs to Sentry |
| 134 | + Logger.replace(Logger.defaultLogger, Sentry.SentryEffectLogger), |
| 135 | + // ___PRODUCT_OPTION_END___ logs |
| 136 | +); |
| 137 | + |
| 138 | +const MainLive = YourAppLayer.pipe(Layer.provide(SentryLive)); |
| 139 | +``` |
| 140 | + |
| 141 | +## Features |
| 142 | + |
| 143 | +The SDK provides composable layers for Effect integration: |
| 144 | + |
| 145 | +<OnboardingOption optionId="performance"> |
| 146 | +- **Tracing** via `Sentry.SentryEffectTracer`: Effect spans are automatically traced as Sentry spans with distributed tracing support |
| 147 | +</OnboardingOption> |
| 148 | +<OnboardingOption optionId="logs"> |
| 149 | +- **Logging** via `Sentry.SentryEffectLogger`: Effect logs are forwarded to Sentry (requires `enableLogs: true`) |
| 150 | +</OnboardingOption> |
| 151 | +<OnboardingOption optionId="metrics"> |
| 152 | +- **Metrics** via `Sentry.SentryEffectMetricsLayer`: Effect metrics (counters, gauges, histograms) are sent to Sentry |
| 153 | +</OnboardingOption> |
| 154 | + |
| 155 | +## Step 3: Verify |
| 156 | + |
| 157 | +Add a test error to verify your setup: |
| 158 | + |
| 159 | +```typescript |
| 160 | +import { Effect } from "effect"; |
| 161 | +import * as Sentry from "@sentry/effect/server"; |
| 162 | + |
| 163 | +const program = Effect.gen(function* () { |
| 164 | + yield* Effect.fail(new Error("Sentry Test Error")); |
| 165 | +}); |
| 166 | + |
| 167 | +// Run with your layer that includes Sentry.effectLayer |
| 168 | +``` |
| 169 | + |
| 170 | +Head over to your project on [Sentry.io](https://sentry.io) to view the collected data. |
| 171 | + |
| 172 | +## Next Steps |
| 173 | + |
| 174 | +- Learn how to [manually capture errors](/platforms/javascript/guides/effect/usage/) |
| 175 | +- Continue to [customize your configuration](/platforms/javascript/guides/effect/configuration/) |
| 176 | +- Get familiar with [Sentry's product features](/product/) like tracing, insights, and alerts |
| 177 | + |
| 178 | +<Expandable permalink={false} title="Are you having problems setting up the SDK?"> |
| 179 | + |
| 180 | +- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink> |
| 181 | +- [Get support](https://sentry.zendesk.com/hc/en-us/) |
| 182 | + |
| 183 | +</Expandable> |
0 commit comments