@@ -51,10 +51,8 @@ export class ContextLines implements Integration {
5151
5252 public constructor ( private readonly _options : ContextLinesOptions = { } ) { }
5353
54- /**
55- * @inheritDoc
56- */
57- public setupOnce ( addGlobalEventProcessor : ( callback : EventProcessor ) => void ) : void {
54+ /** Get's the number of context lines to add */
55+ private get _contextLines ( ) : number {
5856 // This is only here to copy frameContextLines from init options if it hasn't
5957 // been set via this integrations constructor.
6058 //
@@ -65,18 +63,22 @@ export class ContextLines implements Integration {
6563 this . _options . frameContextLines = initOptions ?. frameContextLines ;
6664 }
6765
68- const contextLines =
69- this . _options . frameContextLines !== undefined ? this . _options . frameContextLines : DEFAULT_LINES_OF_CONTEXT ;
66+ return this . _options . frameContextLines !== undefined ? this . _options . frameContextLines : DEFAULT_LINES_OF_CONTEXT ;
67+ }
7068
71- addGlobalEventProcessor ( event => this . addSourceContext ( event , contextLines ) ) ;
69+ /**
70+ * @inheritDoc
71+ */
72+ public setupOnce ( addGlobalEventProcessor : ( callback : EventProcessor ) => void ) : void {
73+ addGlobalEventProcessor ( event => this . addSourceContext ( event ) ) ;
7274 }
7375
7476 /** Processes an event and adds context lines */
75- public async addSourceContext ( event : Event , contextLines : number ) : Promise < Event > {
76- if ( contextLines > 0 && event . exception ?. values ) {
77+ public async addSourceContext ( event : Event ) : Promise < Event > {
78+ if ( this . _contextLines > 0 && event . exception ?. values ) {
7779 for ( const exception of event . exception . values ) {
7880 if ( exception . stacktrace ?. frames ) {
79- await this . _addSourceContextToFrames ( exception . stacktrace . frames , contextLines ) ;
81+ await this . addSourceContextToFrames ( exception . stacktrace . frames ) ;
8082 }
8183 }
8284 }
@@ -85,9 +87,12 @@ export class ContextLines implements Integration {
8587 }
8688
8789 /** Adds context lines to frames */
88- public async _addSourceContextToFrames ( frames : StackFrame [ ] , contextLines : number ) : Promise < void > {
90+ public async addSourceContextToFrames ( frames : StackFrame [ ] ) : Promise < void > {
91+ const contextLines = this . _contextLines ;
92+
8993 for ( const frame of frames ) {
90- if ( frame . filename ) {
94+ // Only add context if we have a filename and it hasn't already been added
95+ if ( frame . filename && frame . context_line === undefined ) {
9196 const sourceFile = await _readSourceFile ( frame . filename ) ;
9297
9398 if ( sourceFile ) {
0 commit comments