-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathapp.ts
More file actions
108 lines (94 loc) · 3.34 KB
/
app.ts
File metadata and controls
108 lines (94 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import * as Sentry from '@sentry/effect';
import { HttpRouter, HttpServer, HttpServerResponse } from '@effect/platform';
import { NodeHttpServer, NodeRuntime } from '@effect/platform-node';
import * as Effect from 'effect/Effect';
import * as Cause from 'effect/Cause';
import * as Layer from 'effect/Layer';
import * as Logger from 'effect/Logger';
import * as LogLevel from 'effect/LogLevel';
import { createServer } from 'http';
const SentryLive = Layer.mergeAll(
Sentry.effectLayer({
dsn: process.env.E2E_TEST_DSN,
environment: 'qa',
debug: !!process.env.DEBUG,
tunnel: 'http://localhost:3031/',
tracesSampleRate: 1,
enableLogs: true,
}),
Layer.setTracer(Sentry.SentryEffectTracer),
Logger.replace(Logger.defaultLogger, Sentry.SentryEffectLogger),
);
const router = HttpRouter.empty.pipe(
HttpRouter.get('/test-success', HttpServerResponse.json({ version: 'v1' })),
HttpRouter.get(
'/test-transaction',
Effect.gen(function* () {
yield* Effect.void.pipe(Effect.withSpan('test-span'));
return yield* HttpServerResponse.json({ status: 'ok' });
}),
),
HttpRouter.get(
'/test-effect-span',
Effect.gen(function* () {
yield* Effect.gen(function* () {
yield* Effect.sleep('50 millis');
yield* Effect.sleep('25 millis').pipe(Effect.withSpan('nested-span'));
}).pipe(Effect.withSpan('custom-effect-span', { kind: 'internal' }));
return yield* HttpServerResponse.json({ status: 'ok' });
}),
),
HttpRouter.get(
'/test-error',
Effect.gen(function* () {
const exceptionId = Sentry.captureException(new Error('This is an error'));
yield* Effect.promise(() => Sentry.flush(2000));
return yield* HttpServerResponse.json({ exceptionId });
}),
),
HttpRouter.get(
'/test-exception/:id',
Effect.sync(() => {
throw new Error('This is an exception with id 123');
}),
),
HttpRouter.get('/test-effect-fail', Effect.fail(new Error('Effect failure'))),
HttpRouter.get('/test-effect-die', Effect.die('Effect defect')),
HttpRouter.get(
'/test-log',
Effect.gen(function* () {
yield* Effect.logDebug('Debug log from Effect');
yield* Effect.logInfo('Info log from Effect');
yield* Effect.logWarning('Warning log from Effect');
yield* Effect.logError('Error log from Effect');
return yield* HttpServerResponse.json({ message: 'Logs sent' });
}),
),
HttpRouter.get(
'/test-log-with-context',
Effect.gen(function* () {
yield* Effect.logInfo('Log with context').pipe(
Effect.annotateLogs('userId', '12345'),
Effect.annotateLogs('action', 'test'),
);
return yield* HttpServerResponse.json({ message: 'Log with context sent' });
}),
),
HttpRouter.catchAllCause(cause => {
const error = Cause.squash(cause);
Sentry.captureException(error);
return Effect.gen(function* () {
yield* Effect.promise(() => Sentry.flush(2000));
return yield* HttpServerResponse.json({ error: String(error) }, { status: 500 });
});
}),
);
const LogLevelLive = Logger.minimumLogLevel(LogLevel.Debug);
const ServerLive = router.pipe(
HttpServer.serve(),
HttpServer.withLogAddress,
Layer.provide(NodeHttpServer.layer(createServer, { port: 3030 })),
Layer.provide(SentryLive),
Layer.provide(LogLevelLive),
);
ServerLive.pipe(Layer.launch, NodeRuntime.runMain);