GeezerVison is showing github.com — fix(deno): Fill module and trim trailing context line in stack frames by sentry-junior[bot] · Pull Request #26641 · getsentry/sentry-javascript
fix(deno): Fill module and trim trailing context line in stack frames
#26641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.ts
(11)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
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 ,
] ;
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
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
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/[email protected] /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, []);
});
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');
});
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
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
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
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
File renamed without changes.
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.