Skip to content

Commit 7725e68

Browse files
authored
feat(js): Add documentation for new ContextLines integration (#7564)
1 parent f1c6cbc commit 7725e68

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/includes/platforms/configuration/integrations/plugin.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,18 @@ Available options:
117117
<PlatformContent includePath="configuration/reporting-observer" />
118118

119119
</PlatformSection>
120+
121+
<PlatformSection supported={["javascript"]}>
122+
123+
### ContextLines
124+
125+
_Import name: `Sentry.Integrations.ContextLines`_
126+
127+
This integration adds source code from inline JavaScript of the current page's HTML (e.g. JS in `<script>` tags) to stack traces of captured errors.
128+
It _can't_ collect source code from assets referenced by your HTML (e.g. `<script src="..." />`).
129+
130+
The `ContextLines` integration is useful when you have inline JS code in HTML pages that can't be accessed by Sentry's backend, for example, due to a login-protected page.
131+
132+
<PlatformContent includePath="configuration/contextlines" />
133+
134+
</PlatformSection>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<SignInNote />
2+
3+
```javascript {tabTitle: ESM}
4+
import * as Sentry from "@sentry/browser";
5+
import { ContextLines } from "@sentry/integrations";
6+
7+
Sentry.init({
8+
dsn: "___PUBLIC_DSN___",
9+
integrations: [
10+
new ContextLines({
11+
// The number of lines to collect around each stack frame's line number
12+
// Defaults to 7
13+
frameContextLines: 7,
14+
}),
15+
],
16+
});
17+
```
18+
19+
```html {tabTitle: Loader}
20+
<script
21+
src="https://js.sentry-cdn.com/___PUBLIC_KEY___.min.js"
22+
crossorigin="anonymous"
23+
></script>
24+
<script
25+
src="https://browser.sentry-cdn.com/{{@inject packages.version('sentry.javascript.browser') }}/contextlines.min.js"
26+
integrity="sha384-{{@inject packages.checksum('sentry.javascript.browser', 'contextlines.min.js', 'sha384-base64') }}"
27+
crossorigin="anonymous"
28+
></script>
29+
30+
<script>
31+
Sentry.onLoad(function () {
32+
Sentry.init({
33+
integrations: [
34+
new Sentry.Integrations.ContextLines({
35+
// The number of lines to collect before and after each stack frame's line number
36+
// Defaults to 7
37+
frameContextLines: 7,
38+
}),
39+
],
40+
});
41+
});
42+
</script>
43+
```
44+
45+
```html {tabTitle: CDN}
46+
<script
47+
src="https://browser.sentry-cdn.com/{{@inject packages.version('sentry.javascript.browser') }}/bundle.tracing.min.js"
48+
integrity="sha384-{{@inject packages.checksum('sentry.javascript.browser', 'bundle.tracing.min.js', 'sha384-base64') }}"
49+
crossorigin="anonymous"
50+
></script>
51+
<script
52+
src="https://browser.sentry-cdn.com/{{@inject packages.version('sentry.javascript.browser') }}/contextlines.min.js"
53+
integrity="sha384-{{@inject packages.checksum('sentry.javascript.browser', 'contextlines.min.js', 'sha384-base64') }}"
54+
crossorigin="anonymous"
55+
></script>
56+
57+
<script>
58+
Sentry.init({
59+
dsn: "___PUBLIC_DSN___",
60+
integrations: [
61+
new Sentry.Integrations.ContextLines({
62+
// The number of lines to collect around each stack frame's line number
63+
// Defaults to 7
64+
frameContextLines: 7,
65+
}),
66+
],
67+
});
68+
</script>
69+
```

0 commit comments

Comments
 (0)