UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

40 lines (36 loc) 1.42 kB
import { isWrapped } from '@opentelemetry/core'; import { getClient, isEnabled, hasSpansEnabled, consoleSandbox, getGlobalScope } from '@sentry/core'; import { isCjs } from './commonjs.js'; import { createMissingInstrumentationContext } from './createMissingInstrumentationContext.js'; /** * Checks and warns if a framework isn't wrapped by opentelemetry. */ function ensureIsWrapped( maybeWrappedFunction, name, ) { const clientOptions = getClient()?.getOptions(); if ( !clientOptions?.disableInstrumentationWarnings && !isWrapped(maybeWrappedFunction) && isEnabled() && hasSpansEnabled(clientOptions) ) { 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/.`, ); } }); getGlobalScope().setContext('missing_instrumentation', createMissingInstrumentationContext(name)); } } export { ensureIsWrapped }; //# sourceMappingURL=ensureIsWrapped.js.map