Skip to content

Commit d231d2a

Browse files
committed
Fix type issues
1 parent e18ab56 commit d231d2a

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

dev-packages/cloudflare-integration-tests/suites/tracing/durableobject/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@ export const TestDurableObject = Sentry.instrumentDurableObjectWithSentry(
2121
(env: Env) => ({
2222
dsn: env.SENTRY_DSN,
2323
tracesSampleRate: 1.0,
24-
beforeSendTransaction: transaction => {
25-
console.log('beforeSendTransaction', transaction);
26-
return transaction;
27-
},
2824
}),
2925
TestDurableObjectBase,
3026
);
3127

3228
export default {
33-
async fetch(request, env): Promise<Response> {
29+
async fetch(request: Request, env: Env): Promise<Response> {
3430
const id: DurableObjectId = env.TEST_DURABLE_OBJECT.idFromName('test');
3531
const stub = env.TEST_DURABLE_OBJECT.get(id) as unknown as TestDurableObjectBase;
3632

packages/cloudflare/src/durableobject.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ function instrumentPrototype<T extends NewableFunction>(target: T): void {
304304

305305
while (current && current !== Object.prototype) {
306306
Object.getOwnPropertyNames(current).forEach(name => {
307-
if (name !== 'constructor' && typeof current[name] === 'function') {
307+
if (name !== 'constructor' && typeof (current as Record<string, unknown>)[name] === 'function') {
308308
methodNames.add(name);
309309
}
310310
});
@@ -313,20 +313,24 @@ function instrumentPrototype<T extends NewableFunction>(target: T): void {
313313

314314
// Instrument each method on the prototype
315315
methodNames.forEach(methodName => {
316-
const originalMethod = proto[methodName];
316+
const originalMethod = (proto as Record<string, unknown>)[methodName];
317317

318318
if (!originalMethod || isInstrumented(originalMethod)) {
319319
return;
320320
}
321321

322322
// Create a wrapper that gets context/options from the instance at runtime
323-
const wrappedMethod = function (this: any, ...args: any[]) {
324-
const instanceContext = this.__SENTRY_CONTEXT__;
325-
const instanceOptions = this.__SENTRY_OPTIONS__;
323+
const wrappedMethod = function (this: any, ...args: any[]): unknown {
324+
const thisWithSentry = this as {
325+
__SENTRY_CONTEXT__: DurableObjectState;
326+
__SENTRY_OPTIONS__: CloudflareOptions;
327+
};
328+
const instanceContext = thisWithSentry.__SENTRY_CONTEXT__;
329+
const instanceOptions = thisWithSentry.__SENTRY_OPTIONS__;
326330

327331
if (!instanceOptions) {
328332
// Fallback to original method if no Sentry data found
329-
return originalMethod.apply(this, args);
333+
return (originalMethod as (...args: any[]) => any).apply(this, args);
330334
}
331335

332336
// Use the existing wrapper but with instance-specific context/options
@@ -337,12 +341,12 @@ function instrumentPrototype<T extends NewableFunction>(target: T): void {
337341
spanName: methodName,
338342
spanOp: 'rpc',
339343
},
340-
originalMethod,
344+
originalMethod as (...args: any[]) => any,
341345
undefined,
342346
true, // noMark = true since we'll mark the prototype method
343347
);
344348

345-
return wrapper.apply(this, args);
349+
return (wrapper as (...args: any[]) => any).apply(this, args);
346350
};
347351

348352
markAsInstrumented(wrappedMethod);

packages/cloudflare/test/durableobject.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('instrumentDurableObjectWithSentry', () => {
5151
} as any;
5252
const mockEnv = {} as any; // Environment mock
5353
const initCore = vi.spyOn(SentryCore, 'initAndBind');
54-
const getClientSpy = vi.spyOn(SentryCore, 'getClient').mockReturnValue(undefined);
54+
vi.spyOn(SentryCore, 'getClient').mockReturnValue(undefined);
5555
const options = vi
5656
.fn()
5757
.mockReturnValueOnce({
@@ -63,12 +63,18 @@ describe('instrumentDurableObjectWithSentry', () => {
6363
const testClass = class {
6464
method() {}
6565
};
66-
const instance1 = Reflect.construct(instrumentDurableObjectWithSentry(options, testClass as any), [mockContext, mockEnv]) as any;
66+
const instance1 = Reflect.construct(instrumentDurableObjectWithSentry(options, testClass as any), [
67+
mockContext,
68+
mockEnv,
69+
]) as any;
6770
instance1.method();
68-
69-
const instance2 = Reflect.construct(instrumentDurableObjectWithSentry(options, testClass as any), [mockContext, mockEnv]) as any;
71+
72+
const instance2 = Reflect.construct(instrumentDurableObjectWithSentry(options, testClass as any), [
73+
mockContext,
74+
mockEnv,
75+
]) as any;
7076
instance2.method();
71-
77+
7278
expect(initCore).nthCalledWith(1, expect.any(Function), expect.objectContaining({ orgId: 1 }));
7379
expect(initCore).nthCalledWith(2, expect.any(Function), expect.objectContaining({ orgId: 2 }));
7480
});

0 commit comments

Comments
 (0)