@datadog/mobile-react-native

中文文档
3.11.0发布于 2026/10/20Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 261.5万

与 Datadog 交互的客户端反应本地模块

中文使用文档
文档目录7 节
  1. 设置
  2. 在 UI 中指定应用程序细节
  3. 初始化包含应用程序上下文的库
  4. 轨道视图导航
  5. 数据存储
  6. 机器人
  7. iOS系统

反应-国内监测

Datadog Real User Monitor(RUM) 使您能够可视化并分析应用程序个人用户的实时性能和用户行程.

设置

要安装国家预防机制,运行:

npm install @datadog/mobile-react-native

要安装 Yarn, 请运行 :

yarn add @datadog/mobile-react-native

最小反应原生版本:SDK支持回放原生版本0.63.4或更高. 与更古老版本的相容性不能保证出框.

版本数 1.0.0-rc5 更需要你拥有 compileSdkVersion = 31 在Android应用程序设置中,这意味着您应该使用Build Tools31版本,Android Gradle插件7版本和Gradle7版本或更高. 要修改版本,请更改 buildscript.ext 您应用程序的顶级块 build.gradle 文档。 Datadog建议使用回放原生版本0.67或更高.

在 UI 中指定应用程序细节

  1. 在那个 数据狗应用选择 UX 监视 > RUM 应用程序 > 新应用程序。 。 。 .
  2. 选择 react-native 作为您的应用程序类型.
  3. 提供新的应用程序名称以生成一个独特的 Datadog 应用程序 ID 和客户端符 .

image

为了保证数据的安全,您必须使用客户代号. 无法只使用 数据犬 API 密钥 来配置 @datadog/mobile-react-native 库,因为他们会暴露客户端。 关于设置客户代号的更多信息,请参见: 客户端调试文档。 。 。 .

初始化包含应用程序上下文的库

import {
    DatadogProvider,
    DatadogProviderConfiguration
} from '@datadog/mobile-react-native';

const datadogConfiguration = new DatadogProviderConfiguration(
    '<CLIENT_TOKEN>',
    '<ENVIRONMENT_NAME>',
    TrackingConsent.GRANTED,
    {
        rumConfiguration: {
            applicationId: '<RUM_APPLICATION_ID>',
            trackInteractions: true, // track User interactions (e.g.: Tap on buttons. You can use 'accessibilityLabel' element property to give tap action the name, otherwise element type will be reported)
            trackResources: true, // track XHR Resources
            trackFetchResources: true, // Optional: also track requests made with the global Expo Fetch implementation
            trackFrustrations: true, // track Frustrations
            trackErrors: true, // track errors
            nativeCrashReportEnabled: true, // Optional: enable or disable native crash reports
            sessionSampleRate: 80, // Optional: sample RUM sessions (here, 80% of session will be sent to Datadog. Default = 100%)
            resourceTraceSampleRate: 80, // Optional: sample tracing integrations for network calls between your app and your backend (here, 80% of calls to your instrumented backend will be linked from the RUM view to the APM view. Default = 20%)
            // You need to specify the hosts of your backends to enable tracing with these backends
            firstPartyHosts: ['example.com'], // matches 'example.com' and subdomains like 'api.example.com'
        },
        logsConfiguration: {
            logEventMapper: logEvent => {
                logEvent.message = `[CUSTOM] ${logEvent.message}`;
                return logEvent;
            }
        },
        traceConfiguration: {}
    }
);
// Optional: Select your Datadog website (one of "US1", "US3", "US5", "EU1", "AP1", "AP2", or "US1_FED"). Default is "US1".
datadogConfiguration.site = 'US1';
// Optional: set the reported service name (by default, it'll use the package name / bundleIdentifier of your Android / iOS app respectively)
datadogConfiguration.service = 'com.example.reactnative';
// Optional: let the SDK print internal logs (above or equal to the provided level. Default = undefined (meaning no logs))
datadogConfiguration.verbosity = SdkVerbosity.WARN;

export default function App() {
    return (
        <DatadogProvider configuration={datadogConfiguration}>
            <Navigation />
        </DatadogProvider>
    );
}

trackFetchResources 通过环球博览会发出的呼吁 fetch直接进口 expo/fetch 没有被拦截。 第 十 条 axios等客户的跟踪保留.

图QL 出错提取( 通过 DatadogLink({ trackErrors: true })用于 b. 通过会议提出的请求 expo/fetch 需要 Expo SDK 56 或 较晚, 如 旧 版本 expo/fetch 不执行 Response.clone()早些时候 版本, GraphQL 元数据仍然被报告,但响应错误没有.

轨道视图导航

因为React Introduct提供了广泛的库来创建屏幕导航,默认只支持手动视图跟踪. 您可以使用下列操作手动启动并停止视图 startView() 财务报告和审定财务报表 stopView 方法。 。 .

import {
    DdSdkReactNative,
    DdSdkReactNativeConfiguration,
    DdLogs,
    DdRum
} from '@datadog/mobile-react-native';

// Start a view with a unique view identifier, a custom view url, and an object to attach additional attributes to the view
DdRum.startView('ViewKey', 'ViewName', Date.now(), {
    'custom.foo': 'something'
});
// Stops a previously started view with the same unique view identifier, and an object to attach additional attributes to the view
DdRum.stopView('ViewKey', Date.now(), { 'custom.bar': 42 });

数据存储

机器人

在数据被上传到 Datadog 之前,它会被保存在应用程序缓存目录中的清晰文本中. 此缓存文件夹由 Android 应用程序沙盒,意味着在大多数设备上 此数据无法被其他应用程序读取. 然而,如果移动设备是根植的,或者某人 与 linux 内核相伴,存储的数据可能会变得可读.

iOS系统

在数据被上传到 Datadog 之前,它被保存在缓存目录中的清晰文本中( )Library/Caches(中文(简体) ) 您的电话 应用程序沙盒,它不能被安装在设备上的任何其他应用读取.

版本与发布记录

@datadog/mobile-react-native 共发布 118 个版本,首次发布于 2021/07/26;过去 12 个月发布了 32 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.11.0latest2026/10/2021 天前
3.10.02026/10/091 个月前
3.9.02026/10/011 个月前
3.8.02026/09/221 个月前
3.7.02026/09/032 个月前
3.6.02026/08/172 个月前

其他发布通道:next → 2.0.0-rc.0,v2 → 2.14.9。

关于 @datadog/mobile-react-native 的常见问题

@datadog/mobile-react-native 是什么?

与 Datadog 交互的客户端反应本地模块

如何安装 @datadog/mobile-react-native?

在项目目录运行 npm install @datadog/mobile-react-native,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.13.1)、react-native(>=0.63.4 <1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@datadog/mobile-react-native 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@datadog/mobile-react-native 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@datadog/mobile-react-native 可以商用吗?

@datadog/mobile-react-native 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@datadog/mobile-react-native 的下载量有多少?

根据 npm 官方下载统计,@datadog/mobile-react-native 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,614,571 次,日均约 87,152 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@datadog/mobile-react-native 还在维护吗?

最新版本 3.11.0 发布于 2026/10/20(21 天前);至今共发布 118 个版本,其中过去 12 个月发布了 32 个;首次发布于 2021/07/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。