Skip to content

Commit 0f2390f

Browse files
committed
feat(effect): add applySdkMetadata
1 parent 8d8a6b9 commit 0f2390f

7 files changed

Lines changed: 77 additions & 11 deletions

File tree

packages/effect/src/client/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { BrowserOptions } from '@sentry/browser';
2-
import * as Sentry from '@sentry/browser';
32
import type * as EffectLayer from 'effect/Layer';
43
import { suspend as suspendLayer } from 'effect/Layer';
54
import { buildEffectLayer } from '../utils/buildEffectLayer';
5+
import { init } from './sdk';
6+
7+
export { init } from './sdk';
68

79
/**
810
* Options for the Sentry Effect client layer.
@@ -32,5 +34,5 @@ export type EffectClientLayerOptions = BrowserOptions;
3234
* ```
3335
*/
3436
export function effectLayer(options: EffectClientLayerOptions): EffectLayer.Layer<never, never, never> {
35-
return suspendLayer(() => buildEffectLayer(options, Sentry.init(options)));
37+
return suspendLayer(() => buildEffectLayer(options, init(options)));
3638
}

packages/effect/src/client/sdk.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { BrowserOptions } from '@sentry/browser';
2+
import { init as initBrowser } from '@sentry/browser';
3+
import type { Client } from '@sentry/core';
4+
import { applySdkMetadata } from '@sentry/core';
5+
6+
/**
7+
* Initializes the Sentry Effect SDK for browser clients.
8+
*
9+
* @param options - Configuration options for the SDK
10+
* @returns The initialized Sentry client, or undefined if initialization failed
11+
*/
12+
export function init(options: BrowserOptions): Client | undefined {
13+
const opts = {
14+
...options,
15+
};
16+
17+
applySdkMetadata(opts, 'effect', ['effect', 'browser']);
18+
19+
return initBrowser(opts);
20+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// import/export got a false positive, and affects most of our index barrel files
2+
// can be removed once following issue is fixed: https://github.com/import-js/eslint-plugin-import/issues/703
3+
/* eslint-disable import/export */
14
export * from '@sentry/browser';
25

3-
export { effectLayer } from './client/index';
6+
export { effectLayer, init } from './client/index';
47
export type { EffectClientLayerOptions } from './client/index';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from '@sentry/node-core/light';
22

3-
export { effectLayer } from './server/index';
3+
export { effectLayer, init } from './server/index';
44
export type { EffectServerLayerOptions } from './server/index';

packages/effect/src/server/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import type { NodeOptions } from '@sentry/node-core';
2-
import * as Sentry from '@sentry/node-core/light';
1+
import type { NodeOptions } from '@sentry/node-core/light';
32
import type * as EffectLayer from 'effect/Layer';
43
import { buildEffectLayer } from '../utils/buildEffectLayer';
4+
import { init } from './sdk';
5+
6+
export { init } from './sdk';
57

68
/**
79
* Options for the Sentry Effect server layer.
@@ -33,5 +35,5 @@ export type EffectServerLayerOptions = NodeOptions;
3335
* ```
3436
*/
3537
export function effectLayer(options: EffectServerLayerOptions): EffectLayer.Layer<never, never, never> {
36-
return buildEffectLayer(options, Sentry.init(options));
38+
return buildEffectLayer(options, init(options));
3739
}

packages/effect/src/server/sdk.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Client } from '@sentry/core';
2+
import { applySdkMetadata } from '@sentry/core';
3+
import type { NodeOptions } from '@sentry/node-core/light';
4+
import { init as initNode } from '@sentry/node-core/light';
5+
6+
/**
7+
* Initializes the Sentry Effect SDK for Node.js servers.
8+
*
9+
* @param options - Configuration options for the SDK
10+
* @returns The initialized Sentry client, or undefined if initialization failed
11+
*/
12+
export function init(options: NodeOptions): Client | undefined {
13+
const opts = {
14+
...options,
15+
};
16+
17+
applySdkMetadata(opts, 'effect', ['effect', 'node-light']);
18+
19+
return initNode(opts);
20+
}

packages/effect/test/layer.test.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from '@effect/vitest';
2-
import { getCurrentScope, getIsolationScope } from '@sentry/core';
2+
import { getClient, getCurrentScope, getIsolationScope, SDK_VERSION } from '@sentry/core';
33
import { Effect, Layer } from 'effect';
44
import { afterEach, beforeEach, vi } from 'vitest';
55
import * as sentryClient from '../src/index.client';
@@ -15,9 +15,9 @@ function getMockTransport() {
1515
}
1616

1717
describe.each([
18-
['client', sentryClient.effectLayer],
19-
['server', sentryServer.effectLayer],
20-
])('effectLayer ($name)', (name, effectLayer) => {
18+
[{ subSdkName: 'browser', effectLayer: sentryClient.effectLayer }],
19+
[{ subSdkName: 'node-light', effectLayer: sentryServer.effectLayer }],
20+
])('effectLayer ($subSdkName)', ({ subSdkName, effectLayer }) => {
2121
beforeEach(() => {
2222
getCurrentScope().clear();
2323
getIsolationScope().clear();
@@ -37,6 +37,25 @@ describe.each([
3737
expect(Layer.isLayer(layer)).toBe(true);
3838
});
3939

40+
it.effect('applies SDK metadata', () =>
41+
Effect.gen(function* () {
42+
yield* Effect.void;
43+
44+
const client = getClient();
45+
const metadata = client?.getOptions()._metadata?.sdk;
46+
47+
expect(metadata?.name).toBe('sentry.javascript.effect');
48+
expect(metadata?.packages).toEqual([{ name: 'npm:@sentry/effect', version: SDK_VERSION }, { name: `npm:@sentry/${subSdkName}`, version: SDK_VERSION }]);
49+
}).pipe(
50+
Effect.provide(
51+
effectLayer({
52+
dsn: TEST_DSN,
53+
transport: getMockTransport(),
54+
}),
55+
),
56+
),
57+
);
58+
4059
it.effect('layer can be provided to an Effect program', () =>
4160
Effect.gen(function* () {
4261
const result = yield* Effect.succeed('test-result');

0 commit comments

Comments
 (0)