@coralogix/react-native-sdk

中文文档
1.0.26发布于 2025/09/04MITTypeScriptES Module近 30 天下载 3755

Official Coralogix SDK for react native

此软件包已被标记为弃用

@coralogix/react-native-sdk is deprecated. Please use @coralogix/react-native-plugin instead.

原始使用文档
文档目录12 节
  1. Links
  2. Usage
  3. View Tracking
  4. Instrumentation's
  5. Ignore Errors
  6. TraceParentInHeader
  7. beforeSend
  8. Proxy Url
  9. Troubleshooting
  10. 🔒 SSL Pinning (react-native-ssl-pinning)
  11. Android Setup
  12. iOS Setup

Official Coralogix SDK for React Native

npm version

** Note: SDK for React Native is currently in Beta **

Usage

To use Coralogix SDK, call CoralogixRum.init(options) at the soonest available moment after the app loads. This will initialize the SDK based on the options you provided.

import { CoralogixRum } from '@coralogix/react-native-sdk';

CoralogixRum.init({
  application: 'app-name',
  environment: 'production',
  public_key: 'abc-123-456',
  coralogixDomain: 'EU2',
  version: 'v1.0.3',
  labels: {
    payment: 'visa',
  },
  ignoreErrors: ['some error message to ignore'],
  sessionSampleRate: 100, // Percentage of overall sessions being tracked, Default to 100%
});

To provide contextual information or transmit manual logs, utilize the exported functions of CoralogixRum. Keep in mind that these functions will remain inactive until you've invoked CoralogixRum.init().

import { CoralogixRum } from '@coralogix/react-native-sdk';

// Update user context dynamically
CoralogixRum.setUserContext({
  user_id: '123',
  user_name: 'name',
  user_email: '[email protected]',
  user_metadata: {
    role: 'admin',
    // ...
  },
});

// Update custom labels dynamically
CoralogixRum.setLabels({
  ...CoralogixRum.getLabels(),
  paymentMethod: 'visa',
  userTheme: 'dark',
  // ...
});

// Update application context dynamically
CoralogixRum.setApplicationContext({
  application: 'app-name',
  version: '1.0.0',
});

CoralogixRum.log(CoralogixLogSeverity.Error, 'this is a log', { key: 'value' });
CoralogixRum.error('this is a log with error severity', { key: 'value' });

View Tracking

To track views, set the view context whenever a view changes.

CoralogixRum.setViewContext({
  view: 'Home',
});

You can automatically track view changes by using react-navigation.

<NavigationContainer
  ref={navigationRef}
  onStateChange={() => {
    const currentRouteName = navigationRef.current.getCurrentRoute().name;

    CoralogixRum.setViewContext({ view: currentRouteName });
  }}
>
  >{/* ... */}
</NavigationContainer>

Instrumentation's

Turn on/off specific instrumentation, default to all trues. Each instrumentation is responsible for which data the SDK will track and collect for you.

CoralogixRum.init({
  // ...
  instrumentations: {
    fetch: false,
    custom: true,
    errors: true,
  },
});

Ignore Errors

The ignoreErrors option allows you to exclude errors that meet specific criteria. This options accepts a set of strings and regular expressions to match against the event's error message. Use regular expressions for exact matching as strings remove partial matches.

import { CoralogixRum } from '@coralogix/react-native-sdk';

CoralogixRum.init({
  // ...
  ignoreErrors: [/Exact Match Error Message/, 'partial/match'],
});

TraceParentInHeader

Add trace context propagation in headers across service boundaries

CoralogixRum.init({
  // ...
  traceParentInHeader: {
    enabled: true,
    options: {
      // When the backend domain is different from the app domain, specifying backend domains is necessary.
      propagateTraceHeaderCorsUrls: [new RegExp('https://webapi.*')],
      // B3 propagation
      propagateB3TraceHeader: {
        singleHeader: true,
        multiHeader: true,
      },
      // Aws propagation
      propagateAwsXrayTraceHeader: true,
    },
  },
});

