diff --git a/CHANGELOG.md b/CHANGELOG.md index 98f8ea622b..62664f14ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,24 @@ This release contains upgrade of `sentry-android` dependency to major version 7. ### Features - Add Android profiles to React Native Profiling ([#3397](https://github.com/getsentry/sentry-react-native/pull/3397)) +- Add `Sentry.metrics` ([#3590](https://github.com/getsentry/sentry-react-native/pull/3590)) + + To learn more, see the [Set Up Metrics](https://docs.sentry.io/platforms/react-native/metrics/) guide. + + ```javascript + import * as Sentry from '@sentry/react-native'; + + Sentry.init({ + dsn: '___DSN___', + integrations: [ + Sentry.metrics.metricsAggregatorIntegration(), + ], + }); + + Sentry.metrics.increment("button_click", 1, { + tags: { system: "iOS", app_version: "1.0.0" }, + }); + ``` ### Fixes diff --git a/samples/expo/app/(tabs)/index.tsx b/samples/expo/app/(tabs)/index.tsx index 9a5b51c0b4..ac547fa01e 100644 --- a/samples/expo/app/(tabs)/index.tsx +++ b/samples/expo/app/(tabs)/index.tsx @@ -6,6 +6,8 @@ import { Text, View } from '@/components/Themed'; import { SENTRY_INTERNAL_DSN } from '@/utils/dsn'; import { HttpClient } from '@sentry/integrations'; import { setScopeProperties } from '@/utils/setScopeProperties'; +import { timestampInSeconds } from '@sentry/utils'; +import React from 'react'; const isRunningInExpoGo = Constants.appOwnership === 'expo' @@ -38,6 +40,7 @@ Sentry.init({ // default: [/.*/] failedRequestTargets: [/.*/], }), + Sentry.metrics.metricsAggregatorIntegration(), ); return integrations.filter(i => i.name !== 'Dedupe'); }, @@ -66,6 +69,25 @@ Sentry.init({ }); export default function TabOneScreen() { + const [componentMountStartTimestamp] = React.useState(() => { + return timestampInSeconds(); + }); + + React.useEffect(() => { + if (componentMountStartTimestamp) { + // Distributions help you get the most insights from your data by allowing you to obtain aggregations such as p90, min, max, and avg. + Sentry.metrics.distribution( + 'tab_one_mount_time', + timestampInSeconds() - componentMountStartTimestamp, + { + unit: "seconds", + }, + ); + } + // We only want this to run once. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + return ( Welcome to Sentry Expo Sample App! @@ -78,6 +100,7 @@ export default function TabOneScreen() {