@datadog/mobile-react-native-apollo-client

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

A client-side React Native module to interact with Apollo Client and Datadog

原始使用文档
文档目录5 节
  1. Overview
  2. Setup
  3. Prerequisites
  4. Instrument your ApolloClient
  5. Redacting sensitive GraphQL data

React-Native Monitoring for @apollo/client

Overview

Monitor your GraphQL resources with Real User Monitoring (RUM) and perform the following:

  • Identify GraphQL queries and mutations
  • Identify GraphQL variables used in queries and mutations
  • Identify the GraphQL query payload
  • Capture GraphQL errors from the response

RUM supports GraphQL requests created using @apollo/client.

Setup

Prerequisites

Set up the RUM React Native SDK on your mobile React Native application. For more information, see RUM React Native Monitoring.

Add @apollo/client (v3.0+) and graphql (v15.0+) to your application following the official installation documentation.

Instrument your ApolloClient

If you initialize your ApolloClient with the uri parameter, initialize it with a HttpLink:

import { ApolloClient, HttpLink } from '@apollo/client';

// before
const apolloClient = new ApolloClient({
    uri: 'https://my.api.com/graphql'
});

// after
const apolloClient = new ApolloClient({
    link: new HttpLink({ uri: 'https://my.api.com/graphql' })
});

Import DatadogLink from @datadog/mobile-react-native-apollo-client and use it in your ApolloClient initialization:

import { ApolloClient, from, HttpLink } from '@apollo/client';
import { DatadogLink } from '@datadog/mobile-react-native-apollo-client';

const apolloClient = new ApolloClient({
    link: from([
        new DatadogLink(),
        new HttpLink({ uri: 'https://my.api.com/graphql' }) // always in last position
    ])
});

Configuration options

You can pass options to the DatadogLink constructor to control what data is collected:

new DatadogLink({
    trackVariables: true, // track GraphQL operation variables (default: true)
    trackPayload: false, // track the GraphQL query payload (default: false)
    trackErrors: false // track GraphQL errors from the response (default: false)
});
OptionDefaultDescription
trackVariablestrueCollect the variables passed to GraphQL operations. You can redact sensitive values using a resourceEventMapper.
trackPayloadfalseCollect the GraphQL query string (the operation body).
trackErrorsfalseCollect errors returned in the GraphQL response errors array. Only message, code, locations, and path fields are collected; all other fields (such as extensions details and stacktrace) are filtered out.

For more information on Apollo Client Links, refer to the official documentation.

Redacting sensitive GraphQL data

Use a resourceEventMapper in your Datadog configuration to redact or drop sensitive data from GraphQL attributes. Variables, payload, and errors are all stored as JSON strings in the resource event context.

const datadogConfiguration = new DatadogProviderConfiguration(
    '<CLIENT_TOKEN>',
    '<ENVIRONMENT_NAME>',
    TrackingConsent.GRANTED,
    {
        rumConfiguration: {
            applicationId: '<RUM_APPLICATION_ID>',
            trackResources: true
        }
    }
);

datadogConfiguration.resourceEventMapper = event => {
    const context = event.context as Record<string, string>;

    // Redact sensitive variables
    if (context['_dd.graphql.variables']) {
        const variables = JSON.parse(context['_dd.graphql.variables']);
        if (variables.password) {
            variables.password = '***';
        }
        context['_dd.graphql.variables'] = JSON.stringify(variables);
    }

    // Drop the payload entirely for a specific operation
    if (context['_dd.graphql.operation_name'] === 'TestOperation') {
        delete context['_dd.graphql.payload'];
    }

    // Redact error messages
    if (context['_dd.graphql.errors']) {
        const errors = JSON.parse(context['_dd.graphql.errors']);
        for (const error of errors) {
            error.message = error.message.replace(/email=\S+/g, 'email=***');
        }
        context['_dd.graphql.errors'] = JSON.stringify(errors);
    }

    return event;
};

版本与发布记录

@datadog/mobile-react-native-apollo-client 共发布 79 个版本,首次发布于 2023/11/02;过去 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-apollo-client 的常见问题

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

A client-side React Native module to interact with Apollo Client and Datadog

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

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

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

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

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

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

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

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

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

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

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

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