Skip to content

Commit

Permalink
Merge pull request #717 from DataDog/marcosaia/RUM-5938/track-rn-version
Browse files Browse the repository at this point in the history
[RUM-5938] Track React Native version
  • Loading branch information
marco-saia-datadog authored Aug 26, 2024
2 parents 5abd71b + faf0d24 commit 176e173
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/DdSdkReactNative.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright 2016-Present Datadog, Inc.
*/

import { version as reactNativeVersion } from 'react-native/package.json';
import { InteractionManager } from 'react-native';

import {
Expand Down Expand Up @@ -48,6 +49,8 @@ export class DdSdkReactNative {
private static readonly DD_SDK_VERSION = '_dd.sdk_version';
private static readonly DD_VERSION = '_dd.version';
private static readonly DD_VERSION_SUFFIX = '_dd.version_suffix';
private static readonly DD_REACT_NATIVE_VERSION =
'_dd.react_native_version';

private static wasAutoInstrumented = false;
private static features?: AutoInstrumentationConfiguration;
Expand Down Expand Up @@ -241,6 +244,12 @@ export class DdSdkReactNative {
] = `-${configuration.versionSuffix}`;
}

if (reactNativeVersion) {
configuration.additionalConfiguration[
DdSdkReactNative.DD_REACT_NATIVE_VERSION
] = `${reactNativeVersion}`;
}

return new DdSdkConfiguration(
configuration.clientToken,
configuration.env,
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/__tests__/DdSdkReactNative.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright 2016-Present Datadog, Inc.
*/

import { version as reactNativeVersion } from 'react-native/package.json';
import { NativeModules } from 'react-native';

import { DdSdkReactNativeConfiguration } from '../DdSdkReactNativeConfiguration';
Expand Down Expand Up @@ -114,6 +115,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.bundleLogsWithTraces).toBe(true);

expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -148,6 +150,7 @@ describe('DdSdkReactNative', () => {
TrackingConsent.GRANTED
);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -190,6 +193,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.env).toBe(fakeEnvName);
expect(ddSdkConfiguration.trackingConsent).toBe(fakeConsent);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -222,6 +226,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.applicationId).toBe(fakeAppId);
expect(ddSdkConfiguration.env).toBe(fakeEnvName);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -281,6 +286,7 @@ describe('DdSdkReactNative', () => {
expect(
ddSdkConfiguration.additionalConfiguration
).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -503,6 +509,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.applicationId).toBe(fakeAppId);
expect(ddSdkConfiguration.env).toBe(fakeEnvName);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -555,6 +562,7 @@ describe('DdSdkReactNative', () => {
}
]);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -604,6 +612,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.applicationId).toBe(fakeAppId);
expect(ddSdkConfiguration.env).toBe(fakeEnvName);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -804,6 +813,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.env).toBe(fakeEnvName);
expect(ddSdkConfiguration.serviceName).toBe(fakeServiceName);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -839,6 +849,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.env).toBe(fakeEnvName);
expect(ddSdkConfiguration.verbosity).toBe(SdkVerbosity.DEBUG);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -874,6 +885,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.env).toBe(fakeEnvName);
expect(ddSdkConfiguration.nativeViewTracking).toBe(true);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -909,6 +921,7 @@ describe('DdSdkReactNative', () => {
expect(ddSdkConfiguration.env).toBe(fakeEnvName);
expect(ddSdkConfiguration.nativeInteractionTracking).toBe(true);
expect(ddSdkConfiguration.additionalConfiguration).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -1115,6 +1128,7 @@ describe('DdSdkReactNative', () => {
expect(
ddSdkConfiguration.additionalConfiguration
).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down Expand Up @@ -1177,6 +1191,7 @@ describe('DdSdkReactNative', () => {
expect(
ddSdkConfiguration.additionalConfiguration
).toStrictEqual({
'_dd.react_native_version': reactNativeVersion,
'_dd.source': 'react-native',
'_dd.sdk_version': sdkVersion
});
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/__tests__/mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const privateProperties = {
'DD_SDK_VERSION',
'DD_VERSION',
'DD_VERSION_SUFFIX',
'DD_REACT_NATIVE_VERSION',
'wasAutoInstrumented',
'initializeNativeSDK',
'_initializeFromDatadogProviderWithConfigurationAsync',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright 2016-Present Datadog, Inc.
*/

import { version as reactNativeVersion } from 'react-native/package.json';
import { NativeModules } from 'react-native';

import { InitializationMode } from '../../../DdSdkReactNativeConfiguration';
Expand Down Expand Up @@ -64,6 +65,7 @@ describe('DatadogProvider', () => {
expect(receivedConfiguration).toMatchInlineSnapshot(`
DdSdkConfiguration {
"additionalConfiguration": {
"_dd.react_native_version": "${reactNativeVersion}",
"_dd.source": "react-native",
},
"applicationId": "fakeApplicationId",
Expand Down

0 comments on commit 176e173

Please sign in to comment.