-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): Add
disableInstrumentationWarnings
option (#13693)
Closes #13471 This can be used when you know what you're doing to avoid the warning log.
- Loading branch information
Showing
3 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { ensureIsWrapped } from '../../src/utils/ensureIsWrapped'; | ||
import { cleanupOtel, mockSdkInit, resetGlobals } from '../helpers/mockSdkInit'; | ||
|
||
const unwrappedFunction = () => {}; | ||
|
||
// We simulate a wrapped function | ||
const wrappedfunction = Object.assign(() => {}, { | ||
__wrapped: true, | ||
__original: () => {}, | ||
__unwrap: () => {}, | ||
}); | ||
|
||
describe('ensureIsWrapped', () => { | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
cleanupOtel(); | ||
resetGlobals(); | ||
}); | ||
|
||
it('warns when the method is unwrapped', () => { | ||
const spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
||
mockSdkInit({ tracesSampleRate: 1 }); | ||
|
||
ensureIsWrapped(unwrappedFunction, 'express'); | ||
|
||
expect(spyWarn).toHaveBeenCalledTimes(1); | ||
expect(spyWarn).toHaveBeenCalledWith( | ||
'[Sentry] express is not instrumented. This is likely because you required/imported express before calling `Sentry.init()`.', | ||
); | ||
}); | ||
|
||
it('does not warn when the method is wrapped', () => { | ||
const spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
||
mockSdkInit({ tracesSampleRate: 1 }); | ||
|
||
ensureIsWrapped(wrappedfunction, 'express'); | ||
|
||
expect(spyWarn).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('does not warn without a client', () => { | ||
const spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
resetGlobals(); | ||
|
||
ensureIsWrapped(wrappedfunction, 'express'); | ||
|
||
expect(spyWarn).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('does not warn without tracing', () => { | ||
const spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
||
mockSdkInit({}); | ||
|
||
ensureIsWrapped(unwrappedFunction, 'express'); | ||
|
||
expect(spyWarn).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('does not warn if disableInstrumentationWarnings=true', () => { | ||
const spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
||
mockSdkInit({ tracesSampleRate: 1, disableInstrumentationWarnings: true }); | ||
|
||
ensureIsWrapped(unwrappedFunction, 'express'); | ||
|
||
expect(spyWarn).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |