Skip to content

Commit 47a6c0b

Browse files
committed
some auto fixing
1 parent 893d711 commit 47a6c0b

File tree

9 files changed

+44
-41
lines changed

9 files changed

+44
-41
lines changed

packages/node/src/cron/node-cron.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface NodeCronOptions {
77
}
88

99
export interface NodeCron {
10-
schedule: (cronExpression: string, callback: () => void, options: NodeCronOptions) => unknown;
10+
schedule: (cronExpression: string, callback: () => void, options: NodeCronOptions | undefined) => unknown;
1111
}
1212

1313
/**
@@ -30,20 +30,23 @@ export interface NodeCron {
3030
*/
3131
export function instrumentNodeCron<T>(lib: Partial<NodeCron> & T): T {
3232
return new Proxy(lib, {
33-
get(target, prop: keyof NodeCron) {
33+
get(target, prop) {
3434
if (prop === 'schedule' && target.schedule) {
3535
// When 'get' is called for schedule, return a proxied version of the schedule function
3636
return new Proxy(target.schedule, {
3737
apply(target, thisArg, argArray: Parameters<NodeCron['schedule']>) {
3838
const [expression, callback, options] = argArray;
3939

40-
if (!options?.name) {
40+
const name = options?.name;
41+
const timezone = options?.timezone;
42+
43+
if (!name) {
4144
throw new Error('Missing "name" for scheduled job. A name is required for Sentry check-in monitoring.');
4245
}
4346

44-
async function monitoredCallback(): Promise<void> {
47+
const monitoredCallback = async (): Promise<void> => {
4548
return withMonitor(
46-
options.name,
49+
name,
4750
async () => {
4851
// We have to manually catch here and capture the exception because node-cron swallows errors
4952
// https://github.com/node-cron/node-cron/issues/399
@@ -56,16 +59,16 @@ export function instrumentNodeCron<T>(lib: Partial<NodeCron> & T): T {
5659
},
5760
{
5861
schedule: { type: 'crontab', value: replaceCronNames(expression) },
59-
timezone: options?.timezone,
62+
timezone,
6063
},
6164
);
62-
}
65+
};
6366

6467
return target.apply(thisArg, [expression, monitoredCallback, options]);
6568
},
6669
});
6770
} else {
68-
return target[prop];
71+
return target[prop as keyof T];
6972
}
7073
},
7174
});

packages/node/src/integrations/context.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,18 @@ export const nodeContextIntegration = defineIntegration(_nodeContextIntegration)
123123
function _updateContext(contexts: Contexts): Contexts {
124124
// Only update properties if they exist
125125

126-
if (contexts?.app?.app_memory) {
126+
if (contexts.app?.app_memory) {
127127
contexts.app.app_memory = process.memoryUsage().rss;
128128
}
129129

130-
if (contexts?.app?.free_memory && typeof (process as ProcessWithCurrentValues).availableMemory === 'function') {
130+
if (contexts.app?.free_memory && typeof (process as ProcessWithCurrentValues).availableMemory === 'function') {
131131
const freeMemory = (process as ProcessWithCurrentValues).availableMemory?.();
132132
if (freeMemory != null) {
133133
contexts.app.free_memory = freeMemory;
134134
}
135135
}
136136

137-
if (contexts?.device?.free_memory) {
137+
if (contexts.device?.free_memory) {
138138
contexts.device.free_memory = os.freemem();
139139
}
140140

@@ -226,7 +226,7 @@ export function getDeviceContext(deviceOpt: DeviceContextOptions | true): Device
226226
// Sometimes os.uptime() throws due to lacking permissions: https://github.com/getsentry/sentry-javascript/issues/8202
227227
let uptime;
228228
try {
229-
uptime = os.uptime && os.uptime();
229+
uptime = os.uptime();
230230
} catch (e) {
231231
// noop
232232
}
@@ -246,7 +246,7 @@ export function getDeviceContext(deviceOpt: DeviceContextOptions | true): Device
246246
}
247247

248248
if (deviceOpt === true || deviceOpt.cpu) {
249-
const cpuInfo: os.CpuInfo[] | undefined = os.cpus();
249+
const cpuInfo = os.cpus() as os.CpuInfo[] | undefined;
250250
const firstCpu = cpuInfo && cpuInfo[0];
251251
if (firstCpu) {
252252
device.processor_count = cpuInfo.length;

packages/node/src/integrations/local-variables/local-variables-sync.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ class AsyncSession implements DebugSession {
134134
const { add, next } = createCallbackList<Variables>(complete);
135135

136136
for (const prop of props) {
137-
if (prop?.value?.objectId && prop?.value.className === 'Array') {
137+
if (prop.value?.objectId && prop.value.className === 'Array') {
138138
const id = prop.value.objectId;
139139
add(vars => this._unrollArray(id, prop.name, vars, next));
140-
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
140+
} else if (prop.value?.objectId && prop.value.className === 'Object') {
141141
const id = prop.value.objectId;
142142
add(vars => this._unrollObject(id, prop.name, vars, next));
143-
} else if (prop?.value) {
143+
} else if (prop.value) {
144144
add(vars => this._unrollOther(prop, vars, next));
145145
}
146146
}
@@ -177,7 +177,7 @@ class AsyncSession implements DebugSession {
177177
vars[name] = props
178178
.filter(v => v.name !== 'length' && !isNaN(parseInt(v.name, 10)))
179179
.sort((a, b) => parseInt(a.name, 10) - parseInt(b.name, 10))
180-
.map(v => v?.value?.value);
180+
.map(v => v.value?.value);
181181

182182
next(vars);
183183
});
@@ -189,7 +189,7 @@ class AsyncSession implements DebugSession {
189189
private _unrollObject(objectId: string, name: string, vars: Variables, next: (obj: Variables) => void): void {
190190
this._getProperties(objectId, props => {
191191
vars[name] = props
192-
.map<[string, unknown]>(v => [v.name, v?.value?.value])
192+
.map<[string, unknown]>(v => [v.name, v.value?.value])
193193
.reduce((obj, [key, val]) => {
194194
obj[key] = val;
195195
return obj;
@@ -235,7 +235,7 @@ const _localVariablesSyncIntegration = ((
235235
let shouldProcessEvent = false;
236236

237237
function addLocalVariablesToException(exception: Exception): void {
238-
const hash = hashFrames(exception?.stacktrace?.frames);
238+
const hash = hashFrames(exception.stacktrace?.frames);
239239

240240
if (hash === undefined) {
241241
return;
@@ -281,7 +281,7 @@ const _localVariablesSyncIntegration = ((
281281
}
282282

283283
function addLocalVariablesToEvent(event: Event): Event {
284-
for (const exception of event?.exception?.values || []) {
284+
for (const exception of event.exception?.values || []) {
285285
addLocalVariablesToException(exception);
286286
}
287287

@@ -327,7 +327,7 @@ const _localVariablesSyncIntegration = ((
327327
rateLimiter?.();
328328

329329
// data.description contains the original error.stack
330-
const exceptionHash = hashFromStack(stackParser, data?.description);
330+
const exceptionHash = hashFromStack(stackParser, data.description);
331331

332332
if (exceptionHash == undefined) {
333333
complete();
@@ -359,7 +359,7 @@ const _localVariablesSyncIntegration = ((
359359
} else {
360360
const id = localScope.object.objectId;
361361
add(frames =>
362-
session?.getLocalVariables(id, vars => {
362+
session.getLocalVariables(id, vars => {
363363
frames[i] = { function: fn, vars };
364364
next(frames);
365365
}),
@@ -385,13 +385,13 @@ const _localVariablesSyncIntegration = ((
385385
max,
386386
() => {
387387
logger.log('Local variables rate-limit lifted.');
388-
session?.setPauseOnExceptions(true);
388+
session.setPauseOnExceptions(true);
389389
},
390390
seconds => {
391391
logger.log(
392392
`Local variables rate-limit exceeded. Disabling capturing of caught exceptions for ${seconds} seconds.`,
393393
);
394-
session?.setPauseOnExceptions(false);
394+
session.setPauseOnExceptions(false);
395395
},
396396
);
397397
}

packages/node/src/integrations/local-variables/worker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ async function getLocalVariables(session: Session, objectId: string): Promise<Va
6767
const variables = {};
6868

6969
for (const prop of properties.result) {
70-
if (prop?.value?.objectId && prop?.value.className === 'Array') {
70+
if (prop.value?.objectId && prop.value.className === 'Array') {
7171
const id = prop.value.objectId;
7272
await unrollArray(session, id, prop.name, variables);
73-
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
73+
} else if (prop.value?.objectId && prop.value.className === 'Object') {
7474
const id = prop.value.objectId;
7575
await unrollObject(session, id, prop.name, variables);
76-
} else if (prop?.value) {
76+
} else if (prop.value) {
7777
unrollOther(prop, variables);
7878
}
7979
}

packages/node/src/integrations/tracing/hapi/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const _hapiIntegration = (() => {
4848
*/
4949
export const hapiIntegration = defineIntegration(_hapiIntegration);
5050

51-
function isErrorEvent(event: RequestEvent): event is RequestEvent {
52-
return event && (event as RequestEvent).error !== undefined;
51+
function isErrorEvent(event: unknown): event is RequestEvent {
52+
return !!(event && typeof event === 'object' && 'error' in event && event.error);
5353
}
5454

5555
function sendErrorToSentry(errorData: object): void {
@@ -74,8 +74,8 @@ export const hapiErrorPlugin = {
7474
server.events.on({ name: 'request', channels: ['error'] }, (request: Request, event: RequestEvent) => {
7575
if (getIsolationScope() !== getDefaultIsolationScope()) {
7676
const route = request.route;
77-
if (route && route.path) {
78-
getIsolationScope().setTransactionName(`${route.method?.toUpperCase() || 'GET'} ${route.path}`);
77+
if (route.path) {
78+
getIsolationScope().setTransactionName(`${route.method.toUpperCase()} ${route.path}`);
7979
}
8080
} else {
8181
DEBUG_BUILD &&

packages/node/src/integrations/tracing/koa.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const instrumentKoa = generateInstrumentOnce(
3131
const attributes = spanToJSON(span).data;
3232
const route = attributes && attributes[ATTR_HTTP_ROUTE];
3333
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
34-
const method: string = info?.context?.request?.method?.toUpperCase() || 'GET';
34+
const method = info.context?.request?.method?.toUpperCase() || 'GET';
3535
if (route) {
3636
getIsolationScope().setTransactionName(`${method} ${route}`);
3737
}

packages/node/src/integrations/tracing/nest/sentry-nest-instrumentation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class SentryNestInstrumentation extends InstrumentationBase {
137137

138138
target.prototype.canActivate = new Proxy(target.prototype.canActivate, {
139139
apply: (originalCanActivate, thisArgCanActivate, argsCanActivate) => {
140-
const context: MinimalNestJsExecutionContext = argsCanActivate[0];
140+
const context = argsCanActivate[0];
141141

142142
if (!context) {
143143
return originalCanActivate.apply(thisArgCanActivate, argsCanActivate);
@@ -180,11 +180,11 @@ export class SentryNestInstrumentation extends InstrumentationBase {
180180

181181
target.prototype.intercept = new Proxy(target.prototype.intercept, {
182182
apply: (originalIntercept, thisArgIntercept, argsIntercept) => {
183-
const context: MinimalNestJsExecutionContext = argsIntercept[0];
184-
const next: CallHandler = argsIntercept[1];
183+
const context = argsIntercept[0] as MinimalNestJsExecutionContext | undefined;
184+
const next = argsIntercept[1] as CallHandler | undefined;
185185

186186
const parentSpan = getActiveSpan();
187-
let afterSpan: Span;
187+
let afterSpan: Span | undefined;
188188

189189
// Check that we can reasonably assume that the target is an interceptor.
190190
if (!context || !next || typeof next.handle !== 'function') {
@@ -228,7 +228,7 @@ export class SentryNestInstrumentation extends InstrumentationBase {
228228
try {
229229
returnedObservableInterceptMaybePromise = originalIntercept.apply(thisArgIntercept, argsIntercept);
230230
} catch (e) {
231-
beforeSpan?.end();
231+
beforeSpan.end();
232232
afterSpan?.end();
233233
throw e;
234234
}
@@ -245,7 +245,7 @@ export class SentryNestInstrumentation extends InstrumentationBase {
245245
return observable;
246246
},
247247
e => {
248-
beforeSpan?.end();
248+
beforeSpan.end();
249249
afterSpan?.end();
250250
throw e;
251251
},
@@ -254,7 +254,7 @@ export class SentryNestInstrumentation extends InstrumentationBase {
254254

255255
// handle sync interceptor
256256
if (typeof returnedObservableInterceptMaybePromise.subscribe === 'function') {
257-
instrumentObservable(returnedObservableInterceptMaybePromise, afterSpan ?? parentSpan);
257+
instrumentObservable(returnedObservableInterceptMaybePromise, afterSpan);
258258
}
259259

260260
return returnedObservableInterceptMaybePromise;

packages/node/src/integrations/tracing/redis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const cacheResponseHook: RedisResponseCustomAttributeFunction = (span: Span, red
4040
if (
4141
!safeKey ||
4242
!cacheOperation ||
43-
!_redisOptions?.cachePrefixes ||
43+
!_redisOptions.cachePrefixes ||
4444
!shouldConsiderForCache(redisCommand, safeKey, _redisOptions.cachePrefixes)
4545
) {
4646
// not relevant for cache

packages/node/src/integrations/tracing/tedious.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const _tediousIntegration = (() => {
3131
return;
3232
}
3333

34-
const operation = description?.split(' ')[0] || '';
34+
const operation = description.split(' ')[0] || '';
3535
if (TEDIUS_INSTRUMENTED_METHODS.has(operation)) {
3636
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.tedious');
3737
}

0 commit comments

Comments
 (0)