diff --git a/dev-packages/e2e-tests/lib/getTestMatrix.ts b/dev-packages/e2e-tests/lib/getTestMatrix.ts index 342f20cf9820..e29f5c13043f 100644 --- a/dev-packages/e2e-tests/lib/getTestMatrix.ts +++ b/dev-packages/e2e-tests/lib/getTestMatrix.ts @@ -101,7 +101,7 @@ function addIncludesForTestApp( } function getSentryDependencies(appName: string): string[] { - const packageJson = getPackageJson(appName) || {}; + const packageJson = getPackageJson(appName); const dependencies = { ...packageJson.devDependencies, diff --git a/packages/browser/test/sdk.test.ts b/packages/browser/test/sdk.test.ts index e00974ab0f5d..7cb69541086b 100644 --- a/packages/browser/test/sdk.test.ts +++ b/packages/browser/test/sdk.test.ts @@ -89,7 +89,7 @@ describe('init', () => { expect(initAndBindSpy).toHaveBeenCalledTimes(1); const optionsPassed = initAndBindSpy.mock.calls[0]?.[1]; - expect(optionsPassed?.integrations?.length).toBeGreaterThan(0); + expect(optionsPassed?.integrations.length).toBeGreaterThan(0); }); test("doesn't install default integrations if told not to", () => { diff --git a/packages/core/src/utils-hoist/vercelWaitUntil.ts b/packages/core/src/utils-hoist/vercelWaitUntil.ts index 280130b766b7..5a5d15268ee9 100644 --- a/packages/core/src/utils-hoist/vercelWaitUntil.ts +++ b/packages/core/src/utils-hoist/vercelWaitUntil.ts @@ -1,9 +1,11 @@ import { GLOBAL_OBJ } from './worldwide'; interface VercelRequestContextGlobal { - get?(): { - waitUntil?: (task: Promise) => void; - }; + get?(): + | { + waitUntil?: (task: Promise) => void; + } + | undefined; } /** diff --git a/packages/core/src/utils/applyScopeDataToEvent.ts b/packages/core/src/utils/applyScopeDataToEvent.ts index fccca13f87b9..22bf7b06e503 100644 --- a/packages/core/src/utils/applyScopeDataToEvent.ts +++ b/packages/core/src/utils/applyScopeDataToEvent.ts @@ -113,22 +113,22 @@ function applyDataToEvent(event: Event, data: ScopeData): void { const { extra, tags, user, contexts, level, transactionName } = data; const cleanedExtra = dropUndefinedKeys(extra); - if (cleanedExtra && Object.keys(cleanedExtra).length) { + if (Object.keys(cleanedExtra).length) { event.extra = { ...cleanedExtra, ...event.extra }; } const cleanedTags = dropUndefinedKeys(tags); - if (cleanedTags && Object.keys(cleanedTags).length) { + if (Object.keys(cleanedTags).length) { event.tags = { ...cleanedTags, ...event.tags }; } const cleanedUser = dropUndefinedKeys(user); - if (cleanedUser && Object.keys(cleanedUser).length) { + if (Object.keys(cleanedUser).length) { event.user = { ...cleanedUser, ...event.user }; } const cleanedContexts = dropUndefinedKeys(contexts); - if (cleanedContexts && Object.keys(cleanedContexts).length) { + if (Object.keys(cleanedContexts).length) { event.contexts = { ...cleanedContexts, ...event.contexts }; } @@ -190,7 +190,7 @@ function applyFingerprintToEvent(event: Event, fingerprint: ScopeData['fingerpri } // If we have no data at all, remove empty array default - if (event.fingerprint && !event.fingerprint.length) { + if (!event.fingerprint.length) { delete event.fingerprint; } } diff --git a/packages/core/src/utils/merge.ts b/packages/core/src/utils/merge.ts index d80520b45cf6..25c386021adc 100644 --- a/packages/core/src/utils/merge.ts +++ b/packages/core/src/utils/merge.ts @@ -13,7 +13,7 @@ export function merge(initialObj: T, mergeObj: T, levels = 2): T { } // If the merge object is an empty object, and the initial object is not undefined, we return the initial object - if (initialObj && mergeObj && Object.keys(mergeObj).length === 0) { + if (initialObj && Object.keys(mergeObj).length === 0) { return initialObj; } diff --git a/packages/core/src/utils/prepareEvent.ts b/packages/core/src/utils/prepareEvent.ts index e896a401be20..d38676f40550 100644 --- a/packages/core/src/utils/prepareEvent.ts +++ b/packages/core/src/utils/prepareEvent.ts @@ -179,7 +179,7 @@ export function applyDebugIds(event: Event, stackParser: StackParser): void { event!.exception!.values!.forEach(exception => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion exception.stacktrace!.frames!.forEach(frame => { - if (filenameDebugIdMap && frame.filename) { + if (frame.filename) { frame.debug_id = filenameDebugIdMap[frame.filename]; } }); diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index 594a297f9395..38ecf724b060 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -151,7 +151,7 @@ export function spanToJSON(span: Span): Partial { } function spanIsOpenTelemetrySdkTraceBaseSpan(span: Span): span is OpenTelemetrySdkTraceBaseSpan { - const castSpan = span as OpenTelemetrySdkTraceBaseSpan; + const castSpan = span as Partial; return !!castSpan.attributes && !!castSpan.startTime && !!castSpan.name && !!castSpan.endTime && !!castSpan.status; } diff --git a/packages/core/test/lib/envelope.test.ts b/packages/core/test/lib/envelope.test.ts index 8909fb8df202..235cdc923b84 100644 --- a/packages/core/test/lib/envelope.test.ts +++ b/packages/core/test/lib/envelope.test.ts @@ -116,7 +116,7 @@ describe('createSpanEnvelope', () => { const spanEnvelope = createSpanEnvelope([span]); - const spanItem = spanEnvelope[1]?.[0]?.[1]; + const spanItem = spanEnvelope[1][0]?.[1]; expect(spanItem).toEqual({ data: { 'sentry.origin': 'manual', @@ -207,7 +207,7 @@ describe('createSpanEnvelope', () => { expect(beforeSendSpan).toHaveBeenCalled(); - const spanItem = spanEnvelope[1]?.[0]?.[1]; + const spanItem = spanEnvelope[1][0]?.[1]; expect(spanItem).toEqual({ data: { 'sentry.origin': 'manual', @@ -242,7 +242,7 @@ describe('createSpanEnvelope', () => { expect(beforeSendSpan).toHaveBeenCalled(); - const spanItem = spanEnvelope[1]?.[0]?.[1]; + const spanItem = spanEnvelope[1][0]?.[1]; expect(spanItem).toEqual({ data: { 'sentry.origin': 'manual', diff --git a/packages/core/test/lib/integrations/zoderrrors.test.ts b/packages/core/test/lib/integrations/zoderrrors.test.ts index d5583fb57380..924ee5dd27da 100644 --- a/packages/core/test/lib/integrations/zoderrrors.test.ts +++ b/packages/core/test/lib/integrations/zoderrrors.test.ts @@ -20,11 +20,7 @@ class ZodError extends Error { super(); const actualProto = new.target.prototype; - if (Object.setPrototypeOf) { - Object.setPrototypeOf(this, actualProto); - } else { - (this as any).__proto__ = actualProto; - } + Object.setPrototypeOf(this, actualProto); this.name = 'ZodError'; this.issues = issues; diff --git a/packages/core/test/lib/tracing/trace.test.ts b/packages/core/test/lib/tracing/trace.test.ts index ac7605481649..fe304acc2beb 100644 --- a/packages/core/test/lib/tracing/trace.test.ts +++ b/packages/core/test/lib/tracing/trace.test.ts @@ -152,9 +152,7 @@ describe('startSpan', () => { try { await startSpan({ name: 'GET users/[id]' }, () => { return startSpan({ name: 'SELECT * from users' }, childSpan => { - if (childSpan) { - childSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'db.query'); - } + childSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'db.query'); return callback(); }); }); diff --git a/packages/core/test/lib/transports/multiplexed.test.ts b/packages/core/test/lib/transports/multiplexed.test.ts index 647acbdc856e..024ea7e4bd8a 100644 --- a/packages/core/test/lib/transports/multiplexed.test.ts +++ b/packages/core/test/lib/transports/multiplexed.test.ts @@ -118,7 +118,7 @@ describe('makeMultiplexedTransport', () => { const makeTransport = makeMultiplexedTransport( createTestTransport((url, _, env) => { expect(url).toBe(DSN2_URL); - expect(env[0]?.dsn).toBe(DSN2); + expect(env[0].dsn).toBe(DSN2); }), () => [DSN2], ); @@ -134,7 +134,7 @@ describe('makeMultiplexedTransport', () => { createTestTransport((url, release, env) => { expect(url).toBe(DSN2_URL); expect(release).toBe('something@1.0.0'); - expect(env[0]?.dsn).toBe(DSN2); + expect(env[0].dsn).toBe(DSN2); }), () => [{ dsn: DSN2, release: 'something@1.0.0' }], ); @@ -150,7 +150,7 @@ describe('makeMultiplexedTransport', () => { createTestTransport((url, release, env) => { expect(url).toBe('http://google.com'); expect(release).toBe('something@1.0.0'); - expect(env[0]?.dsn).toBe(DSN2); + expect(env[0].dsn).toBe(DSN2); }), () => [{ dsn: DSN2, release: 'something@1.0.0' }], ); diff --git a/packages/core/test/lib/transports/offline.test.ts b/packages/core/test/lib/transports/offline.test.ts index 5aa29596fa25..2f4df73ddae9 100644 --- a/packages/core/test/lib/transports/offline.test.ts +++ b/packages/core/test/lib/transports/offline.test.ts @@ -328,7 +328,7 @@ describe('makeOfflineTransport', () => { // When it gets shifted out of the store, the sent_at header should be updated const envelopes = getSentEnvelopes().map(parseEnvelope) as EventEnvelope[]; expect(envelopes[0]?.[0]).toBeDefined(); - const sent_at = new Date(envelopes[0]![0]?.sent_at); + const sent_at = new Date(envelopes[0]![0].sent_at); expect(sent_at.getTime()).toBeGreaterThan(testStartTime.getTime()); }, diff --git a/packages/core/test/utils-hoist/envelope.test.ts b/packages/core/test/utils-hoist/envelope.test.ts index dfb24f043fe8..ac1f17cfa1d9 100644 --- a/packages/core/test/utils-hoist/envelope.test.ts +++ b/packages/core/test/utils-hoist/envelope.test.ts @@ -71,7 +71,7 @@ describe('envelope', () => { measurements: { inp: { value: expect.any(Number), unit: expect.any(String) } }, }; - expect(spanEnvelopeItem[0]?.type).toBe('span'); + expect(spanEnvelopeItem[0].type).toBe('span'); expect(spanEnvelopeItem[1]).toMatchObject(expectedObj); }); }); diff --git a/packages/core/test/utils-hoist/misc.test.ts b/packages/core/test/utils-hoist/misc.test.ts index a042215fbcb9..3ae992d5f3bb 100644 --- a/packages/core/test/utils-hoist/misc.test.ts +++ b/packages/core/test/utils-hoist/misc.test.ts @@ -215,7 +215,7 @@ describe('addExceptionMechanism', () => { addExceptionMechanism(event); - expect(event.exception.values[0]?.mechanism).toEqual(defaultMechanism); + expect(event.exception.values[0].mechanism).toEqual(defaultMechanism); }); it('prefers current values to defaults', () => { @@ -226,7 +226,7 @@ describe('addExceptionMechanism', () => { addExceptionMechanism(event); - expect(event.exception.values[0]?.mechanism).toEqual(nonDefaultMechanism); + expect(event.exception.values[0].mechanism).toEqual(nonDefaultMechanism); }); it('prefers incoming values to current values', () => { @@ -239,7 +239,7 @@ describe('addExceptionMechanism', () => { addExceptionMechanism(event, newMechanism); // the new `handled` value took precedence - expect(event.exception.values[0]?.mechanism).toEqual({ type: 'instrument', handled: true, synthetic: true }); + expect(event.exception.values[0].mechanism).toEqual({ type: 'instrument', handled: true, synthetic: true }); }); it('merges data values', () => { @@ -251,7 +251,7 @@ describe('addExceptionMechanism', () => { addExceptionMechanism(event, newMechanism); - expect(event.exception.values[0]?.mechanism.data).toEqual({ + expect(event.exception.values[0].mechanism.data).toEqual({ function: 'addEventListener', handler: 'organizeShoes', target: 'closet', diff --git a/packages/feedback/src/core/components/Actor.test.ts b/packages/feedback/src/core/components/Actor.test.ts index 27c138d5420d..5eee6709a065 100644 --- a/packages/feedback/src/core/components/Actor.test.ts +++ b/packages/feedback/src/core/components/Actor.test.ts @@ -22,7 +22,7 @@ describe('Actor', () => { const actorComponent = feedback!.createWidget(); expect(actorComponent.el).toBeInstanceOf(HTMLButtonElement); - expect(actorComponent.el?.textContent).toBe(TRIGGER_LABEL); + expect(actorComponent.el.textContent).toBe(TRIGGER_LABEL); }); it('renders the correct aria label for the button', () => { @@ -43,19 +43,19 @@ describe('Actor', () => { // aria label is the same as trigger label when the trigger label isn't empty const actorDefault = feedback!.createWidget({ triggerLabel: 'Button' }); - expect(actorDefault.el?.textContent).toBe('Button'); - expect(actorDefault.el?.ariaLabel).toBe('Button'); + expect(actorDefault.el.textContent).toBe('Button'); + expect(actorDefault.el.ariaLabel).toBe('Button'); // aria label is default text when trigger label is empty and aria isn't configured const actorIcon = feedback!.createWidget({ triggerLabel: '' }); - expect(actorIcon.el?.textContent).toBe(''); - expect(actorIcon.el?.ariaLabel).toBe(TRIGGER_LABEL); + expect(actorIcon.el.textContent).toBe(''); + expect(actorIcon.el.ariaLabel).toBe(TRIGGER_LABEL); // aria label is the triggerAriaLabel if it's configured const actorAria = feedback!.createWidget({ triggerLabel: 'Button', triggerAriaLabel: 'Aria' }); - expect(actorAria.el?.textContent).toBe('Button'); - expect(actorAria.el?.ariaLabel).toBe('Aria'); + expect(actorAria.el.textContent).toBe('Button'); + expect(actorAria.el.ariaLabel).toBe('Aria'); }); }); diff --git a/packages/node/src/cron/node-cron.ts b/packages/node/src/cron/node-cron.ts index efa7cde2b698..5b9e48900287 100644 --- a/packages/node/src/cron/node-cron.ts +++ b/packages/node/src/cron/node-cron.ts @@ -7,7 +7,7 @@ export interface NodeCronOptions { } export interface NodeCron { - schedule: (cronExpression: string, callback: () => void, options: NodeCronOptions) => unknown; + schedule: (cronExpression: string, callback: () => void, options: NodeCronOptions | undefined) => unknown; } /** @@ -30,20 +30,23 @@ export interface NodeCron { */ export function instrumentNodeCron(lib: Partial & T): T { return new Proxy(lib, { - get(target, prop: keyof NodeCron) { + get(target, prop) { if (prop === 'schedule' && target.schedule) { // When 'get' is called for schedule, return a proxied version of the schedule function return new Proxy(target.schedule, { apply(target, thisArg, argArray: Parameters) { const [expression, callback, options] = argArray; - if (!options?.name) { + const name = options?.name; + const timezone = options?.timezone; + + if (!name) { throw new Error('Missing "name" for scheduled job. A name is required for Sentry check-in monitoring.'); } - async function monitoredCallback(): Promise { + const monitoredCallback = async (): Promise => { return withMonitor( - options.name, + name, async () => { // We have to manually catch here and capture the exception because node-cron swallows errors // https://github.com/node-cron/node-cron/issues/399 @@ -56,16 +59,16 @@ export function instrumentNodeCron(lib: Partial & T): T { }, { schedule: { type: 'crontab', value: replaceCronNames(expression) }, - timezone: options?.timezone, + timezone, }, ); - } + }; return target.apply(thisArg, [expression, monitoredCallback, options]); }, }); } else { - return target[prop]; + return target[prop as keyof T]; } }, }); diff --git a/packages/node/src/integrations/context.ts b/packages/node/src/integrations/context.ts index 5176a3a3348a..092d358f640f 100644 --- a/packages/node/src/integrations/context.ts +++ b/packages/node/src/integrations/context.ts @@ -123,18 +123,18 @@ export const nodeContextIntegration = defineIntegration(_nodeContextIntegration) function _updateContext(contexts: Contexts): Contexts { // Only update properties if they exist - if (contexts?.app?.app_memory) { + if (contexts.app?.app_memory) { contexts.app.app_memory = process.memoryUsage().rss; } - if (contexts?.app?.free_memory && typeof (process as ProcessWithCurrentValues).availableMemory === 'function') { + if (contexts.app?.free_memory && typeof (process as ProcessWithCurrentValues).availableMemory === 'function') { const freeMemory = (process as ProcessWithCurrentValues).availableMemory?.(); if (freeMemory != null) { contexts.app.free_memory = freeMemory; } } - if (contexts?.device?.free_memory) { + if (contexts.device?.free_memory) { contexts.device.free_memory = os.freemem(); } @@ -226,7 +226,7 @@ export function getDeviceContext(deviceOpt: DeviceContextOptions | true): Device // Sometimes os.uptime() throws due to lacking permissions: https://github.com/getsentry/sentry-javascript/issues/8202 let uptime; try { - uptime = os.uptime && os.uptime(); + uptime = os.uptime(); } catch (e) { // noop } @@ -246,7 +246,7 @@ export function getDeviceContext(deviceOpt: DeviceContextOptions | true): Device } if (deviceOpt === true || deviceOpt.cpu) { - const cpuInfo: os.CpuInfo[] | undefined = os.cpus(); + const cpuInfo = os.cpus() as os.CpuInfo[] | undefined; const firstCpu = cpuInfo && cpuInfo[0]; if (firstCpu) { device.processor_count = cpuInfo.length; diff --git a/packages/node/src/integrations/local-variables/local-variables-sync.ts b/packages/node/src/integrations/local-variables/local-variables-sync.ts index 3416dbf47347..daddc44cad1f 100644 --- a/packages/node/src/integrations/local-variables/local-variables-sync.ts +++ b/packages/node/src/integrations/local-variables/local-variables-sync.ts @@ -134,13 +134,13 @@ class AsyncSession implements DebugSession { const { add, next } = createCallbackList(complete); for (const prop of props) { - if (prop?.value?.objectId && prop?.value.className === 'Array') { + if (prop.value?.objectId && prop.value.className === 'Array') { const id = prop.value.objectId; add(vars => this._unrollArray(id, prop.name, vars, next)); - } else if (prop?.value?.objectId && prop?.value?.className === 'Object') { + } else if (prop.value?.objectId && prop.value.className === 'Object') { const id = prop.value.objectId; add(vars => this._unrollObject(id, prop.name, vars, next)); - } else if (prop?.value) { + } else if (prop.value) { add(vars => this._unrollOther(prop, vars, next)); } } @@ -177,7 +177,7 @@ class AsyncSession implements DebugSession { vars[name] = props .filter(v => v.name !== 'length' && !isNaN(parseInt(v.name, 10))) .sort((a, b) => parseInt(a.name, 10) - parseInt(b.name, 10)) - .map(v => v?.value?.value); + .map(v => v.value?.value); next(vars); }); @@ -189,7 +189,7 @@ class AsyncSession implements DebugSession { private _unrollObject(objectId: string, name: string, vars: Variables, next: (obj: Variables) => void): void { this._getProperties(objectId, props => { vars[name] = props - .map<[string, unknown]>(v => [v.name, v?.value?.value]) + .map<[string, unknown]>(v => [v.name, v.value?.value]) .reduce((obj, [key, val]) => { obj[key] = val; return obj; @@ -235,7 +235,7 @@ const _localVariablesSyncIntegration = (( let shouldProcessEvent = false; function addLocalVariablesToException(exception: Exception): void { - const hash = hashFrames(exception?.stacktrace?.frames); + const hash = hashFrames(exception.stacktrace?.frames); if (hash === undefined) { return; @@ -281,7 +281,7 @@ const _localVariablesSyncIntegration = (( } function addLocalVariablesToEvent(event: Event): Event { - for (const exception of event?.exception?.values || []) { + for (const exception of event.exception?.values || []) { addLocalVariablesToException(exception); } @@ -327,7 +327,7 @@ const _localVariablesSyncIntegration = (( rateLimiter?.(); // data.description contains the original error.stack - const exceptionHash = hashFromStack(stackParser, data?.description); + const exceptionHash = hashFromStack(stackParser, data.description); if (exceptionHash == undefined) { complete(); @@ -359,7 +359,7 @@ const _localVariablesSyncIntegration = (( } else { const id = localScope.object.objectId; add(frames => - session?.getLocalVariables(id, vars => { + session.getLocalVariables(id, vars => { frames[i] = { function: fn, vars }; next(frames); }), @@ -385,13 +385,13 @@ const _localVariablesSyncIntegration = (( max, () => { logger.log('Local variables rate-limit lifted.'); - session?.setPauseOnExceptions(true); + session.setPauseOnExceptions(true); }, seconds => { logger.log( `Local variables rate-limit exceeded. Disabling capturing of caught exceptions for ${seconds} seconds.`, ); - session?.setPauseOnExceptions(false); + session.setPauseOnExceptions(false); }, ); } diff --git a/packages/node/src/integrations/local-variables/worker.ts b/packages/node/src/integrations/local-variables/worker.ts index b00c8ca3b9c7..564744c1d878 100644 --- a/packages/node/src/integrations/local-variables/worker.ts +++ b/packages/node/src/integrations/local-variables/worker.ts @@ -67,13 +67,13 @@ async function getLocalVariables(session: Session, objectId: string): Promise { */ export const hapiIntegration = defineIntegration(_hapiIntegration); -function isErrorEvent(event: RequestEvent): event is RequestEvent { - return event && (event as RequestEvent).error !== undefined; +function isErrorEvent(event: unknown): event is RequestEvent { + return !!(event && typeof event === 'object' && 'error' in event && event.error); } function sendErrorToSentry(errorData: object): void { @@ -74,8 +74,8 @@ export const hapiErrorPlugin = { server.events.on({ name: 'request', channels: ['error'] }, (request: Request, event: RequestEvent) => { if (getIsolationScope() !== getDefaultIsolationScope()) { const route = request.route; - if (route && route.path) { - getIsolationScope().setTransactionName(`${route.method?.toUpperCase() || 'GET'} ${route.path}`); + if (route.path) { + getIsolationScope().setTransactionName(`${route.method.toUpperCase()} ${route.path}`); } } else { DEBUG_BUILD && diff --git a/packages/node/src/integrations/tracing/koa.ts b/packages/node/src/integrations/tracing/koa.ts index 469ab63a0d82..9860773f8d91 100644 --- a/packages/node/src/integrations/tracing/koa.ts +++ b/packages/node/src/integrations/tracing/koa.ts @@ -31,7 +31,7 @@ export const instrumentKoa = generateInstrumentOnce( const attributes = spanToJSON(span).data; const route = attributes && attributes[ATTR_HTTP_ROUTE]; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - const method: string = info?.context?.request?.method?.toUpperCase() || 'GET'; + const method = info.context?.request?.method?.toUpperCase() || 'GET'; if (route) { getIsolationScope().setTransactionName(`${method} ${route}`); } diff --git a/packages/node/src/integrations/tracing/nest/sentry-nest-instrumentation.ts b/packages/node/src/integrations/tracing/nest/sentry-nest-instrumentation.ts index 91428a96c88d..f94d828bc11f 100644 --- a/packages/node/src/integrations/tracing/nest/sentry-nest-instrumentation.ts +++ b/packages/node/src/integrations/tracing/nest/sentry-nest-instrumentation.ts @@ -137,7 +137,7 @@ export class SentryNestInstrumentation extends InstrumentationBase { target.prototype.canActivate = new Proxy(target.prototype.canActivate, { apply: (originalCanActivate, thisArgCanActivate, argsCanActivate) => { - const context: MinimalNestJsExecutionContext = argsCanActivate[0]; + const context = argsCanActivate[0]; if (!context) { return originalCanActivate.apply(thisArgCanActivate, argsCanActivate); @@ -180,11 +180,11 @@ export class SentryNestInstrumentation extends InstrumentationBase { target.prototype.intercept = new Proxy(target.prototype.intercept, { apply: (originalIntercept, thisArgIntercept, argsIntercept) => { - const context: MinimalNestJsExecutionContext = argsIntercept[0]; - const next: CallHandler = argsIntercept[1]; + const context = argsIntercept[0] as MinimalNestJsExecutionContext | undefined; + const next = argsIntercept[1] as CallHandler | undefined; const parentSpan = getActiveSpan(); - let afterSpan: Span; + let afterSpan: Span | undefined; // Check that we can reasonably assume that the target is an interceptor. if (!context || !next || typeof next.handle !== 'function') { @@ -228,7 +228,7 @@ export class SentryNestInstrumentation extends InstrumentationBase { try { returnedObservableInterceptMaybePromise = originalIntercept.apply(thisArgIntercept, argsIntercept); } catch (e) { - beforeSpan?.end(); + beforeSpan.end(); afterSpan?.end(); throw e; } @@ -245,7 +245,7 @@ export class SentryNestInstrumentation extends InstrumentationBase { return observable; }, e => { - beforeSpan?.end(); + beforeSpan.end(); afterSpan?.end(); throw e; }, @@ -254,7 +254,7 @@ export class SentryNestInstrumentation extends InstrumentationBase { // handle sync interceptor if (typeof returnedObservableInterceptMaybePromise.subscribe === 'function') { - instrumentObservable(returnedObservableInterceptMaybePromise, afterSpan ?? parentSpan); + instrumentObservable(returnedObservableInterceptMaybePromise, afterSpan); } return returnedObservableInterceptMaybePromise; diff --git a/packages/node/src/integrations/tracing/redis.ts b/packages/node/src/integrations/tracing/redis.ts index be788815c177..103773073dbe 100644 --- a/packages/node/src/integrations/tracing/redis.ts +++ b/packages/node/src/integrations/tracing/redis.ts @@ -40,7 +40,7 @@ const cacheResponseHook: RedisResponseCustomAttributeFunction = (span: Span, red if ( !safeKey || !cacheOperation || - !_redisOptions?.cachePrefixes || + !_redisOptions.cachePrefixes || !shouldConsiderForCache(redisCommand, safeKey, _redisOptions.cachePrefixes) ) { // not relevant for cache diff --git a/packages/node/src/integrations/tracing/tedious.ts b/packages/node/src/integrations/tracing/tedious.ts index 8671edd2c09f..6e1374c7e06a 100644 --- a/packages/node/src/integrations/tracing/tedious.ts +++ b/packages/node/src/integrations/tracing/tedious.ts @@ -31,7 +31,7 @@ const _tediousIntegration = (() => { return; } - const operation = description?.split(' ')[0] || ''; + const operation = description.split(' ')[0] || ''; if (TEDIUS_INSTRUMENTED_METHODS.has(operation)) { span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.tedious'); } diff --git a/packages/node/test/integration/transactions.test.ts b/packages/node/test/integration/transactions.test.ts index a54d3c5f73bb..525b2978fc2e 100644 --- a/packages/node/test/integration/transactions.test.ts +++ b/packages/node/test/integration/transactions.test.ts @@ -517,7 +517,7 @@ describe('Integration | Transactions', () => { // Checking the spans here, as they are circular to the transaction... const runArgs = beforeSendTransaction.mock.calls[0] as unknown as [TransactionEvent, unknown]; - const spans = runArgs[0]?.spans || []; + const spans = runArgs[0].spans || []; // note: Currently, spans do not have any context/span added to them // This is the same behavior as for the "regular" SDKs diff --git a/packages/opentelemetry/test/integration/transactions.test.ts b/packages/opentelemetry/test/integration/transactions.test.ts index d225fb1a0194..fe24f49a9bf1 100644 --- a/packages/opentelemetry/test/integration/transactions.test.ts +++ b/packages/opentelemetry/test/integration/transactions.test.ts @@ -399,7 +399,7 @@ describe('Integration | Transactions', () => { // Checking the spans here, as they are circular to the transaction... const runArgs = beforeSendTransaction.mock.calls[0] as unknown as [TransactionEvent, unknown]; - const spans = runArgs[0]?.spans || []; + const spans = runArgs[0].spans || []; // note: Currently, spans do not have any context/span added to them // This is the same behavior as for the "regular" SDKs