Skip to content

RUM causing some network requests to fail #1272

@othmanAbdelaziz2001

Description

@othmanAbdelaziz2001

After we enabled RUM to 50% of our users for our RN App, we noticed a Spike in network errors being reported and users started reporting that app is becoming laggy as you can notice in the video.
https://github.com/user-attachments/assets/7026dc0d-956b-4d2c-bb67-08cfd6090515

the RUM setup we have is kinda straight forward.
Image

And When we looked at RUM resources events we found a lot of requests (more than 50% of all resources) are with status Code 1, we are pretty sure that our Infra at this time was just fine and when we disabled RUM everything went normal.

Image

After this we took an immediate action and we closed RUM feature flag for all users and error rates dropped dow a lot.
I will add some code sample for our datadog integration code


`import {
  DdSdkReactNative,
  DdSdkReactNativeConfiguration,
  TrackingConsent,
} from '@datadog/mobile-react-native';
import environment from 'react-native-config';
import CodePush from 'react-native-code-push';
import APIConfig from '::root/src/reactive-core/APIConfig';
import { isEnabled } from '@/libs/services/feature/src';
import {
  FirebaseRemoteConfigOption,
  LogVerbosity,
  verbosity,
} from '::root/src/constants/constants';
import { DdRumReactNavigationTracking } from '@datadog/mobile-react-navigation';
import { logger } from '.';
import { getRemoteConfig } from '::root/src/util/RemoteConfig';
import DeviceInfo from 'react-native-device-info';
import { getJSBundleVersion } from '@/util/app-version';
const globalData = global as typeof globalThis & {
  DDSdkInitialized: boolean;
  sessionID: string;
};
interface IRemoteConfigOptions {
  clientToken: string;
  applicationId: string;
  site: string;
  resourceTracingSamplingRate: number;
  sessionSamplingRate: number;
  trackBackgroundEvents: boolean;
  trackInteractions: boolean;
  trackResources: boolean;
  nativeCrashReportEnabled: boolean;
  trackErrors: boolean;
  loggingVerbosity: keyof typeof LogVerbosity;
}

export const initializeDatadog = async (
  navigationRef: React.RefObject<any>,
  remoteConfigOption: FirebaseRemoteConfigOption,
  loggingVerbosity?: LogVerbosity,
) => {
  if (globalData.DDSdkInitialized) {
    return;
  }
  try {
    const remoteConfiguration = await getDatadogRemoteConfig(
      remoteConfigOption,
    );
    const effectiveVerbosity =
      loggingVerbosity ??
      LogVerbosity[
        remoteConfiguration.loggingVerbosity as keyof typeof LogVerbosity
      ] ??
      LogVerbosity.Info;

    const config = new DdSdkReactNativeConfiguration(
      remoteConfiguration.clientToken,
      environment.ENV_NAME,
      remoteConfiguration.applicationId,
      remoteConfiguration.trackInteractions, // 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)
      remoteConfiguration.trackResources, // track XHR Resources
      remoteConfiguration.trackErrors, // track Errors

      TrackingConsent.GRANTED,
    );
    const storeVersion = DeviceInfo.getVersion();
    config.site = environment.DATADOG_SITE;
    config.serviceName = 'thndr-app';
    const update = await CodePush.getUpdateMetadata();
    const codePush = update?.label?.substring(1);
    // Optional: enable or disable native crash reports
    config.nativeCrashReportEnabled =
      remoteConfiguration.nativeCrashReportEnabled;
    // Optional: sample RUM sessions (here, 80% of session will be sent to Datadog. Default = 100%)
    config.firstPartyHosts = [
      environment.BASE_API as string,
      'prod-api',
    ];

    config.resourceTracingSamplingRate =
      remoteConfiguration.resourceTracingSamplingRate;
    config.sessionSamplingRate = remoteConfiguration.sessionSamplingRate;
    config.trackBackgroundEvents = remoteConfiguration.trackBackgroundEvents;
    config.versionSuffix = codePush;
    const logVerbosity = verbosity[effectiveVerbosity] ?? [];

    config.logEventMapper = event => {
      if (!logVerbosity.includes(event.status)) {
        return null;
      }

      event.context = {
        ...event.context,
        storeVersion,
      };
      return event;
    };
    config.resourceEventMapper = event => {
    // doing some ops
          return event;
        } else {
          return null;
        }
      }
      return event;
    };
    await DdSdkReactNative.initialize(config).then(() => {
      globalData.DDSdkInitialized = true;
      DdRumReactNavigationTracking.startTrackingViews(navigationRef.current);

      DdSdkReactNative.setAttributes({ sessionId: globalData.sessionID });
    });
  } catch (error) {
    logger.error(
      'Failed to initialize datadog',
      typeof error === 'object' ? error! : undefined,
    );
  }
};

function replaceSensitiveInfo(data: any) {
 // doing some ops
}
`
"@datadog/mobile-react-native": "^2.6.6",
"@datadog/mobile-react-navigation": "^2.6.6",
"react-native": "0.77.3",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions