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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"scripts": {
"start": "deno run --allow-net --allow-env --allow-read src/app.ts",
"start": "deno run --allow-net --allow-env --allow-read --allow-sys src/app.ts",
"test": "playwright test",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { waitForStreamedSpans, getSpanOp } from '@sentry-internal/test-utils';

const SEGMENT_SPAN = {
attributes: {
'app.start_time': {
type: 'string',
value: expect.any(String),
},
'client.address': {
type: 'string',
value: expect.any(String),
Expand All @@ -11,6 +15,11 @@ const SEGMENT_SPAN = {
type: 'integer',
value: expect.any(Number),
},
// TODO: 'device.archs' is set but arrays are not yet serialized in span attributes
Comment thread
chargome marked this conversation as resolved.
'device.processor_count': {
type: 'integer',
value: expect.any(Number),
},
'http.request.header.accept': {
type: 'string',
value: '*/*',
Expand Down Expand Up @@ -51,6 +60,14 @@ const SEGMENT_SPAN = {
type: 'integer',
value: expect.any(Number),
},
'os.name': {
type: 'string',
value: expect.any(String),
},
'os.version': {
type: 'string',
value: expect.any(String),
},
'sentry.environment': {
type: 'string',
value: 'qa',
Expand Down Expand Up @@ -115,6 +132,14 @@ const SEGMENT_SPAN = {
type: 'string',
value: 'node',
},
'process.runtime.engine.name': {
type: 'string',
value: 'v8',
},
'process.runtime.engine.version': {
type: 'string',
value: expect.any(String),
},
},
end_timestamp: expect.any(Number),
is_segment: true,
Expand Down
75 changes: 44 additions & 31 deletions packages/deno/src/integrations/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Event, IntegrationFn } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration, safeSetSpanJSONAttributes } from '@sentry/core';

const INTEGRATION_NAME = 'DenoContext';

Expand All @@ -22,41 +22,54 @@ async function getOSRelease(): Promise<string | undefined> {
: undefined;
}

async function addDenoRuntimeContext(event: Event): Promise<Event> {
event.contexts = {
...{
app: {
app_start_time: new Date(Date.now() - performance.now()).toISOString(),
},
device: {
arch: Deno.build.arch,
// eslint-disable-next-line no-restricted-globals
processor_count: navigator.hardwareConcurrency,
},
os: {
name: getOSName(),
version: await getOSRelease(),
},
v8: {
name: 'v8',
version: Deno.version.v8,
},
typescript: {
name: 'TypeScript',
version: Deno.version.typescript,
},
},
...event.contexts,
const _denoContextIntegration = (() => {
const appStartTime = new Date(Date.now() - performance.now()).toISOString();
const osName = getOSName();
const arch = Deno.build.arch;
// eslint-disable-next-line no-restricted-globals
const processorCount = navigator.hardwareConcurrency;
const v8Version = Deno.version.v8;
const tsVersion = Deno.version.typescript;

const cachedContext = {
app: { app_start_time: appStartTime },
device: { arch, processor_count: processorCount },
os: { name: osName } as { name: string; version?: string },
v8: { name: 'v8', version: v8Version },
typescript: { name: 'TypeScript', version: tsVersion },
};

return event;
}
const cachedSpanAttributes: Record<string, unknown> = {
'app.start_time': appStartTime,
// Convention uses 'device.archs' (string[]), but array attributes are not yet serialized.
// Once array serialization lands, this will start appearing on spans automatically.
'device.archs': [arch],
'device.processor_count': processorCount,
'os.name': osName,
'process.runtime.engine.name': 'v8',
'process.runtime.engine.version': v8Version,
};

getOSRelease()
.then(release => {
cachedContext.os.version = release;
cachedSpanAttributes['os.version'] = release;
})
.catch(() => {
// Ignore - os.version will be undefined
});

const _denoContextIntegration = (() => {
return {
name: INTEGRATION_NAME,
processEvent(event) {
return addDenoRuntimeContext(event);
event.contexts = {
...cachedContext,
...event.contexts,
};
return event;
Comment thread
chargome marked this conversation as resolved.
},
processSegmentSpan(span) {
safeSetSpanJSONAttributes(span, cachedSpanAttributes);
},
};
}) satisfies IntegrationFn;
Expand Down
Loading