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
11 changes: 0 additions & 11 deletions dev-packages/deno-integration-tests/node-suites/excludes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ const NO_CLIENT_REPORTS = [
'suites/tracing/sampling/test.ts',
];

// The stack frames of `@sentry/deno` have no `module`, and some have other `function` names. Their
// `post_context` also ends with an extra empty line, and in CommonJS scenarios the line numbers can
// be off.
const STACK_FRAMES_DIFFER = [
'suites/contextLines/filename-with-spaces/test.ts',
'suites/public-api/captureException/catched-error/test.ts',
'suites/tracing/postgresjs-tracing-channel/test.ts',
'suites/tracing/postgresjs/test.ts',
];

export const NODE_SUITES_EXCLUDE = [
'**/node_modules/**',
...NODE_ONLY,
Expand All @@ -122,5 +112,4 @@ export const NODE_SUITES_EXCLUDE = [
...NO_NODE_DEFAULT_INTEGRATION,
...GLOBAL_HANDLERS_DIFFER,
...NO_CLIENT_REPORTS,
...STACK_FRAMES_DIFFER,
];
4 changes: 4 additions & 0 deletions packages/deno/src/integrations/contextlines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ async function addSourceContextToFrames(frames: StackFrame[], contextLines: numb
if (sourceFile) {
try {
const lines = sourceFile.split('\n');
// A trailing newline ends the last line, it does not start another one.
if (lines[lines.length - 1] === '') {
lines.pop();
}
addContextToFrame(lines, frame, contextLines);
} catch {
// anomaly, being defensive in case
Expand Down
9 changes: 7 additions & 2 deletions packages/deno/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
requestDataIntegration,
stackParserFromStackParserOptions,
} from '@sentry/core';
import { detectOrchestrionSetup, getTracingIntegrations, getErrorIntegrations } from '@sentry/server-utils';
import {
createGetModuleFromFilename,
detectOrchestrionSetup,
getTracingIntegrations,
getErrorIntegrations,
} from '@sentry/server-utils';
import { DenoClient } from './client';
import { nodeStackLineParser } from '@sentry/core/server';
import { breadcrumbsIntegration } from './integrations/breadcrumbs';
Expand Down Expand Up @@ -61,7 +66,7 @@ export function getDefaultIntegrations(options: Options): Integration[] {
return [...getDefaultIntegrationsWithoutPerformance(), ...(hasSpansEnabled(options) ? getTracingIntegrations() : [])];
}

const defaultStackParser: StackParser = createStackParser(nodeStackLineParser());
const defaultStackParser: StackParser = createStackParser(nodeStackLineParser(createGetModuleFromFilename()));

/**
* The Sentry Deno SDK Client.
Expand Down
27 changes: 27 additions & 0 deletions packages/deno/test/contextlines.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Client, Event } from '@sentry/core';
import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts';
import { contextLinesIntegration } from '../build/esm/index.js';

Deno.test('does not add an empty line after the last line of a file to the context', async () => {
const filename = new URL(import.meta.url).pathname;
const lines = (await Deno.readTextFile(filename)).split('\n');
assertEquals(lines[lines.length - 1], '');
const lastLine = lines.length - 1;

const event: Event = {
exception: {
values: [{ stacktrace: { frames: [{ filename, lineno: lastLine, colno: 1, in_app: true }] } }],
},
};

const processed = await contextLinesIntegration({ frameContextLines: 2 }).processEvent?.(
event,
{},
undefined as unknown as Client,
);
const frame = processed?.exception?.values?.[0]?.stacktrace?.frames?.[0];

assertEquals(frame?.pre_context, lines.slice(lastLine - 3, lastLine - 1));
assertEquals(frame?.context_line, lines[lastLine - 1]);
assertEquals(frame?.post_context, []);
});
8 changes: 8 additions & 0 deletions packages/deno/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ Deno.test('getDefaultIntegrations is getDefaultIntegrationsWithoutPerformance pl
assertEquals(full.slice(0, base.length), base);
assertArrayIncludes(full.slice(base.length), ['Graphql', 'Postgres', 'OpenAI']);
});

Deno.test('the default stack parser fills the module of frames', () => {
const client = init({});
const frames = client
.getOptions()
.stackParser('Error\n at handle (file:///app/node_modules/postgres/src/connection.js:10:5)');
assertEquals(frames[0]?.module, 'postgres.src:connection');
});
2 changes: 1 addition & 1 deletion packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export { workerThreadsIntegration } from './integrations/workerThreads';
export { NODE_VERSION } from './nodeVersion';
export { defaultStackParser, getSentryRelease } from './sdk/api';
export { getHttpAgent, makeNodeTransport } from './transports';
export { createGetModuleFromFilename } from './utils/module';
export { createGetModuleFromFilename } from '@sentry/server-utils';

export { eveConversationHook, eveIntegration, getInstrumentedModuleNames } from '@sentry/server-utils';
export { eveInstrumentation } from './eve';
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/integrations/anr/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
uuid4,
} from '@sentry/core';
import { callFrameToStackFrame, watchdogTimer } from '@sentry/core/server';
import { createGetModuleFromFilename } from '@sentry/server-utils';
import { makeNodeTransport } from '../../transports';
import { createGetModuleFromFilename } from '../../utils/module';
import type { WorkerStartData } from './common';

type VoidFunction = () => void;
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/sdk/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { StackParser } from '@sentry/core';
import { createStackParser, GLOBAL_OBJ } from '@sentry/core';
import { _INTERNAL_getReleaseFromCommitEnv as getReleaseFromCommitEnv, nodeStackLineParser } from '@sentry/core/server';
import { createGetModuleFromFilename } from '../utils/module';
import { createGetModuleFromFilename } from '@sentry/server-utils';

/**
* Returns a release dynamically from environment variables.
Expand Down
1 change: 1 addition & 0 deletions packages/server-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export {
makeServeTunnelIntegration,
} from './integrations/serveTunnel';
export { instrumentTunnelServer as _INTERNAL_instrumentTunnelServer } from './utils/tunnelServer';
export { createGetModuleFromFilename } from './utils/module';
export { SentryMastraExporter } from './ai/mastra';
export { lruMemoizerIntegration } from './integrations/lru-memoizer';
export { mongoIntegration } from './integrations/mongodb';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { createGetModuleFromFilename } from '../../src';
import { createGetModuleFromFilename } from '../../src/utils/module';

describe('createGetModuleFromFilename', () => {
it.each([
Expand Down
Loading