原生反应的官方 Corlogix SDK
** 注:SDK for React Industrial目前位于Beta**
链接
使用量
要使用 Corlogix SDK, 请打电话 CoralogixRum.init(options) 在应用程序加载后最快可用的时刻.
这将根据您提供的选项初始化 SDK .
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%
});
提供背景资料或传送手动日志,利用导出功能 CoralogixRum。 。 。 .
记住这些功能在您使用之前 将一直没有活动 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' });
查看跟踪
要跟踪视图,请在视图发生变化时设置视图上下文.
CoralogixRum.setViewContext({
view: 'Home',
});
您可以使用 反应导航。 。 。 .
<NavigationContainer
ref={navigationRef}
onStateChange={() => {
const currentRouteName = navigationRef.current.getCurrentRoute().name;
CoralogixRum.setViewContext({ view: currentRouteName });
}}
>
>{/* ... */}
</NavigationContainer>
仪器
打开/关闭特定仪器,默认为全部真伪. 每个仪器都负责SDK为您追踪和收集的数据.
CoralogixRum.init({
// ...
instrumentations: {
fetch: false,
custom: true,
errors: true,
},
});
忽略错误
忽略错误选项允许您排除符合特定标准的错误 . 此选项接受一组字符串和正则表达式来匹配事件的错误消息 . 使用正则表达式进行精确匹配, 因为字符串会删除部分匹配 .
import { CoralogixRum } from '@coralogix/react-native-sdk';
CoralogixRum.init({
// ...
ignoreErrors: [/Exact Match Error Message/, 'partial/match'],
});
TracePurent 信头
在信头中添加可跨服务界限的微量上下文传播
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,
},
},
});
在发送前
在发送到 Corlogix 之前启用事件访问和修改, 支持内容修改, 以及事件丢弃 .
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;
},
});
代理用户
路由请求的代理配置 .
通过指定代理 URL,所有 RUM 数据将通过 POST 方法被引导到此 URL.
然而,有必要将这些数据随后从代理中转发到Corlogix.
发送到代理服务器的每个请求的 Corlogix 路由可在请求的 cxforward 参数中找到
(例如, https://www.your-proxy.com/endpoint?cxforward=https%3A%2F%2Fingress.eu1.rum-ingress-coralogix.com%2Frowser%2Fv1beta%2Flogs) (中文(简体) ).
CoralogixRum.init({
// ...
coralogixDomain: 'EU1',
proxyUrl: 'https://www.your-proxy.com/endpoint',
});
解决问题
URL. 来源未执行
npm install react-native-url-polyfill- 在您输入点文件(index.js)上方添加:
import "react-native-url-polyfill/auto"
SSL Pinning(反应-内生- ssl-pinning)
初始化 SDK :
✅ 重要内容: 当 SSL 被启用时 (
sslFetch: true),经常fetch仪器 必须禁用 避免冲突.
CoralogixRum.init({
debug: true,
instrumentations: {
fetch: false, // Disable regular fetch instrumentation
sslFetch: true, // Enable SSL pinning fetch instrumentation
},
});
Android 设置
-
修改
android/app/build.gradle数字 :-
在那个 文件顶端,添加:
apply from: "../../node_modules/@coralogix/react-native-sdk/ssl/android/preBuildSetup.gradle" -
内部
android {}块,添加:sourceSets { main { java.srcDirs += ['../../node_modules/@coralogix/react-native-sdk/ssl/android'] } }
-
-
更新
MainApplication.java数字 :-
添加导入 :
import com.coralogix.reactnativesdk.ssl.OkHttp3InterceptorPackage; -
添加
OkHttp3InterceptorPackage到软件包列表:override fun getPackages(): List<ReactPackage> = PackageList(this).packages.apply { add(OkHttp3InterceptorPackage()) }
-
iOS 设置
-
在 Xcode 中添加文件 :
- 打开
ios/YourProject.xcworkspace在Xcode中. - 转到 文件 > 添加文件到“ 您的项目 ”...
- 从 :
(包括:node_modules/@coralogix/react-native-sdk/ssl/iosNetworkInterceptor.h/.m, (中文(简体) ),NetworkInterceptorEmitter.h/.m(中文(简体) )
- 打开
-
安装依赖 :
cd ios && pod install