-
-
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.
ref(node): Extract framework wrapping warning into utility function
- Loading branch information
1 parent
40f399c
commit e123f24
Showing
6 changed files
with
42 additions
and
112 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
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,28 @@ | ||
import { isWrapped } from '@opentelemetry/core'; | ||
import { hasTracingEnabled, isEnabled } from '@sentry/core'; | ||
import { consoleSandbox } from '@sentry/utils'; | ||
import { isCjs } from '../sdk/init'; | ||
|
||
/** | ||
* Checks and warns if a framework isn't wrapped by opentelemetry. | ||
*/ | ||
export function ensureIsWrapped( | ||
maybeWrappedModule: unknown, | ||
name: 'express' | 'connect' | 'fastify' | 'hapi' | 'koa', | ||
): void { | ||
if (!isWrapped(maybeWrappedModule) && isEnabled() && hasTracingEnabled()) { | ||
consoleSandbox(() => { | ||
if (isCjs()) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`[Sentry] ${name} is not instrumented. This is likely because you required/imported ${name} before calling \`Sentry.init()\`.`, | ||
); | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`[Sentry] ${name} is not instrumented. Please make sure to initialize Sentry in a separate file that you \`--import\` when running node, see: https://docs.sentry.io/platforms/javascript/guides/${name}/install/esm/.`, | ||
); | ||
} | ||
}); | ||
} | ||
} |