diff --git forkSrcPrefix/src/platform-includes/performance/retrieve-transaction/javascript.mdx forkDstPrefix/src/platform-includes/performance/retrieve-transaction/javascript.mdx index 04a017c056348fb44754115d7d61b80a2ad352b7..e7b6180ad83f2862441b7f06b0e2da4cf9eb02fb 100644 --- forkSrcPrefix/src/platform-includes/performance/retrieve-transaction/javascript.mdx +++ forkDstPrefix/src/platform-includes/performance/retrieve-transaction/javascript.mdx @@ -1,12 +1,11 @@ ## Retrieve a Transaction -In cases where you want to attach spans to an already ongoing transaction, such as when grouping transactions, you can use `Sentry.getCurrentHub().getScope().getTransaction()`. This function will return a `Transaction` object when there is a running transaction on the scope, otherwise it returns `undefined`. If you are using our `BrowserTracing` integration, by default we attach the transaction to the Scope, so you could do something like this: +In cases where you want to attach spans to an already ongoing transaction, such as when grouping transactions, you can use `Sentry.getActiveTransaction()`. This function will return a `Transaction` object when there is a running transaction on the scope, otherwise it returns `undefined`. If you are using our `BrowserTracing` integration, by default we attach the transaction to the Scope, so you could do something like this: ```javascript function myJsFunction() { - const transaction = Sentry.getCurrentHub() - .getScope() - .getTransaction(); + const transaction = Sentry.getActiveTransaction(); + if (transaction) { const span = transaction.startChild({ op: "encode", diff --git forkSrcPrefix/src/platform-includes/performance/custom-performance-metrics/javascript.mdx forkDstPrefix/src/platform-includes/performance/custom-performance-metrics/javascript.mdx index 92baab7dc79366c61f739bd93503834c1fb06b9f..8a953fe82fb409b985c6917436af378bdd866aaf 100644 --- forkSrcPrefix/src/platform-includes/performance/custom-performance-metrics/javascript.mdx +++ forkDstPrefix/src/platform-includes/performance/custom-performance-metrics/javascript.mdx @@ -1,14 +1,16 @@ Adding custom metrics is supported in Sentry's JavaScript SDK version `7.0.0` and above. ```javascript -const transaction = Sentry.getCurrentHub().getScope().getTransaction(); +const transaction = Sentry.getActiveTransaction(); -// Record amount of memory used -transaction.setMeasurement('memoryUsed', 123, 'byte'); +if (transaction) { + // Record amount of memory used + transaction.setMeasurement('memoryUsed', 123, 'byte'); -// Record time when Footer component renders on page -transaction.setMeasurement('ui.footerComponent.render', 1.3, 'second'); + // Record time when Footer component renders on page + transaction.setMeasurement('ui.footerComponent.render', 1.3, 'second'); -// Record amount of times localStorage was read -transaction.setMeasurement('localStorageRead', 4); + // Record amount of times localStorage was read + transaction.setMeasurement('localStorageRead', 4); +} ``` diff --git forkSrcPrefix/src/platform-includes/performance/custom-performance-metrics/react-native.mdx forkDstPrefix/src/platform-includes/performance/custom-performance-metrics/react-native.mdx index de32407d87c50b6194d15d0ec405037f816ea193..1eb8f8be4afa78dcd06d3c2fbfb6647a6c9272d8 100644 --- forkSrcPrefix/src/platform-includes/performance/custom-performance-metrics/react-native.mdx +++ forkDstPrefix/src/platform-includes/performance/custom-performance-metrics/react-native.mdx @@ -3,14 +3,16 @@ Adding custom metrics is supported in Sentry's React Native SDK version `4.0.0` ```javascript import * as Sentry from '@sentry/react-native'; -const transaction = Sentry.getCurrentHub().getScope().getTransaction(); +const transaction = Sentry.getActiveTransaction(); -// Record amount of memory used -transaction.setMeasurement('memoryUsed', 123, 'byte'); +if (transaction) { + // Record amount of memory used + transaction.setMeasurement('memoryUsed', 123, 'byte'); -// Record time when Footer component renders on page -transaction.setMeasurement('ui.footerComponent.render', 1.3, 'second'); + // Record time when Footer component renders on page + transaction.setMeasurement('ui.footerComponent.render', 1.3, 'second'); -// Record amount of times localStorage was read -transaction.setMeasurement('localStorageRead', 4); + // Record amount of times localStorage was read + transaction.setMeasurement('localStorageRead', 4); +} ``` diff --git forkSrcPrefix/src/platform-includes/performance/enable-tracing/javascript.mdx forkDstPrefix/src/platform-includes/performance/enable-tracing/javascript.mdx index 82eeab254f7049d81e8b21e4730e035de0164be0..d074ff10f0d4072a8ae8152e965128fc66e69c1e 100644 --- forkSrcPrefix/src/platform-includes/performance/enable-tracing/javascript.mdx +++ forkDstPrefix/src/platform-includes/performance/enable-tracing/javascript.mdx @@ -1,11 +1,10 @@ -Install the tracing package: -```bash {tabTitle: ESM} -# Using yarn -yarn add @sentry/tracing -# Using npm -npm install --save @sentry/tracing +```javascript {tabTitle: ESM} +import { addTracingExtensions } from '@sentry/browser'; + +// Include tracing support +addTracingExtensions(); ``` ```html {tabTitle: CDN}