beforeSend

Enable event access and modification before sending to Coralogix, supporting content modification, and event discarding.

CoralogixRum.init({
  // ...
  beforeSend: (event) => {
    // Discard events from @company.com users.
    if (event.session_context.user_email?.endsWith('@company.com')) {
      return null;
    }

    // Redact sensitive information.
    event.session_context.user_email = '***@***';

    return event;
  },
});

Proxy Url

Proxy configuration to route requests.
By specifying a proxy URL, all RUM data will be directed to this URL via the POST method. However, it is necessary for this data to be subsequently relayed from the proxy to Coralogix. The Coralogix route for each request that is sent to the proxy is available in the request’s cxforward parameter (for example, https://www.your-proxy.com/endpoint?cxforward=https%3A%2F%2Fingress.eu1.rum-ingress-coralogix.com%2Fbrowser%2Fv1beta%2Flogs).

CoralogixRum.init({
  // ...
  coralogixDomain: 'EU1',
  proxyUrl: 'https://www.your-proxy.com/endpoint',
});

Troubleshooting

URL.origin is not implemented

  1. npm install react-native-url-polyfill
  2. At the top of your entry-point file (index.js) add: import "react-native-url-polyfill/auto"

🔒 SSL Pinning (react-native-ssl-pinning)


Initialize the SDK:

✅ Important: When SSL pinning is enabled (sslFetch: true), the regular fetch instrumentation must be disabled to avoid conflicts.

CoralogixRum.init({
  debug: true,
  instrumentations: {
    fetch: false, // Disable regular fetch instrumentation
    sslFetch: true, // Enable SSL pinning fetch instrumentation
  },
});

Android Setup

  1. Modify android/app/build.gradle:

    • At the top of the file, add:

      apply from: "../../node_modules/@coralogix/react-native-sdk/ssl/android/preBuildSetup.gradle"
      
    • Inside the android {} block, add:

      sourceSets {
        main {
          java.srcDirs += ['../../node_modules/@coralogix/react-native-sdk/ssl/android']
        }
      }
      
  2. Update MainApplication.java:

    • Add import:

      import com.coralogix.reactnativesdk.ssl.OkHttp3InterceptorPackage;
      
    • Add OkHttp3InterceptorPackage to the package list:

             override fun getPackages(): List<ReactPackage> =
             PackageList(this).packages.apply {
                 add(OkHttp3InterceptorPackage())
             }
      

iOS Setup

  1. Add Files in Xcode:

    • Open ios/YourProject.xcworkspace in Xcode.
    • Go to File > Add Files to "YourProject"...
    • Add all files from:
      node_modules/@coralogix/react-native-sdk/ssl/ios
      
      (includes NetworkInterceptor.h/.m, NetworkInterceptorEmitter.h/.m)
  2. Install Dependencies:

    cd ios && pod install
    

版本与发布记录

@coralogix/react-native-sdk 共发布 17 个版本,首次发布于 2024/05/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.26latest2025/09/041.2 年前
1.0.252025/06/241.4 年前
1.0.242025/05/301.5 年前
1.0.232025/05/211.5 年前
1.0.222025/04/291.5 年前
1.0.212025/04/231.5 年前

关于 @coralogix/react-native-sdk 的常见问题

@coralogix/react-native-sdk 是什么?

Official Coralogix SDK for react native注意:该包已被作者标记为弃用——@coralogix/react-native-sdk is deprecated. Please use @coralogix/react-native-plugin instead.

如何安装 @coralogix/react-native-sdk?

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

@coralogix/react-native-sdk 支持 TypeScript 吗?

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

@coralogix/react-native-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@coralogix/react-native-sdk 可以商用吗?

@coralogix/react-native-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@coralogix/react-native-sdk 的下载量有多少?

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

@coralogix/react-native-sdk 还在维护吗?

最新版本 1.0.26 发布于 2025/09/04(1.2 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/05/21。作者已将其标记为弃用,新项目建议寻找替代方案。