Skip to content

Commit af9b1d8

Browse files
committed
No longer a breaking change
1 parent 2fe44fc commit af9b1d8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/node/src/integrations/contextlines.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { getCurrentHub } from '@sentry/core';
12
import { Event, EventProcessor, Integration } from '@sentry/types';
23
import { addContextToFrame } from '@sentry/utils';
34
import { readFile } from 'fs';
45
import { LRUMap } from 'lru_map';
56

7+
import { NodeClient } from '../client';
8+
69
const FILE_CONTENT_CACHE = new LRUMap<string, string | null>(100);
710

811
function readTextFileAsync(path: string): Promise<string> {
@@ -44,12 +47,17 @@ export class ContextLines implements Integration {
4447
* @inheritDoc
4548
*/
4649
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void): void {
50+
if (this._options.frameContextLines == undefined) {
51+
const initOptions = getCurrentHub().getClient<NodeClient>()?.getOptions();
52+
this._options.frameContextLines = initOptions?.frameContextLines;
53+
}
54+
4755
addGlobalEventProcessor(event => this.addToEvent(event));
4856
}
4957

5058
/** Processes an event and adds context lines */
5159
public async addToEvent(event: Event): Promise<Event> {
52-
const contextLines = this._options.frameContextLines != undefined ? this._options.frameContextLines : 7;
60+
const contextLines = this._options.frameContextLines == undefined ? 7 : this._options.frameContextLines;
5361

5462
const frames = event.exception?.values?.[0].stacktrace?.frames;
5563

packages/node/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export interface NodeOptions extends Options {
2020
/** HTTPS proxy certificates path */
2121
caCerts?: string;
2222

23+
/** Sets the number of context lines for each frame when loading a file. */
24+
frameContextLines?: number;
25+
2326
/** Callback that is executed when a fatal global error occurs. */
2427
onFatalError?(error: Error): void;
2528
}

0 commit comments

Comments
 (0)