|
1 | 1 | import type { Integration } from '@sentry/types';
|
2 | 2 |
|
3 |
| -import { getClient } from '../../src/'; |
| 3 | +import { getClient, getIsolationScope } from '../../src/'; |
4 | 4 | import * as auto from '../../src/integrations/tracing';
|
5 | 5 | import { init } from '../../src/sdk';
|
6 | 6 | import { NodeClient } from '../../src/sdk/client';
|
@@ -34,112 +34,153 @@ describe('init()', () => {
|
34 | 34 | jest.clearAllMocks();
|
35 | 35 | });
|
36 | 36 |
|
37 |
| - it("doesn't install default integrations if told not to", () => { |
38 |
| - init({ dsn: PUBLIC_DSN, defaultIntegrations: false }); |
| 37 | + describe('integrations', () => { |
| 38 | + it("doesn't install default integrations if told not to", () => { |
| 39 | + init({ dsn: PUBLIC_DSN, defaultIntegrations: false }); |
39 | 40 |
|
40 |
| - const client = getClient(); |
| 41 | + const client = getClient(); |
41 | 42 |
|
42 |
| - expect(client?.getOptions()).toEqual( |
43 |
| - expect.objectContaining({ |
44 |
| - integrations: [], |
45 |
| - }), |
46 |
| - ); |
| 43 | + expect(client?.getOptions()).toEqual( |
| 44 | + expect.objectContaining({ |
| 45 | + integrations: [], |
| 46 | + }), |
| 47 | + ); |
47 | 48 |
|
48 |
| - expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); |
49 |
| - }); |
| 49 | + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); |
| 50 | + }); |
50 | 51 |
|
51 |
| - it('installs merged default integrations, with overrides provided through options', () => { |
52 |
| - const mockDefaultIntegrations = [ |
53 |
| - new MockIntegration('Some mock integration 2.1'), |
54 |
| - new MockIntegration('Some mock integration 2.2'), |
55 |
| - ]; |
| 52 | + it('installs merged default integrations, with overrides provided through options', () => { |
| 53 | + const mockDefaultIntegrations = [ |
| 54 | + new MockIntegration('Some mock integration 2.1'), |
| 55 | + new MockIntegration('Some mock integration 2.2'), |
| 56 | + ]; |
56 | 57 |
|
57 |
| - const mockIntegrations = [ |
58 |
| - new MockIntegration('Some mock integration 2.1'), |
59 |
| - new MockIntegration('Some mock integration 2.3'), |
60 |
| - ]; |
| 58 | + const mockIntegrations = [ |
| 59 | + new MockIntegration('Some mock integration 2.1'), |
| 60 | + new MockIntegration('Some mock integration 2.3'), |
| 61 | + ]; |
61 | 62 |
|
62 |
| - init({ dsn: PUBLIC_DSN, integrations: mockIntegrations, defaultIntegrations: mockDefaultIntegrations }); |
| 63 | + init({ dsn: PUBLIC_DSN, integrations: mockIntegrations, defaultIntegrations: mockDefaultIntegrations }); |
63 | 64 |
|
64 |
| - expect(mockDefaultIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(0); |
65 |
| - expect(mockDefaultIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
66 |
| - expect(mockIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
67 |
| - expect(mockIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
68 |
| - expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); |
69 |
| - }); |
| 65 | + expect(mockDefaultIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(0); |
| 66 | + expect(mockDefaultIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
| 67 | + expect(mockIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
| 68 | + expect(mockIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
| 69 | + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); |
| 70 | + }); |
70 | 71 |
|
71 |
| - it('installs integrations returned from a callback function', () => { |
72 |
| - const mockDefaultIntegrations = [ |
73 |
| - new MockIntegration('Some mock integration 3.1'), |
74 |
| - new MockIntegration('Some mock integration 3.2'), |
75 |
| - ]; |
76 |
| - |
77 |
| - const newIntegration = new MockIntegration('Some mock integration 3.3'); |
78 |
| - |
79 |
| - init({ |
80 |
| - dsn: PUBLIC_DSN, |
81 |
| - defaultIntegrations: mockDefaultIntegrations, |
82 |
| - integrations: integrations => { |
83 |
| - const newIntegrations = [...integrations]; |
84 |
| - newIntegrations[1] = newIntegration; |
85 |
| - return newIntegrations; |
86 |
| - }, |
| 72 | + it('installs integrations returned from a callback function', () => { |
| 73 | + const mockDefaultIntegrations = [ |
| 74 | + new MockIntegration('Some mock integration 3.1'), |
| 75 | + new MockIntegration('Some mock integration 3.2'), |
| 76 | + ]; |
| 77 | + |
| 78 | + const newIntegration = new MockIntegration('Some mock integration 3.3'); |
| 79 | + |
| 80 | + init({ |
| 81 | + dsn: PUBLIC_DSN, |
| 82 | + defaultIntegrations: mockDefaultIntegrations, |
| 83 | + integrations: integrations => { |
| 84 | + const newIntegrations = [...integrations]; |
| 85 | + newIntegrations[1] = newIntegration; |
| 86 | + return newIntegrations; |
| 87 | + }, |
| 88 | + }); |
| 89 | + |
| 90 | + expect(mockDefaultIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
| 91 | + expect(mockDefaultIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(0); |
| 92 | + expect(newIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
| 93 | + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); |
87 | 94 | });
|
88 | 95 |
|
89 |
| - expect(mockDefaultIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
90 |
| - expect(mockDefaultIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(0); |
91 |
| - expect(newIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
92 |
| - expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); |
| 96 | + it('installs performance default instrumentations if tracing is enabled', () => { |
| 97 | + const autoPerformanceIntegration = new MockIntegration('Some mock integration 4.4'); |
| 98 | + |
| 99 | + mockAutoPerformanceIntegrations.mockReset().mockImplementation(() => [autoPerformanceIntegration]); |
| 100 | + |
| 101 | + const mockIntegrations = [ |
| 102 | + new MockIntegration('Some mock integration 4.1'), |
| 103 | + new MockIntegration('Some mock integration 4.3'), |
| 104 | + ]; |
| 105 | + |
| 106 | + init({ |
| 107 | + dsn: PUBLIC_DSN, |
| 108 | + integrations: mockIntegrations, |
| 109 | + enableTracing: true, |
| 110 | + }); |
| 111 | + |
| 112 | + expect(mockIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
| 113 | + expect(mockIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
| 114 | + expect(autoPerformanceIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
| 115 | + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(1); |
| 116 | + |
| 117 | + const client = getClient(); |
| 118 | + expect(client?.getOptions()).toEqual( |
| 119 | + expect.objectContaining({ |
| 120 | + integrations: expect.arrayContaining([mockIntegrations[0], mockIntegrations[1], autoPerformanceIntegration]), |
| 121 | + }), |
| 122 | + ); |
| 123 | + }); |
93 | 124 | });
|
94 | 125 |
|
95 |
| - it('installs performance default instrumentations if tracing is enabled', () => { |
96 |
| - const autoPerformanceIntegration = new MockIntegration('Some mock integration 4.4'); |
| 126 | + describe('OpenTelemetry', () => { |
| 127 | + it('sets up OpenTelemetry by default', () => { |
| 128 | + init({ dsn: PUBLIC_DSN }); |
| 129 | + |
| 130 | + const client = getClient<NodeClient>(); |
97 | 131 |
|
98 |
| - mockAutoPerformanceIntegrations.mockReset().mockImplementation(() => [autoPerformanceIntegration]); |
| 132 | + expect(client?.traceProvider).toBeDefined(); |
| 133 | + }); |
99 | 134 |
|
100 |
| - const mockIntegrations = [ |
101 |
| - new MockIntegration('Some mock integration 4.1'), |
102 |
| - new MockIntegration('Some mock integration 4.3'), |
103 |
| - ]; |
| 135 | + it('allows to opt-out of OpenTelemetry setup', () => { |
| 136 | + init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true }); |
104 | 137 |
|
105 |
| - init({ |
106 |
| - dsn: PUBLIC_DSN, |
107 |
| - integrations: mockIntegrations, |
108 |
| - enableTracing: true, |
| 138 | + const client = getClient<NodeClient>(); |
| 139 | + |
| 140 | + expect(client?.traceProvider).not.toBeDefined(); |
109 | 141 | });
|
| 142 | + }); |
| 143 | + |
| 144 | + it('returns intiated client', () => { |
| 145 | + const client = init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true }); |
110 | 146 |
|
111 |
| - expect(mockIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
112 |
| - expect(mockIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
113 |
| - expect(autoPerformanceIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); |
114 |
| - expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(1); |
115 |
| - |
116 |
| - const client = getClient(); |
117 |
| - expect(client?.getOptions()).toEqual( |
118 |
| - expect.objectContaining({ |
119 |
| - integrations: expect.arrayContaining([mockIntegrations[0], mockIntegrations[1], autoPerformanceIntegration]), |
120 |
| - }), |
121 |
| - ); |
| 147 | + expect(client).toBeInstanceOf(NodeClient); |
122 | 148 | });
|
123 | 149 |
|
124 |
| - it('sets up OpenTelemetry by default', () => { |
125 |
| - init({ dsn: PUBLIC_DSN }); |
| 150 | + describe('autoSessionTracking', () => { |
| 151 | + it('does not track session by default if no release is set', () => { |
| 152 | + init({ dsn: PUBLIC_DSN }); |
126 | 153 |
|
127 |
| - const client = getClient<NodeClient>(); |
| 154 | + const session = getIsolationScope().getSession(); |
| 155 | + expect(session).toBeUndefined(); |
| 156 | + }); |
128 | 157 |
|
129 |
| - expect(client?.traceProvider).toBeDefined(); |
130 |
| - }); |
| 158 | + it('tracks session by default if release is set', () => { |
| 159 | + init({ dsn: PUBLIC_DSN, release: '1.2.3' }); |
131 | 160 |
|
132 |
| - it('allows to opt-out of OpenTelemetry setup', () => { |
133 |
| - init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true }); |
| 161 | + const session = getIsolationScope().getSession(); |
| 162 | + expect(session).toBeDefined(); |
| 163 | + }); |
134 | 164 |
|
135 |
| - const client = getClient<NodeClient>(); |
| 165 | + it('does not track session if no release is set even if autoSessionTracking=true', () => { |
| 166 | + init({ dsn: PUBLIC_DSN, autoSessionTracking: true }); |
136 | 167 |
|
137 |
| - expect(client?.traceProvider).not.toBeDefined(); |
138 |
| - }); |
| 168 | + const session = getIsolationScope().getSession(); |
| 169 | + expect(session).toBeUndefined(); |
| 170 | + }); |
139 | 171 |
|
140 |
| - it('returns intiated client', () => { |
141 |
| - const client = init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true }); |
| 172 | + it('does not track session if autoSessionTracking=false', () => { |
| 173 | + init({ dsn: PUBLIC_DSN, autoSessionTracking: false, release: '1.2.3' }); |
142 | 174 |
|
143 |
| - expect(client).toBeInstanceOf(NodeClient); |
| 175 | + const session = getIsolationScope().getSession(); |
| 176 | + expect(session).toBeUndefined(); |
| 177 | + }); |
| 178 | + |
| 179 | + it('tracks session by default if autoSessionTracking=true & release is set', () => { |
| 180 | + init({ dsn: PUBLIC_DSN, release: '1.2.3', autoSessionTracking: true }); |
| 181 | + |
| 182 | + const session = getIsolationScope().getSession(); |
| 183 | + expect(session).toBeDefined(); |
| 184 | + }); |
144 | 185 | });
|
145 | 186 | });
|
0 commit comments