Skip to content

Commit 2e392c6

Browse files
Create structure for Performance content to be common across all platforms (#2754)
* initial structure and include statements * disable Automatic for React Native * create PlatformSection for automatic instrumentation * explicitly disable content for React Native and fix syntax * feat: Add configure and install snippets for react native * feat: React Native group transactions Co-authored-by: jennmueng <[email protected]>
1 parent 344dbd0 commit 2e392c6

File tree

23 files changed

+304
-231
lines changed

23 files changed

+304
-231
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
```javascript
2+
import * as Sentry from "@sentry/browser";
3+
import { Integrations } from "@sentry/tracing";
4+
5+
Sentry.init({
6+
dsn: "___PUBLIC_DSN___",
7+
integrations: [
8+
new Integrations.BrowserTracing({
9+
beforeNavigate: context => {
10+
return {
11+
...context,
12+
// You could use your UI's routing library to find the matching
13+
// route template here. We don't have one right now, so do some basic
14+
// parameter replacements.
15+
name: location.pathname
16+
.replace(/\d+/g, "<digits>")
17+
.replace(/[a-f0-9]{32}/g, "<hash>"),
18+
};
19+
},
20+
}),
21+
],
22+
23+
// We recommend adjusting this value in production, or using tracesSampler
24+
// for finer control
25+
tracesSampleRate: 1.0,
26+
});
27+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```javascript {tabTitle: ESM}
2+
// If you're using one of our integration packages, like `@sentry/react` or
3+
// `@sentry/angular`, substitute its name for `@sentry/browser` here
4+
import * as Sentry from "@sentry/browser";
5+
6+
// If taking advantage of automatic instrumentation (highly recommended)
7+
import { Integrations as TracingIntegrations } from "@sentry/tracing";
8+
// Or, if only manually tracing
9+
// import * as _ from "@sentry/tracing"
10+
// Note: You MUST import the package in some way for tracing to work
11+
12+
Sentry.init({
13+
dsn: "___PUBLIC_DSN___",
14+
15+
// This enables automatic instrumentation (highly recommended), but is not
16+
// necessary for purely manual usage
17+
integrations: [new TracingIntegrations.BrowserTracing()],
18+
19+
// To set a uniform sample rate
20+
tracesSampleRate: 0.2
21+
22+
// Alternatively, to control sampling dynamically
23+
tracesSampler: samplingContext => { ... }
24+
});
25+
```
26+
27+
```javascript {tabTitle: CDN}
28+
Sentry.init({
29+
dsn: "___PUBLIC_DSN___",
30+
31+
// This enables automatic instrumentation (highly recommended), but is not
32+
// necessary for purely manual usage
33+
integrations: [new Sentry.Integrations.BrowserTracing()],
34+
35+
// To set a uniform sample rate
36+
tracesSampleRate: 0.2
37+
38+
// Alternatively, to control sampling dynamically
39+
tracesSampler: samplingContext => { ... }
40+
});
41+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```javascript
2+
import * as Sentry from "@sentry/react-native";
3+
4+
// Unlike Sentry on other platforms, you do not need to import anything to use tracing on React Native
5+
6+
Sentry.init({
7+
dsn: "___PUBLIC_DSN___",
8+
9+
// To set a uniform sample rate
10+
tracesSampleRate: 0.2
11+
12+
// Alternatively, to control sampling dynamically
13+
tracesSampler: samplingContext => { ... }
14+
});
15+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Instead, using `span.set_tag` and `span.set_data` preserves the details of this query using structured metadata. This could be done over `baseUrl`, `endpoint`, and `parameters`:
2+
3+
```javascript
4+
const baseUrl = "https://empowerplant.io";
5+
const endpoint = "/api/0/projects/ep/setup_form";
6+
const parameters = {
7+
user_id: 314159265358979323846264338327,
8+
tracking_id: "EasyAsABC123OrSimpleAsDoReMi",
9+
product_name: PlantToHumanTranslator,
10+
product_id: 161803398874989484820458683436563811772030917980576,
11+
};
12+
13+
const span = transaction.startChild({
14+
op: "request",
15+
description: "setup form",
16+
});
17+
18+
span.setTag("baseUrl", baseUrl);
19+
span.setTag("endpoint", endpoint);
20+
span.setData("parameters", parameters);
21+
// you may also find some parameters to be valuable as tags
22+
span.setData("user_id", parameters.user_id);
23+
http.get(`${base_url}/${endpoint}/`, (data = parameters));
24+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
After configuration, you will see both `pageload` and `navigation` when viewing transactions in sentry.io.
2+
3+
```javascript {tabTitle: ESM}
4+
// If you're using one of our integration packages, like `@sentry/react` or `@sentry/angular`,
5+
// substitute its name for `@sentry/browser` here
6+
import * as Sentry from "@sentry/browser";
7+
import { Integrations as TracingIntegrations } from "@sentry/tracing"; // Must import second
8+
9+
Sentry.init({
10+
dsn: "___PUBLIC_DSN___",
11+
12+
integrations: [
13+
new Integrations.BrowserTracing({
14+
tracingOrigins: ["localhost", "my-site-url.com", /^\//],
15+
// ... other options
16+
}),
17+
],
18+
19+
// We recommend adjusting this value in production, or using tracesSampler
20+
// for finer control
21+
tracesSampleRate: 1.0,
22+
});
23+
```
24+
25+
```javascript {tabTitle: CDN}
26+
Sentry.init({
27+
dsn: "___PUBLIC_DSN___",
28+
29+
integrations: [
30+
new Sentry.Integrations.BrowserTracing({
31+
tracingOrigins: ["localhost", "my-site-url.com", /^\//],
32+
// ... other options
33+
}),
34+
],
35+
36+
// We recommend adjusting this value in production, or using tracesSampler
37+
// for finer control
38+
tracesSampleRate: 1.0,
39+
});
40+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This is valid for all JavaScript SDKs (both backend and frontend) and works independently of the `Express`, `Http`, and `BrowserTracing` integrations.
2+
3+
```javascript
4+
const transaction = Sentry.startTransaction({ name: "test-transaction" });
5+
const span = transaction.startChild({ op: "functionX" }); // This function returns a Span
6+
// functionCallX
7+
span.finish(); // Remember that only finished spans will be sent with the transaction
8+
transaction.finish(); // Finishing the transaction will send it to Sentry
9+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```javascript
2+
import * as Sentry from "@sentry/browser";
3+
import { Integrations } from "@sentry/tracing";
4+
Sentry.init({
5+
dsn: "___PUBLIC_DSN___",
6+
integrations: [
7+
new Integrations.BrowserTracing({
8+
shouldCreateSpanForRequest: url => {
9+
// Do not create spans for outgoing requests to a `/health/` endpoint
10+
return !url.match(/\/health\/?$/);
11+
},
12+
}),
13+
],
14+
15+
// We recommend adjusting this value in production, or using tracesSampler
16+
// for finer control
17+
tracesSampleRate: 1.0,
18+
});
19+
```

src/platforms/javascript/common/performance/capturing/group-transactions.mdx renamed to src/includes/performance/group-transaction-example/javascript.mdx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
---
2-
title: Group Transactions
3-
sidebar_order: 50
4-
description: "Learn how to group transactions."
5-
---
6-
7-
When Sentry captures transactions, they are assigned a transaction name. This name is generally auto-generated by the Sentry SDK based on the framework integrations you are using. If you can't leverage the automatic transaction generation (or want to customize how transaction names are generated) you can use a global event processor that is registered when you initialize the SDK with your configuration.
8-
91
An example of doing this in a node.js application:
102

113
```javascript
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```javascript
2+
import { addGlobalEventProcessor } from "@sentry/react-native";
3+
4+
addGlobalEventProcessor(event => {
5+
// if event is a transaction event
6+
if (event.type === "transaction") {
7+
event.transaction = sanitizeTransactionName(event.transaction);
8+
}
9+
return event;
10+
});
11+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
```bash {tabTitle: ESM}
2+
# Using yarn
3+
yarn add @sentry/tracing
4+
5+
# Using npm
6+
npm install @sentry/tracing
7+
```
8+
9+
```html {tabTitle: CDN}
10+
<script
11+
<!--
12+
Note that `bundle.tracing.min.js` contains both `@sentry/browser` AND
13+
`@sentry/tracing`, and should therefore be used in place of
14+
`@sentry/browser`'s bundle rather than in addition to it.
15+
-->
16+
src="https://browser.sentry-cdn.com/{{ packages.version('sentry.javascript.browser') }}/bundle.tracing.min.js"
17+
integrity="sha384-{{ packages.checksum('sentry.javascript.browser', 'bundle.tracing.min.js', 'sha384-base64') }}"
18+
crossorigin="anonymous"
19+
></script>
20+
```

0 commit comments

Comments
 (0)