-
-
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): Only show instrumentation warning when tracing is enabled (#…
…12141) Also gives a better warning in ESM mode with a helpful link to the docs.
- Loading branch information
1 parent
f7bd662
commit a30fbbc
Showing
7 changed files
with
44 additions
and
64 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
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/.`, | ||
); | ||
} | ||
}); | ||
} | ||
} |