Skip to content

Commit b748de5

Browse files
committed
add integration boilerplate
1 parent a858a07 commit b748de5

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { Event, EventProcessor, Integration } from '@sentry/types';
2+
3+
interface ContextLinesOptions {
4+
/**
5+
* Sets the number of context lines for each frame when loading a file.
6+
* Defaults to 7.
7+
*
8+
* Set to 0 to disable loading and inclusion of source files.
9+
**/
10+
frameContextLines?: number;
11+
}
12+
13+
/**
14+
* Collects source context lines around the line of a stackframe
15+
* This integration only works for stack frames pointing to JS that's directly embedded
16+
* in HTML files.
17+
* It DOES NOT work for stack frames pointing to JS files that are loaded by the browser.
18+
* For frames pointing to files, context lines are added during ingestino and symbolication
19+
* by attempting to download the JS files to the Sentry backend.
20+
*/
21+
export class ContextLines implements Integration {
22+
/**
23+
* @inheritDoc
24+
*/
25+
public static id: string = 'ContextLines';
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public name: string = ContextLines.id;
31+
32+
public constructor(
33+
private readonly _options: ContextLinesOptions = {
34+
frameContextLines: 0,
35+
},
36+
) {}
37+
38+
/**
39+
* @inheritDoc
40+
*/
41+
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void): void {
42+
addGlobalEventProcessor(event => this.addSourceContext(event));
43+
}
44+
45+
/** Processes an event and adds context lines */
46+
public addSourceContext(event: Event): Event {
47+
return event;
48+
}
49+
}

packages/browser/src/integrations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export { Breadcrumbs } from './breadcrumbs';
44
export { LinkedErrors } from './linkederrors';
55
export { HttpContext } from './httpcontext';
66
export { Dedupe } from './dedupe';
7+
export { ContextLines } from './contextlines';

0 commit comments

Comments
 (0)