Skip to content

Commit e8da292

Browse files
committed
fixup! feat(effect): Remove effectLayer auto composition
1 parent cb6091d commit e8da292

3 files changed

Lines changed: 45 additions & 17 deletions

File tree

dev-packages/e2e-tests/test-applications/effect-node/tests/transactions.test.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ test('Sends transaction with manual Effect span', async ({ baseURL }) => {
2828
expect(transactionEvent.transaction).toBe('http.server GET');
2929

3030
const spans = transactionEvent.spans || [];
31-
expect(spans).toContainEqual(
31+
expect(spans).toEqual([
3232
expect.objectContaining({
3333
description: 'test-span',
3434
}),
35-
);
35+
]);
3636
});
3737

3838
test('Sends Effect spans with correct parent-child structure', async ({ baseURL }) => {
@@ -49,23 +49,39 @@ test('Sends Effect spans with correct parent-child structure', async ({ baseURL
4949

5050
expect(transactionEvent.transaction).toBe('http.server GET');
5151

52-
const spans = transactionEvent.spans || [];
53-
54-
expect(spans).toContainEqual(
55-
expect.objectContaining({
56-
description: 'custom-effect-span',
52+
expect(transactionEvent).toEqual(expect.objectContaining({
53+
contexts: expect.objectContaining({
54+
trace: expect.objectContaining({
55+
origin: 'auto.http.effect',
56+
}),
5757
}),
58-
);
59-
60-
expect(spans).toContainEqual(
61-
expect.objectContaining({
62-
description: 'nested-span',
58+
spans: [
59+
expect.objectContaining({
60+
description: 'custom-effect-span',
61+
origin: 'auto.function.effect',
62+
}),
63+
expect.objectContaining({
64+
description: 'nested-span',
65+
origin: 'auto.function.effect',
66+
}),
67+
],
68+
sdk: expect.objectContaining({
69+
name: 'sentry.javascript.effect',
70+
packages: [
71+
expect.objectContaining({
72+
name: 'npm:@sentry/effect',
73+
}),
74+
expect.objectContaining({
75+
name: 'npm:@sentry/node-light',
76+
}),
77+
],
6378
}),
64-
);
79+
}));
80+
81+
const parentSpan = transactionEvent.spans?.[0]?.span_id;
82+
const nestedSpan = transactionEvent.spans?.[1]?.parent_span_id;
6583

66-
const parentSpan = spans.find(s => s.description === 'custom-effect-span');
67-
const nestedSpan = spans.find(s => s.description === 'nested-span');
68-
expect(nestedSpan?.parent_span_id).toBe(parentSpan?.span_id);
84+
expect(nestedSpan).toBe(parentSpan);
6985
});
7086

7187
test('Sends transaction for error route', async ({ baseURL }) => {

packages/effect/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const SentryLive = Layer.mergeAll(
2626
}),
2727
Layer.setTracer(Sentry.SentryEffectTracer),
2828
Logger.replace(Logger.defaultLogger, Sentry.SentryEffectLogger),
29+
Sentry.SentryEffectMetricsLayer,
2930
);
3031

3132
const MainLive = HttpLive.pipe(Layer.provide(SentryLive));

packages/effect/test/layer.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, it } from '@effect/vitest';
2-
import { getClient, getCurrentScope, getIsolationScope, SDK_VERSION } from '@sentry/core';
2+
import * as sentryCore from '@sentry/core';
3+
import { getClient, getCurrentScope, getIsolationScope, SDK_VERSION, SentrySpan } from '@sentry/core';
34
import { Effect, Layer, Logger, LogLevel } from 'effect';
45
import { afterEach, beforeEach, vi } from 'vitest';
56
import * as sentryClient from '../src/index.client';
@@ -41,6 +42,7 @@ describe.each([
4142

4243
afterEach(() => {
4344
getCurrentScope().setClient(undefined);
45+
vi.restoreAllMocks();
4446
});
4547

4648
it('creates a valid Effect layer', () => {
@@ -91,8 +93,11 @@ describe.each([
9193

9294
it.effect('layer enables tracing when tracer is set', () =>
9395
Effect.gen(function* () {
96+
const startInactiveSpanMock = vi.spyOn(sentryCore, 'startInactiveSpan');
97+
9498
const result = yield* Effect.withSpan('test-span')(Effect.succeed('traced'));
9599
expect(result).toBe('traced');
100+
expect(startInactiveSpanMock).toHaveBeenCalledWith(expect.objectContaining({ name: 'test-span' }));
96101
}).pipe(
97102
Effect.withTracer(SentryEffectTracer),
98103
Effect.provide(
@@ -106,11 +111,14 @@ describe.each([
106111

107112
it.effect('layer can be composed with tracer layer', () =>
108113
Effect.gen(function* () {
114+
const startInactiveSpanMock = vi.spyOn(sentryCore, 'startInactiveSpan');
115+
109116
const result = yield* Effect.succeed(42).pipe(
110117
Effect.map(n => n * 2),
111118
Effect.withSpan('computation'),
112119
);
113120
expect(result).toBe(84);
121+
expect(startInactiveSpanMock).toHaveBeenCalledWith(expect.objectContaining({ name: 'computation' }));
114122
}).pipe(
115123
Effect.provide(
116124
Layer.mergeAll(
@@ -145,13 +153,16 @@ describe.each([
145153

146154
it.effect('layer can be composed with all Effect features', () =>
147155
Effect.gen(function* () {
156+
const startInactiveSpanMock = vi.spyOn(sentryCore, 'startInactiveSpan');
157+
148158
yield* Effect.logInfo('starting computation');
149159
const result = yield* Effect.succeed(42).pipe(
150160
Effect.map(n => n * 2),
151161
Effect.withSpan('computation'),
152162
);
153163
yield* Effect.logInfo('computation complete');
154164
expect(result).toBe(84);
165+
expect(startInactiveSpanMock).toHaveBeenCalledWith(expect.objectContaining({ name: 'computation' }));
155166
}).pipe(
156167
Effect.provide(
157168
Layer.mergeAll(

0 commit comments

Comments
 (0)