Skip to content

Commit 6455f93

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

3 files changed

Lines changed: 45 additions & 15 deletions

File tree

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

Lines changed: 32 additions & 14 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,41 @@ 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(
52+
expect(transactionEvent).toEqual(
5553
expect.objectContaining({
56-
description: 'custom-effect-span',
54+
contexts: expect.objectContaining({
55+
trace: expect.objectContaining({
56+
origin: 'auto.http.effect',
57+
}),
58+
}),
59+
spans: [
60+
expect.objectContaining({
61+
description: 'custom-effect-span',
62+
origin: 'auto.function.effect',
63+
}),
64+
expect.objectContaining({
65+
description: 'nested-span',
66+
origin: 'auto.function.effect',
67+
}),
68+
],
69+
sdk: expect.objectContaining({
70+
name: 'sentry.javascript.effect',
71+
packages: [
72+
expect.objectContaining({
73+
name: 'npm:@sentry/effect',
74+
}),
75+
expect.objectContaining({
76+
name: 'npm:@sentry/node-light',
77+
}),
78+
],
79+
}),
5780
}),
5881
);
5982

60-
expect(spans).toContainEqual(
61-
expect.objectContaining({
62-
description: 'nested-span',
63-
}),
64-
);
83+
const parentSpan = transactionEvent.spans?.[0]?.span_id;
84+
const nestedSpan = transactionEvent.spans?.[1]?.parent_span_id;
6585

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);
86+
expect(nestedSpan).toBe(parentSpan);
6987
});
7088

7189
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)