|
1 | 1 | import type { Integration } from '@sentry/types';
|
| 2 | +import { logger } from '@sentry/utils'; |
2 | 3 |
|
| 4 | +import * as SentryOpentelemetry from '@sentry/opentelemetry'; |
3 | 5 | import { getClient, getIsolationScope } from '../../src/';
|
4 | 6 | import * as auto from '../../src/integrations/tracing';
|
5 |
| -import { init } from '../../src/sdk'; |
| 7 | +import { init, validateOpenTelemetrySetup } from '../../src/sdk'; |
6 | 8 | import { NodeClient } from '../../src/sdk/client';
|
7 | 9 | import { cleanupOtel } from '../helpers/mockSdkInit';
|
8 | 10 |
|
@@ -193,3 +195,65 @@ describe('init()', () => {
|
193 | 195 | });
|
194 | 196 | });
|
195 | 197 | });
|
| 198 | + |
| 199 | +describe('validateOpenTelemetrySetup', () => { |
| 200 | + afterEach(() => { |
| 201 | + global.__SENTRY__ = {}; |
| 202 | + cleanupOtel(); |
| 203 | + jest.clearAllMocks(); |
| 204 | + }); |
| 205 | + |
| 206 | + it('works with correct setup', () => { |
| 207 | + const errorSpy = jest.spyOn(logger, 'error').mockImplementation(() => {}); |
| 208 | + const warnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 209 | + |
| 210 | + jest.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { |
| 211 | + return ['SentryContextManager', 'SentryPropagator', 'SentrySampler']; |
| 212 | + }); |
| 213 | + |
| 214 | + validateOpenTelemetrySetup(); |
| 215 | + |
| 216 | + expect(errorSpy).toHaveBeenCalledTimes(0); |
| 217 | + expect(warnSpy).toHaveBeenCalledTimes(0); |
| 218 | + }); |
| 219 | + |
| 220 | + it('works with missing setup, without tracing', () => { |
| 221 | + const errorSpy = jest.spyOn(logger, 'error').mockImplementation(() => {}); |
| 222 | + const warnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 223 | + |
| 224 | + jest.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { |
| 225 | + return []; |
| 226 | + }); |
| 227 | + |
| 228 | + validateOpenTelemetrySetup(); |
| 229 | + |
| 230 | + // Without tracing, this is expected only twice |
| 231 | + expect(errorSpy).toHaveBeenCalledTimes(2); |
| 232 | + expect(warnSpy).toHaveBeenCalledTimes(1); |
| 233 | + |
| 234 | + expect(errorSpy).toBeCalledWith(expect.stringContaining('You have to set up the SentryContextManager.')); |
| 235 | + expect(errorSpy).toBeCalledWith(expect.stringContaining('You have to set up the SentryPropagator.')); |
| 236 | + expect(warnSpy).toBeCalledWith(expect.stringContaining('You have to set up the SentrySampler.')); |
| 237 | + }); |
| 238 | + |
| 239 | + it('works with missing setup, with tracing', () => { |
| 240 | + const errorSpy = jest.spyOn(logger, 'error').mockImplementation(() => {}); |
| 241 | + const warnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 242 | + |
| 243 | + jest.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { |
| 244 | + return []; |
| 245 | + }); |
| 246 | + |
| 247 | + init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true, tracesSampleRate: 1 }); |
| 248 | + |
| 249 | + validateOpenTelemetrySetup(); |
| 250 | + |
| 251 | + expect(errorSpy).toHaveBeenCalledTimes(3); |
| 252 | + expect(warnSpy).toHaveBeenCalledTimes(1); |
| 253 | + |
| 254 | + expect(errorSpy).toBeCalledWith(expect.stringContaining('You have to set up the SentryContextManager.')); |
| 255 | + expect(errorSpy).toBeCalledWith(expect.stringContaining('You have to set up the SentryPropagator.')); |
| 256 | + expect(errorSpy).toBeCalledWith(expect.stringContaining('You have to set up the SentrySpanProcessor.')); |
| 257 | + expect(warnSpy).toBeCalledWith(expect.stringContaining('You have to set up the SentrySampler.')); |
| 258 | + }); |
| 259 | +}); |
0 commit comments