首页 > 解决方案 > null 不是对象(评估'InstrumentationConstants_1.InstrumentationConstants.BREADCRUMB_VISIBILITY_CRASHES_ONLY')

问题描述

当我使用 appdynamics 检测我的 React 本机应用程序时,React 本机应用程序会出现运行时错误

'null 不是对象(评估'InstrumentationConstants_1.InstrumentationConstants.BREADCRUMB_VISIBILITY_CRASHES_ONLY')'

当我集成它时,它仍然可以很好地集成,但是一旦我设置应用程序停止运行。整合后我用过

Instrumentation.start({
  appKey: "AD-AAB-AAY-BHY",
  collectorURL: "https://col.eum-appdynamics.com",
});

import { Instrumentation } from "@appdynamics/react-native-agent";

在文件的顶部。

还做了 android 手动链接的所有步骤。

我在这里缺少什么吗?

标签: reactjsreact-nativeappdynamics

解决方案


我意识到已经有一段时间了,但无论如何我都会做出贡献,因为它也可以帮助其他人。

就我而言,在 iOS 中导入 Instrumentation 会导致此错误;这似乎是最新版本的 @appdynamics/react-native-agent (截至撰写时为 20.7.0 版)的问题。

我改为使用本机代码(在 AppDelegate.m 文件中)初始化 AppDynamics,如下所示:

#import <ADEUMInstrumentation/ADEumInstrumentation.h>

...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  ...

  ADEumAgentConfiguration *adeumAgentConfig = [[ADEumAgentConfiguration alloc] initWithAppKey:@"YOUR IOS KEY"];

  // AppDynamics swizzles some methods for making requests and may mess up other libraries; disable automatic instrumentation if it causes problems to you.
  adeumAgentConfig.enableAutoInstrument = NO;

  // Initialize AppDynamics
  [ADEumInstrumentation initWithConfiguration:adeumAgentConfig];

  // Leaving screnshots enabled may cause lag during touches; block screenshots if you experience that.
  [ADEumInstrumentation blockScreenshots];

  ...

  return YES;
}

有关更多信息,请查看 iOS 指南: https ://docs.appdynamics.com/display/PRO45/Instrument+an+iOS+Application

此外,我避免在 javascript 中导入 AppDynamics,方法是在运行时要求它,仅在 Android 中。

if (Platform.OS === 'android') {
    const { Instrumentation } = require('@appdynamics/react-native-agent');
    const appKey = 'YOUR ANDROID KEY';
    console.log(`Starting AppDynamics with key ${appKey}.`);
    Instrumentation.start({
      appKey,
    });
  }

推荐阅读