Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ jobs:
if: matrix.test-application == 'deno' || matrix.test-application == 'deno-streamed'
uses: denoland/setup-deno@v2.0.4
with:
deno-version: v2.1.5
deno-version: ${{ matrix.deno-version || 'v2.1.5' }}
- name: Restore caches
uses: ./.github/actions/restore-cache
with:
Expand Down Expand Up @@ -1118,6 +1118,11 @@ jobs:
uses: actions/setup-node@v6
with:
node-version-file: 'dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}/package.json'
- name: Set up Deno
if: matrix.test-application == 'deno' || matrix.test-application == 'deno-streamed'
uses: denoland/setup-deno@v2.0.4
with:
deno-version: ${{ matrix.deno-version || 'v2.1.5' }}
- name: Restore caches
uses: ./.github/actions/restore-cache
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@
},
"volta": {
"extends": "../../package.json"
},
"sentryTest": {
"optionalVariants": [
{
"deno-version": "latest",
"label": "deno-streamed (latest)"
}
]
}
}
8 changes: 8 additions & 0 deletions dev-packages/e2e-tests/test-applications/deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@
},
"volta": {
"extends": "../../package.json"
},
"sentryTest": {
"optionalVariants": [
{
"deno-version": "latest",
"label": "deno (latest)"
}
]
}
}
48 changes: 34 additions & 14 deletions packages/deno/src/integrations/deno-serve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import { debug, defineIntegration } from '@sentry/core';
import { setAsyncLocalStorageAsyncContextStrategy } from '../async';
import type { RequestHandlerWrapperOptions } from '../wrap-deno-request-handler';
import { wrapDenoRequestHandler } from '../wrap-deno-request-handler';
Expand Down Expand Up @@ -44,24 +44,44 @@ const applyHandlerWrap = <A extends Deno.Addr>(
() => handler(request, info as Deno.ServeHandlerInfo<A>),
)) as Deno.ServeHandler;

const instrumentedDenoServe = (serve: typeof Deno.serve): typeof Deno.serve =>
new Proxy(serve, {
apply(target, thisArg, args: ServeParams) {
if (isSimpleHandler(args)) {
args[0] = applyHandlerWrap(args[0]);
} else if (isServeOptWithFunction(args)) {
args[1] = applyHandlerWrap(args[1], args[0]);
} else if (isServeInitOptions(args)) {
args[0].handler = applyHandlerWrap(args[0].handler, args[0]);
}
// if none of those matched, it'll crash, most likely.
return target.apply(thisArg, args);
},
});

const _denoServeIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
setAsyncLocalStorageAsyncContextStrategy();
Deno.serve = new Proxy(Deno.serve, {
apply(target, thisArg, args: ServeParams) {
if (isSimpleHandler(args)) {
args[0] = applyHandlerWrap(args[0]);
} else if (isServeOptWithFunction(args)) {
args[1] = applyHandlerWrap(args[1], args[0]);
} else if (isServeInitOptions(args)) {
args[0].handler = applyHandlerWrap(args[0].handler, args[0]);
}
// if none of those matched, it'll crash, most likely.
return target.apply(thisArg, args);
},
});

const originalServe = Deno.serve;
const wrappedServe = instrumentedDenoServe(originalServe);

try {
const descriptor = Object.getOwnPropertyDescriptor(Deno, 'serve');

Object.defineProperty(Deno, 'serve', {
configurable: descriptor?.configurable ?? true,
enumerable: descriptor?.enumerable ?? true,
// writable: true avoids other instrumentations on older Deno versions
// from crashing if they used to do assignment
writable: true,
value: wrappedServe,
});
} catch (error) {
debug.warn('Could not instrument Deno.serve.', error);
}
},
};
}) satisfies IntegrationFn;
Expand Down
Loading