@datadog/mobile-react-native-code-push 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -0
- package/lib/commonjs/index.js +30 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/codepush/src/index.d.ts +7 -0
- package/lib/typescript/core/src/DdSdkReactNative.d.ts +47 -0
- package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +59 -0
- package/lib/typescript/core/src/InternalLog.d.ts +11 -0
- package/lib/typescript/core/src/ProxyConfiguration.d.ts +56 -0
- package/lib/typescript/core/src/SdkVerbosity.d.ts +9 -0
- package/lib/typescript/core/src/TimeProvider.d.ts +20 -0
- package/lib/typescript/core/src/Timer.d.ts +21 -0
- package/lib/typescript/core/src/TrackingConsent.d.ts +8 -0
- package/lib/typescript/core/src/foundation.d.ts +7 -0
- package/lib/typescript/core/src/index.d.ts +9 -0
- package/lib/typescript/core/src/nativeModulesTypes.d.ts +168 -0
- package/lib/typescript/core/src/rum/instrumentation/DdEventsInterceptor.d.ts +11 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +17 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumUserInteractionTracking.d.ts +14 -0
- package/lib/typescript/core/src/rum/instrumentation/EventsInterceptor.d.ts +3 -0
- package/lib/typescript/core/src/rum/instrumentation/NoOpEventsInterceptor.d.ts +4 -0
- package/lib/typescript/core/src/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +20 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
- package/lib/typescript/core/src/types.d.ts +197 -0
- package/lib/typescript/core/src/version.d.ts +1 -0
- package/package.json +75 -0
- package/src/__tests__/index.test.ts +88 -0
- package/src/index.ts +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# React-Native Monitoring for AppCenter CodePush
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
**Note**: This package is an integration for the [`react-native-code-push`][1] library. Before using it, you must first install and setup the core [`mobile-react-native`][2] SDK.
|
|
6
|
+
|
|
7
|
+
To install with NPM, run:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @datadog/mobile-react-native-code-push
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
To install with Yarn, run:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add @datadog/mobile-react-native-code-push
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Initialize the SDK
|
|
20
|
+
|
|
21
|
+
To initialize the SDK, use `DatadogCodepush.initialize` instead of `DdSdkReactNative.initialize`:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import { DdSdkReactNativeConfiguration } from '@datadog/mobile-react-native';
|
|
25
|
+
import { DatadogCodepush } from '@datadog/mobile-react-native-code-push';
|
|
26
|
+
|
|
27
|
+
const config = new DdSdkReactNativeConfiguration(
|
|
28
|
+
'<CLIENT_TOKEN>',
|
|
29
|
+
'<ENVIRONMENT_NAME>',
|
|
30
|
+
'<RUM_APPLICATION_ID>',
|
|
31
|
+
true, // 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)
|
|
32
|
+
true, // track XHR Resources
|
|
33
|
+
true // track Errors
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
await DatadogCodepush.initialize(config);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
This method sets your reported version to the same value as the one the [`datadog-ci react-native codepush` command][3] uses when uploading your CodePush bundle and source maps.
|
|
40
|
+
|
|
41
|
+
## Using AppCenter CodePush without `@datadog/mobile-react-native-code-push`
|
|
42
|
+
|
|
43
|
+
If you use `datadog-ci react-native upload` to upload your CodePush bundle and source maps with a different format for the version, you can override the reported version in the SDK configuration object by using either:
|
|
44
|
+
|
|
45
|
+
- `versionSuffix` (recommended) to add a suffix to the commercial version of your app
|
|
46
|
+
- `version` to completely override the version
|
|
47
|
+
|
|
48
|
+
[1]: https://github.com/microsoft/react-native-code-push
|
|
49
|
+
[2]: https://github.com/DataDog/dd-sdk-reactnative/tree/main/packages/core
|
|
50
|
+
[3]: https://github.com/DataDog/datadog-ci/tree/master/src/commands/react-native#codepush
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DatadogCodepush = void 0;
|
|
7
|
+
|
|
8
|
+
var _mobileReactNative = require("@datadog/mobile-react-native");
|
|
9
|
+
|
|
10
|
+
var _reactNativeCodePush = _interopRequireDefault(require("react-native-code-push"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Use this class instead of DdSdkReactNative to initialize the Datadog SDK when using AppCenter CodePush.
|
|
16
|
+
*/
|
|
17
|
+
const DatadogCodepush = {
|
|
18
|
+
async initialize(configuration) {
|
|
19
|
+
const codePushUpdateMetadata = await _reactNativeCodePush.default.getUpdateMetadata();
|
|
20
|
+
|
|
21
|
+
if (codePushUpdateMetadata) {
|
|
22
|
+
configuration.versionSuffix = `codepush.${codePushUpdateMetadata.label}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return _mobileReactNative.DdSdkReactNative.initialize(configuration);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
};
|
|
29
|
+
exports.DatadogCodepush = DatadogCodepush;
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["DatadogCodepush","initialize","configuration","codePushUpdateMetadata","codePush","getUpdateMetadata","versionSuffix","label","DdSdkReactNative"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAEA;AACA;AACA;AACO,MAAMA,eAAe,GAAG;AAC3B,QAAMC,UAAN,CACIC,aADJ,EAEiB;AACb,UAAMC,sBAAsB,GAAG,MAAMC,6BAASC,iBAAT,EAArC;;AACA,QAAIF,sBAAJ,EAA4B;AACxBD,MAAAA,aAAa,CAACI,aAAd,GAA+B,YAAWH,sBAAsB,CAACI,KAAM,EAAvE;AACH;;AACD,WAAOC,oCAAiBP,UAAjB,CAA4BC,aAA5B,CAAP;AACH;;AAT0B,CAAxB","sourcesContent":["import { DdSdkReactNative } from '@datadog/mobile-react-native';\nimport type { DdSdkReactNativeConfiguration } from '@datadog/mobile-react-native';\nimport codePush from 'react-native-code-push';\n\n/**\n * Use this class instead of DdSdkReactNative to initialize the Datadog SDK when using AppCenter CodePush.\n */\nexport const DatadogCodepush = {\n async initialize(\n configuration: DdSdkReactNativeConfiguration\n ): Promise<void> {\n const codePushUpdateMetadata = await codePush.getUpdateMetadata();\n if (codePushUpdateMetadata) {\n configuration.versionSuffix = `codepush.${codePushUpdateMetadata.label}`;\n }\n return DdSdkReactNative.initialize(configuration);\n }\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DdSdkReactNative } from '@datadog/mobile-react-native';
|
|
2
|
+
import codePush from 'react-native-code-push';
|
|
3
|
+
/**
|
|
4
|
+
* Use this class instead of DdSdkReactNative to initialize the Datadog SDK when using AppCenter CodePush.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const DatadogCodepush = {
|
|
8
|
+
async initialize(configuration) {
|
|
9
|
+
const codePushUpdateMetadata = await codePush.getUpdateMetadata();
|
|
10
|
+
|
|
11
|
+
if (codePushUpdateMetadata) {
|
|
12
|
+
configuration.versionSuffix = `codepush.${codePushUpdateMetadata.label}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return DdSdkReactNative.initialize(configuration);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["DdSdkReactNative","codePush","DatadogCodepush","initialize","configuration","codePushUpdateMetadata","getUpdateMetadata","versionSuffix","label"],"mappings":"AAAA,SAASA,gBAAT,QAAiC,8BAAjC;AAEA,OAAOC,QAAP,MAAqB,wBAArB;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,eAAe,GAAG;AAC3B,QAAMC,UAAN,CACIC,aADJ,EAEiB;AACb,UAAMC,sBAAsB,GAAG,MAAMJ,QAAQ,CAACK,iBAAT,EAArC;;AACA,QAAID,sBAAJ,EAA4B;AACxBD,MAAAA,aAAa,CAACG,aAAd,GAA+B,YAAWF,sBAAsB,CAACG,KAAM,EAAvE;AACH;;AACD,WAAOR,gBAAgB,CAACG,UAAjB,CAA4BC,aAA5B,CAAP;AACH;;AAT0B,CAAxB","sourcesContent":["import { DdSdkReactNative } from '@datadog/mobile-react-native';\nimport type { DdSdkReactNativeConfiguration } from '@datadog/mobile-react-native';\nimport codePush from 'react-native-code-push';\n\n/**\n * Use this class instead of DdSdkReactNative to initialize the Datadog SDK when using AppCenter CodePush.\n */\nexport const DatadogCodepush = {\n async initialize(\n configuration: DdSdkReactNativeConfiguration\n ): Promise<void> {\n const codePushUpdateMetadata = await codePush.getUpdateMetadata();\n if (codePushUpdateMetadata) {\n configuration.versionSuffix = `codepush.${codePushUpdateMetadata.label}`;\n }\n return DdSdkReactNative.initialize(configuration);\n }\n};\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DdSdkReactNativeConfiguration } from '@datadog/mobile-react-native';
|
|
2
|
+
/**
|
|
3
|
+
* Use this class instead of DdSdkReactNative to initialize the Datadog SDK when using AppCenter CodePush.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DatadogCodepush: {
|
|
6
|
+
initialize(configuration: DdSdkReactNativeConfiguration): Promise<void>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
2
|
+
import type { TrackingConsent } from './TrackingConsent';
|
|
3
|
+
/**
|
|
4
|
+
* This class initializes the Datadog SDK, and sets up communication with the server.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DdSdkReactNative {
|
|
7
|
+
private static readonly DD_SOURCE_KEY;
|
|
8
|
+
private static readonly DD_SDK_VERSION;
|
|
9
|
+
private static readonly DD_SERVICE_NAME;
|
|
10
|
+
private static readonly DD_SDK_VERBOSITY_KEY;
|
|
11
|
+
private static readonly DD_NATIVE_VIEW_TRACKING_KEY;
|
|
12
|
+
private static readonly DD_VERSION;
|
|
13
|
+
private static readonly DD_VERSION_SUFFIX;
|
|
14
|
+
private static readonly DD_PROXY_TYPE_KEY;
|
|
15
|
+
private static readonly DD_PROXY_ADDRESS_KEY;
|
|
16
|
+
private static readonly DD_PROXY_PORT_KEY;
|
|
17
|
+
private static readonly DD_PROXY_USERNAME_KEY;
|
|
18
|
+
private static readonly DD_PROXY_PASSWORD_KEY;
|
|
19
|
+
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY;
|
|
20
|
+
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
21
|
+
private static wasInitialized;
|
|
22
|
+
/**
|
|
23
|
+
* Initializes the Datadog SDK.
|
|
24
|
+
* @param configuration the configuration for the SDK library
|
|
25
|
+
* @returns a Promise.
|
|
26
|
+
*/
|
|
27
|
+
static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
30
|
+
* @param attributes: The global context attributes.
|
|
31
|
+
* @returns a Promise.
|
|
32
|
+
*/
|
|
33
|
+
static setAttributes(attributes: object): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Set the user information.
|
|
36
|
+
* @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
|
|
37
|
+
* @returns a Promise.
|
|
38
|
+
*/
|
|
39
|
+
static setUser(user: object): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Set the tracking consent regarding the data collection.
|
|
42
|
+
* @param trackingConsent: One of TrackingConsent values.
|
|
43
|
+
* @returns a Promise.
|
|
44
|
+
*/
|
|
45
|
+
static setTrackingConsent(consent: TrackingConsent): Promise<void>;
|
|
46
|
+
private static enableFeatures;
|
|
47
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ProxyConfiguration } from './ProxyConfiguration';
|
|
2
|
+
import type { SdkVerbosity } from './SdkVerbosity';
|
|
3
|
+
import { TrackingConsent } from './TrackingConsent';
|
|
4
|
+
/**
|
|
5
|
+
* The SDK configuration class.
|
|
6
|
+
* It will be used to configure the SDK functionality at initialization.
|
|
7
|
+
*/
|
|
8
|
+
export declare class DdSdkReactNativeConfiguration {
|
|
9
|
+
readonly clientToken: string;
|
|
10
|
+
readonly env: string;
|
|
11
|
+
readonly applicationId: string;
|
|
12
|
+
readonly trackInteractions: boolean;
|
|
13
|
+
readonly trackResources: boolean;
|
|
14
|
+
readonly trackErrors: boolean;
|
|
15
|
+
readonly trackingConsent: TrackingConsent;
|
|
16
|
+
nativeCrashReportEnabled: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
|
|
19
|
+
*/
|
|
20
|
+
sampleRate?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Percentage of sampled RUM sessions. Range `0`-`100`.
|
|
23
|
+
*/
|
|
24
|
+
sessionSamplingRate: number;
|
|
25
|
+
/**
|
|
26
|
+
* Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
|
|
27
|
+
*/
|
|
28
|
+
resourceTracingSamplingRate: number;
|
|
29
|
+
site: string;
|
|
30
|
+
verbosity: SdkVerbosity | undefined;
|
|
31
|
+
nativeViewTracking: boolean;
|
|
32
|
+
proxyConfig?: ProxyConfiguration;
|
|
33
|
+
serviceName?: string;
|
|
34
|
+
firstPartyHosts: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Overrides the reported version of the app.
|
|
37
|
+
* Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
|
|
38
|
+
* Other special characters are converted to underscores.
|
|
39
|
+
*
|
|
40
|
+
* See https://docs.datadoghq.com/getting_started/tagging/#define-tags for more information on the format.
|
|
41
|
+
*
|
|
42
|
+
* Make sure you set it correctly, as it will have to match the one specified during the upload of your source maps and other mapping files.
|
|
43
|
+
*/
|
|
44
|
+
version?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Add a suffix to the reported version of the app.
|
|
47
|
+
* Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
|
|
48
|
+
* Other special characters are converted to underscores.
|
|
49
|
+
*
|
|
50
|
+
* See https://docs.datadoghq.com/getting_started/tagging/#define-tags for more information on the format.
|
|
51
|
+
*
|
|
52
|
+
* A dash (`-`) will be automatically added between the version and the suffix
|
|
53
|
+
*/
|
|
54
|
+
versionSuffix?: string;
|
|
55
|
+
additionalConfig: {
|
|
56
|
+
[k: string]: any;
|
|
57
|
+
};
|
|
58
|
+
constructor(clientToken: string, env: string, applicationId: string, trackInteractions?: boolean, trackResources?: boolean, trackErrors?: boolean, trackingConsent?: TrackingConsent);
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
2
|
+
/**
|
|
3
|
+
* /!\ DO NOT USE THIS IN YOUR APP /!\\
|
|
4
|
+
*
|
|
5
|
+
* This logger is only for debugging the Datadog SDK.
|
|
6
|
+
*/
|
|
7
|
+
export declare class InternalLog {
|
|
8
|
+
private static levelMap;
|
|
9
|
+
static verbosity: SdkVerbosity | undefined;
|
|
10
|
+
static log(message: string, verbosity: SdkVerbosity): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy server configuration.
|
|
3
|
+
*/
|
|
4
|
+
declare class ProxyConfiguration {
|
|
5
|
+
/**
|
|
6
|
+
* Proxy type.
|
|
7
|
+
*/
|
|
8
|
+
readonly type: ProxyType;
|
|
9
|
+
/**
|
|
10
|
+
* Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
|
|
11
|
+
*/
|
|
12
|
+
readonly address: string;
|
|
13
|
+
/**
|
|
14
|
+
* Proxy port.
|
|
15
|
+
*/
|
|
16
|
+
readonly port: number;
|
|
17
|
+
/**
|
|
18
|
+
* Username for Basic authentication scheme.
|
|
19
|
+
*
|
|
20
|
+
* Note: "SOCKS + authentication" scheme is not supported.
|
|
21
|
+
*/
|
|
22
|
+
readonly username?: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Password for Basic authentication scheme.
|
|
25
|
+
*/
|
|
26
|
+
readonly password?: string | undefined;
|
|
27
|
+
constructor(
|
|
28
|
+
/**
|
|
29
|
+
* Proxy type.
|
|
30
|
+
*/
|
|
31
|
+
type: ProxyType,
|
|
32
|
+
/**
|
|
33
|
+
* Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
|
|
34
|
+
*/
|
|
35
|
+
address: string,
|
|
36
|
+
/**
|
|
37
|
+
* Proxy port.
|
|
38
|
+
*/
|
|
39
|
+
port: number,
|
|
40
|
+
/**
|
|
41
|
+
* Username for Basic authentication scheme.
|
|
42
|
+
*
|
|
43
|
+
* Note: "SOCKS + authentication" scheme is not supported.
|
|
44
|
+
*/
|
|
45
|
+
username?: string | undefined,
|
|
46
|
+
/**
|
|
47
|
+
* Password for Basic authentication scheme.
|
|
48
|
+
*/
|
|
49
|
+
password?: string | undefined);
|
|
50
|
+
}
|
|
51
|
+
declare enum ProxyType {
|
|
52
|
+
HTTP = "http",
|
|
53
|
+
HTTPS = "https",
|
|
54
|
+
SOCKS = "socks"
|
|
55
|
+
}
|
|
56
|
+
export { ProxyConfiguration, ProxyType };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Timestamp structure holding the
|
|
3
|
+
*/
|
|
4
|
+
export declare type Timestamp = {
|
|
5
|
+
unix: number;
|
|
6
|
+
react_native: number | null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Simple class providing timestamps in milliseconds.
|
|
10
|
+
* If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TimeProvider {
|
|
13
|
+
private canUsePerformanceNow;
|
|
14
|
+
/** Keeps an average offset between the unix time and the provided timestamp. */
|
|
15
|
+
private baseOffset;
|
|
16
|
+
constructor();
|
|
17
|
+
getTimestamp(): Timestamp;
|
|
18
|
+
now(): number;
|
|
19
|
+
private performanceNow;
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TimeProvider } from './TimeProvider';
|
|
2
|
+
/**
|
|
3
|
+
* Simple timer which records time ticks. Shouldn't be re-used once stopped.
|
|
4
|
+
* All timestamps/durations returned are in milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
export default class Timer {
|
|
7
|
+
private timeProvider;
|
|
8
|
+
private times;
|
|
9
|
+
constructor(timeProvider?: TimeProvider);
|
|
10
|
+
get startTime(): number;
|
|
11
|
+
get stopTime(): number;
|
|
12
|
+
start(): void;
|
|
13
|
+
stop(): void;
|
|
14
|
+
recordTick(label: string): void;
|
|
15
|
+
hasTickFor(label: string): boolean;
|
|
16
|
+
durationBetween(startLabel: string, endLabel: string): number;
|
|
17
|
+
timeAt(label: string): number;
|
|
18
|
+
reset(): void;
|
|
19
|
+
private durationBetweenTicks;
|
|
20
|
+
private checkLabelExists;
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DdSdkConfiguration, DdLogsType, DdTraceType, DdRumType } from './types';
|
|
2
|
+
import type { DdNativeSdkType } from './nativeModulesTypes';
|
|
3
|
+
declare const DdSdk: DdNativeSdkType;
|
|
4
|
+
declare const DdLogs: DdLogsType;
|
|
5
|
+
declare const DdTrace: DdTraceType;
|
|
6
|
+
declare const DdRum: DdRumType;
|
|
7
|
+
export { DdSdkConfiguration, DdSdk, DdLogs, DdTrace, DdRum };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
2
|
+
import { DdSdkReactNative } from './DdSdkReactNative';
|
|
3
|
+
import { InternalLog } from './InternalLog';
|
|
4
|
+
import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
|
|
5
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
6
|
+
import { TrackingConsent } from './TrackingConsent';
|
|
7
|
+
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
8
|
+
import { RumActionType, ErrorSource } from './types';
|
|
9
|
+
export { DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A configuration object to initialize Datadog's features.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DdNativeSdkConfiguration {
|
|
5
|
+
readonly clientToken: string;
|
|
6
|
+
readonly env: string;
|
|
7
|
+
readonly applicationId: string;
|
|
8
|
+
readonly nativeCrashReportEnabled: boolean;
|
|
9
|
+
readonly sampleRate: number;
|
|
10
|
+
readonly site: string;
|
|
11
|
+
readonly trackingConsent: string;
|
|
12
|
+
readonly additionalConfig: object;
|
|
13
|
+
constructor(clientToken: string, env: string, applicationId: string, nativeCrashReportEnabled: boolean, sampleRate: number, site: string, trackingConsent: string, additionalConfig: object);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The entry point to initialize Datadog's features.
|
|
17
|
+
*/
|
|
18
|
+
export declare type DdNativeSdkType = {
|
|
19
|
+
/**
|
|
20
|
+
* Initializes Datadog's features.
|
|
21
|
+
* @param configuration: The configuration to use.
|
|
22
|
+
*/
|
|
23
|
+
initialize(configuration: DdNativeSdkConfiguration): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
26
|
+
* @param attributes: The global context attributes.
|
|
27
|
+
*/
|
|
28
|
+
setAttributes(attributes: object): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Set the user information.
|
|
31
|
+
* @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
|
|
32
|
+
*/
|
|
33
|
+
setUser(user: object): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Set the tracking consent regarding the data collection.
|
|
36
|
+
* @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
|
|
37
|
+
*/
|
|
38
|
+
setTrackingConsent(trackingConsent: string): Promise<void>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The entry point to use Datadog's Logs feature.
|
|
42
|
+
*/
|
|
43
|
+
export declare type DdNativeLogsType = {
|
|
44
|
+
/**
|
|
45
|
+
* Send a log with level debug.
|
|
46
|
+
* @param message: The message to send.
|
|
47
|
+
* @param context: The additional context to send.
|
|
48
|
+
*/
|
|
49
|
+
debug(message: string, context?: object): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Send a log with level info.
|
|
52
|
+
* @param message: The message to send.
|
|
53
|
+
* @param context: The additional context to send.
|
|
54
|
+
*/
|
|
55
|
+
info(message: string, context?: object): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Send a log with level warn.
|
|
58
|
+
* @param message: The message to send.
|
|
59
|
+
* @param context: The additional context to send.
|
|
60
|
+
*/
|
|
61
|
+
warn(message: string, context?: object): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Send a log with level error.
|
|
64
|
+
* @param message: The message to send.
|
|
65
|
+
* @param context: The additional context to send.
|
|
66
|
+
*/
|
|
67
|
+
error(message: string, context?: object): Promise<void>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The entry point to use Datadog's Trace feature.
|
|
71
|
+
*/
|
|
72
|
+
export declare type DdNativeTraceType = {
|
|
73
|
+
/**
|
|
74
|
+
* Start a span, and returns a unique identifier for the span.
|
|
75
|
+
* @param operation: The operation name of the span.
|
|
76
|
+
* @param context: The additional context to send.
|
|
77
|
+
* @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
|
|
78
|
+
*/
|
|
79
|
+
startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Finish a started span.
|
|
82
|
+
* @param spanId: The unique identifier of the span.
|
|
83
|
+
* @param context: The additional context to send.
|
|
84
|
+
* @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
85
|
+
*/
|
|
86
|
+
finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The entry point to use Datadog's RUM feature.
|
|
90
|
+
*/
|
|
91
|
+
export declare type DdNativeRumType = {
|
|
92
|
+
/**
|
|
93
|
+
* Start tracking a RUM View.
|
|
94
|
+
* @param key: The view unique key identifier.
|
|
95
|
+
* @param name: The view name.
|
|
96
|
+
* @param context: The additional context to send.
|
|
97
|
+
* @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
|
|
98
|
+
*/
|
|
99
|
+
startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Stop tracking a RUM View.
|
|
102
|
+
* @param key: The view unique key identifier.
|
|
103
|
+
* @param context: The additional context to send.
|
|
104
|
+
* @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
105
|
+
*/
|
|
106
|
+
stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Start tracking a RUM Action.
|
|
109
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
110
|
+
* @param name: The action name.
|
|
111
|
+
* @param context: The additional context to send.
|
|
112
|
+
* @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
|
|
113
|
+
*/
|
|
114
|
+
startAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Stop tracking the ongoing RUM Action.
|
|
117
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
118
|
+
* @param name: The action name.
|
|
119
|
+
* @param context: The additional context to send.
|
|
120
|
+
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
121
|
+
*/
|
|
122
|
+
stopAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Add a RUM Action.
|
|
125
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
126
|
+
* @param name: The action name.
|
|
127
|
+
* @param context: The additional context to send.
|
|
128
|
+
* @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
129
|
+
*/
|
|
130
|
+
addAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Start tracking a RUM Resource.
|
|
133
|
+
* @param key: The resource unique key identifier.
|
|
134
|
+
* @param method: The resource method (GET, POST, …).
|
|
135
|
+
* @param url: The resource url.
|
|
136
|
+
* @param context: The additional context to send.
|
|
137
|
+
* @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
|
|
138
|
+
*/
|
|
139
|
+
startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Stop tracking a RUM Resource.
|
|
142
|
+
* @param key: The resource unique key identifier.
|
|
143
|
+
* @param statusCode: The resource status code.
|
|
144
|
+
* @param kind: The resource's kind (xhr, document, image, css, font, …).
|
|
145
|
+
* @param size: The resource size in bytes. If size is unknown, use -1.
|
|
146
|
+
* @param context: The additional context to send.
|
|
147
|
+
* @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
148
|
+
*/
|
|
149
|
+
stopResource(key: string, statusCode: number, kind: ResourceKind, size?: number, context?: object, timestampMs?: number): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Add a RUM Error.
|
|
152
|
+
* @param message: The error message.
|
|
153
|
+
* @param source: The error source (network, source, console, webview, custom).
|
|
154
|
+
* @param stacktrace: The error stacktrace.
|
|
155
|
+
* @param context: The additional context to send.
|
|
156
|
+
* @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
157
|
+
*/
|
|
158
|
+
addError(message: string, source: ErrorSource, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.
|
|
161
|
+
* @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
|
|
162
|
+
*/
|
|
163
|
+
addTiming(name: string): Promise<void>;
|
|
164
|
+
};
|
|
165
|
+
declare type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
|
|
166
|
+
declare type ResourceKind = 'image' | 'xhr' | 'beacon' | 'css' | 'document' | 'fetch' | 'font' | 'js' | 'media' | 'other' | 'native';
|
|
167
|
+
declare type ErrorSource = 'NETWORK' | 'SOURCE' | 'CONSOLE' | 'WEBVIEW' | 'CUSTOM';
|
|
168
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type EventsInterceptor from './EventsInterceptor';
|
|
2
|
+
export declare const UNKNOWN_TARGET_NAME = "unknown_target";
|
|
3
|
+
export declare class DdEventsInterceptor implements EventsInterceptor {
|
|
4
|
+
static ACTION_EVENT_DROPPED_WARN_MESSAGE: string;
|
|
5
|
+
private debouncingStartedTimestamp;
|
|
6
|
+
interceptOnPress(...args: any[]): void;
|
|
7
|
+
private handleTargetEvent;
|
|
8
|
+
private resolveTargetName;
|
|
9
|
+
private resolveElementTypeName;
|
|
10
|
+
private findClosestActionLabel;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DdRumErrorTracking {
|
|
5
|
+
private static isTracking;
|
|
6
|
+
private static isInDefaultErrorHandler;
|
|
7
|
+
private static defaultErrorHandler;
|
|
8
|
+
private static defaultConsoleError;
|
|
9
|
+
/**
|
|
10
|
+
* Starts tracking errors and sends a RUM Error event every time an error is detected.
|
|
11
|
+
*/
|
|
12
|
+
static startTracking(): void;
|
|
13
|
+
static onGlobalError(error: any, isFatal?: boolean): void;
|
|
14
|
+
static onConsoleError(...params: unknown[]): void;
|
|
15
|
+
private static getErrorMessage;
|
|
16
|
+
private static getErrorStackTrace;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
3
|
+
* For now we are only covering the "onPress" events.
|
|
4
|
+
*/
|
|
5
|
+
export declare class DdRumUserInteractionTracking {
|
|
6
|
+
private static isTracking;
|
|
7
|
+
private static eventsInterceptor;
|
|
8
|
+
/**
|
|
9
|
+
* Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.
|
|
10
|
+
* Please note that we are only considering as valid - for - tracking only the user interactions that have
|
|
11
|
+
* a visible output (either an UI state change or a Resource request)
|
|
12
|
+
*/
|
|
13
|
+
static startTracking(): void;
|
|
14
|
+
}
|
package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DdRumResourceTracking {
|
|
5
|
+
private static isTracking;
|
|
6
|
+
private static requestProxy;
|
|
7
|
+
/**
|
|
8
|
+
* Starts tracking resources and sends a RUM Resource event every time a network request is detected.
|
|
9
|
+
*/
|
|
10
|
+
static startTracking({ tracingSamplingRate, firstPartyHosts }: {
|
|
11
|
+
tracingSamplingRate: number;
|
|
12
|
+
firstPartyHosts: string[];
|
|
13
|
+
}): void;
|
|
14
|
+
static stopTracking(): void;
|
|
15
|
+
}
|
package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Hostname } from './firstPartyHosts';
|
|
2
|
+
export declare type DdRumResourceTracingAttributes = {
|
|
3
|
+
tracingStrategy: 'KEEP';
|
|
4
|
+
traceId: string;
|
|
5
|
+
spanId: string;
|
|
6
|
+
samplingPriorityHeader: '1';
|
|
7
|
+
} | {
|
|
8
|
+
tracingStrategy: 'DISCARD';
|
|
9
|
+
traceId?: void;
|
|
10
|
+
spanId?: void;
|
|
11
|
+
samplingPriorityHeader: '0';
|
|
12
|
+
};
|
|
13
|
+
export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegex, tracingSamplingRate }: {
|
|
14
|
+
hostname: Hostname | null;
|
|
15
|
+
firstPartyHostsRegex: RegExp;
|
|
16
|
+
tracingSamplingRate: number;
|
|
17
|
+
}) => DdRumResourceTracingAttributes;
|
|
18
|
+
export declare function generateTraceId(): string;
|
package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare type Hostname = {
|
|
2
|
+
_type: 'Hostname';
|
|
3
|
+
} & string;
|
|
4
|
+
export declare const NO_MATCH_REGEX: RegExp;
|
|
5
|
+
export declare const firstPartyHostsRegexBuilder: (firstPartyHosts: string[]) => RegExp;
|
|
6
|
+
export declare const isHostFirstParty: (hostname: Hostname, firstPartyHostsRegex: RegExp) => boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ResourceKind } from '../../../../../../../core/src/types';
|
|
2
|
+
import type { DdRumResourceTracingAttributes } from '../distributedTracing';
|
|
3
|
+
export interface RUMResource {
|
|
4
|
+
key: string;
|
|
5
|
+
request: {
|
|
6
|
+
method: string;
|
|
7
|
+
url: string;
|
|
8
|
+
kind: ResourceKind;
|
|
9
|
+
};
|
|
10
|
+
tracingAttributes: DdRumResourceTracingAttributes;
|
|
11
|
+
response: {
|
|
12
|
+
statusCode: number;
|
|
13
|
+
size: number;
|
|
14
|
+
};
|
|
15
|
+
timings: {
|
|
16
|
+
startTime: number;
|
|
17
|
+
stopTime: number;
|
|
18
|
+
responseStartTime?: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RUMResource } from '../../domain/interfaces/RumResource';
|
|
2
|
+
declare type ResourceMapper = (resource: RUMResource) => RUMResource | null;
|
|
3
|
+
export declare class ResourceReporter {
|
|
4
|
+
private mappers;
|
|
5
|
+
constructor(resourceMappers: ResourceMapper[]);
|
|
6
|
+
reportResource: (resource: RUMResource) => void;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RUMResource } from '../../domain/interfaces/RumResource';
|
|
2
|
+
/**
|
|
3
|
+
* Filters RN symbolicate calls and Expo logs calls that happen only in dev.
|
|
4
|
+
* @param resource RUMResource
|
|
5
|
+
*/
|
|
6
|
+
export declare const filterDevResource: (resource: RUMResource) => RUMResource | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface Timing {
|
|
2
|
+
/**
|
|
3
|
+
* Time relative (absolute in case of iOS) to some point, in ns.
|
|
4
|
+
*/
|
|
5
|
+
startTime: number;
|
|
6
|
+
/**
|
|
7
|
+
* Duration in ns.
|
|
8
|
+
*/
|
|
9
|
+
duration: number;
|
|
10
|
+
}
|
|
11
|
+
interface ResourceTimings {
|
|
12
|
+
firstByte: Timing;
|
|
13
|
+
download: Timing;
|
|
14
|
+
fetch: Timing;
|
|
15
|
+
}
|
|
16
|
+
export declare function createTimings(startTime: number, responseStartTime: number, responseEndTime: number): ResourceTimings;
|
|
17
|
+
export {};
|
package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="react-native" />
|
|
2
|
+
import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
|
|
3
|
+
import { RequestProxy } from '../domain/interfaces/RequestProxy';
|
|
4
|
+
import type { ResourceReporter } from './DatadogRumResource/ResourceReporter';
|
|
5
|
+
export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
|
|
6
|
+
export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
|
|
7
|
+
export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
|
|
8
|
+
export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
|
|
9
|
+
export declare const ORIGIN_RUM = "rum";
|
|
10
|
+
interface XHRProxyProviders {
|
|
11
|
+
xhrType: typeof XMLHttpRequest;
|
|
12
|
+
resourceReporter: ResourceReporter;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Proxies XMLHTTPRequest to track resources.
|
|
16
|
+
*/
|
|
17
|
+
export declare class XHRProxy extends RequestProxy {
|
|
18
|
+
private providers;
|
|
19
|
+
private static originalXhrOpen;
|
|
20
|
+
private static originalXhrSend;
|
|
21
|
+
constructor(providers: XHRProxyProviders);
|
|
22
|
+
onTrackingStart: (context: RequestProxyOptions) => void;
|
|
23
|
+
onTrackingStop: () => void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A configuration object to initialize Datadog's features.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DdSdkConfiguration {
|
|
5
|
+
readonly clientToken: string;
|
|
6
|
+
readonly env: string;
|
|
7
|
+
readonly applicationId: string;
|
|
8
|
+
readonly nativeCrashReportEnabled: boolean;
|
|
9
|
+
readonly sampleRate: number;
|
|
10
|
+
readonly site: string;
|
|
11
|
+
readonly trackingConsent: string;
|
|
12
|
+
readonly additionalConfig: object;
|
|
13
|
+
constructor(clientToken: string, env: string, applicationId: string, nativeCrashReportEnabled: boolean, sampleRate: number, site: string, trackingConsent: string, additionalConfig: object);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The entry point to initialize Datadog's features.
|
|
17
|
+
*/
|
|
18
|
+
export declare type DdSdkType = {
|
|
19
|
+
/**
|
|
20
|
+
* Initializes Datadog's features.
|
|
21
|
+
* @param configuration: The configuration to use.
|
|
22
|
+
*/
|
|
23
|
+
initialize(configuration: DdSdkConfiguration): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
26
|
+
* @param attributes: The global context attributes.
|
|
27
|
+
*/
|
|
28
|
+
setAttributes(attributes: object): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Set the user information.
|
|
31
|
+
* @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
|
|
32
|
+
*/
|
|
33
|
+
setUser(user: object): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Set the tracking consent regarding the data collection.
|
|
36
|
+
* @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
|
|
37
|
+
*/
|
|
38
|
+
setTrackingConsent(trackingConsent: string): Promise<void>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The entry point to use Datadog's Logs feature.
|
|
42
|
+
*/
|
|
43
|
+
export declare type DdLogsType = {
|
|
44
|
+
/**
|
|
45
|
+
* Send a log with level debug.
|
|
46
|
+
* @param message: The message to send.
|
|
47
|
+
* @param context: The additional context to send.
|
|
48
|
+
*/
|
|
49
|
+
debug(message: string, context?: object): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Send a log with level info.
|
|
52
|
+
* @param message: The message to send.
|
|
53
|
+
* @param context: The additional context to send.
|
|
54
|
+
*/
|
|
55
|
+
info(message: string, context?: object): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Send a log with level warn.
|
|
58
|
+
* @param message: The message to send.
|
|
59
|
+
* @param context: The additional context to send.
|
|
60
|
+
*/
|
|
61
|
+
warn(message: string, context?: object): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Send a log with level error.
|
|
64
|
+
* @param message: The message to send.
|
|
65
|
+
* @param context: The additional context to send.
|
|
66
|
+
*/
|
|
67
|
+
error(message: string, context?: object): Promise<void>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The entry point to use Datadog's Trace feature.
|
|
71
|
+
*/
|
|
72
|
+
export declare type DdTraceType = {
|
|
73
|
+
/**
|
|
74
|
+
* Start a span, and returns a unique identifier for the span.
|
|
75
|
+
* @param operation: The operation name of the span.
|
|
76
|
+
* @param context: The additional context to send.
|
|
77
|
+
* @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
|
|
78
|
+
*/
|
|
79
|
+
startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Finish a started span.
|
|
82
|
+
* @param spanId: The unique identifier of the span.
|
|
83
|
+
* @param context: The additional context to send.
|
|
84
|
+
* @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
85
|
+
*/
|
|
86
|
+
finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The entry point to use Datadog's RUM feature.
|
|
90
|
+
*/
|
|
91
|
+
export declare type DdRumType = {
|
|
92
|
+
/**
|
|
93
|
+
* Start tracking a RUM View.
|
|
94
|
+
* @param key: The view unique key identifier.
|
|
95
|
+
* @param name: The view name.
|
|
96
|
+
* @param context: The additional context to send.
|
|
97
|
+
* @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
|
|
98
|
+
*/
|
|
99
|
+
startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Stop tracking a RUM View.
|
|
102
|
+
* @param key: The view unique key identifier.
|
|
103
|
+
* @param context: The additional context to send.
|
|
104
|
+
* @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
105
|
+
*/
|
|
106
|
+
stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Start tracking a RUM Action.
|
|
109
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
110
|
+
* @param name: The action name.
|
|
111
|
+
* @param context: The additional context to send.
|
|
112
|
+
* @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
|
|
113
|
+
*/
|
|
114
|
+
startAction(type: RumActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Stop tracking the ongoing RUM Action.
|
|
117
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
118
|
+
* @param name: The action name.
|
|
119
|
+
* @param context: The additional context to send.
|
|
120
|
+
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
121
|
+
*/
|
|
122
|
+
stopAction(type: RumActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Stop tracking the ongoing RUM Action.
|
|
125
|
+
*
|
|
126
|
+
* Warning: using this function signature can lead to inconsistent behaviors on iOS and Android when multiple actions are started in parallel.
|
|
127
|
+
*
|
|
128
|
+
* @deprecated add the `type` and `name` of the action as first two arguments.
|
|
129
|
+
* @param context: The additional context to send.
|
|
130
|
+
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
131
|
+
*/
|
|
132
|
+
stopAction(context?: object, timestampMs?: number): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Add a RUM Action.
|
|
135
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
136
|
+
* @param name: The action name.
|
|
137
|
+
* @param context: The additional context to send.
|
|
138
|
+
* @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
139
|
+
*/
|
|
140
|
+
addAction(type: RumActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Start tracking a RUM Resource.
|
|
143
|
+
* @param key: The resource unique key identifier.
|
|
144
|
+
* @param method: The resource method (GET, POST, …).
|
|
145
|
+
* @param url: The resource url.
|
|
146
|
+
* @param context: The additional context to send.
|
|
147
|
+
* @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
|
|
148
|
+
*/
|
|
149
|
+
startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Stop tracking a RUM Resource.
|
|
152
|
+
* @param key: The resource unique key identifier.
|
|
153
|
+
* @param statusCode: The resource status code.
|
|
154
|
+
* @param kind: The resource's kind (xhr, document, image, css, font, …).
|
|
155
|
+
* @param size: The resource size in bytes. If size is unknown, use -1.
|
|
156
|
+
* @param context: The additional context to send.
|
|
157
|
+
* @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
158
|
+
*/
|
|
159
|
+
stopResource(key: string, statusCode: number, kind: ResourceKind, size?: number, context?: object, timestampMs?: number): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Add a RUM Error.
|
|
162
|
+
* @param message: The error message.
|
|
163
|
+
* @param source: The error source (network, source, console, webview, custom).
|
|
164
|
+
* @param stacktrace: The error stacktrace.
|
|
165
|
+
* @param context: The additional context to send.
|
|
166
|
+
* @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
167
|
+
*/
|
|
168
|
+
addError(message: string, source: ErrorSource, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.
|
|
171
|
+
* @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
|
|
172
|
+
*/
|
|
173
|
+
addTiming(name: string): Promise<void>;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Describe the type of a RUM Action.
|
|
177
|
+
*/
|
|
178
|
+
export declare enum RumActionType {
|
|
179
|
+
/** User tapped on a widget. */
|
|
180
|
+
TAP = "TAP",
|
|
181
|
+
/** User scrolled a view. */
|
|
182
|
+
SCROLL = "SCROLL",
|
|
183
|
+
/** User swiped on a view. */
|
|
184
|
+
SWIPE = "SWIPE",
|
|
185
|
+
/** User pressed hardware back button (Android only). */
|
|
186
|
+
BACK = "BACK",
|
|
187
|
+
/** A custom action. */
|
|
188
|
+
CUSTOM = "CUSTOM"
|
|
189
|
+
}
|
|
190
|
+
export declare type ResourceKind = 'image' | 'xhr' | 'beacon' | 'css' | 'document' | 'fetch' | 'font' | 'js' | 'media' | 'other' | 'native';
|
|
191
|
+
export declare enum ErrorSource {
|
|
192
|
+
NETWORK = "NETWORK",
|
|
193
|
+
SOURCE = "SOURCE",
|
|
194
|
+
CONSOLE = "CONSOLE",
|
|
195
|
+
WEBVIEW = "WEBVIEW",
|
|
196
|
+
CUSTOM = "CUSTOM"
|
|
197
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "1.1.1";
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@datadog/mobile-react-native-code-push",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "A client-side React Native module to interact with Appcenter Codepush and Datadog",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"datadog",
|
|
7
|
+
"react-native",
|
|
8
|
+
"ios",
|
|
9
|
+
"android",
|
|
10
|
+
"codepush",
|
|
11
|
+
"appcenter"
|
|
12
|
+
],
|
|
13
|
+
"author": "Datadog (https://github.com/DataDog)",
|
|
14
|
+
"homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"url": "https://github.com/DataDog/dd-sdk-reactnative",
|
|
17
|
+
"directory": "packages/codepush"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/DataDog/dd-sdk-reactnative/issues"
|
|
21
|
+
},
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"main": "lib/commonjs/index",
|
|
24
|
+
"files": [
|
|
25
|
+
"src",
|
|
26
|
+
"lib"
|
|
27
|
+
],
|
|
28
|
+
"types": "lib/typescript/codepush/src/index.d.ts",
|
|
29
|
+
"react-native": "src/index",
|
|
30
|
+
"source": "src/index",
|
|
31
|
+
"module": "lib/module/index",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "jest",
|
|
37
|
+
"lint": "eslint .",
|
|
38
|
+
"prepare": "rm -rf lib && yarn bob build"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@datadog/mobile-react-native": "^1.1.0",
|
|
42
|
+
"@testing-library/react-native": "7.0.2",
|
|
43
|
+
"react-native-code-push": "7.0.5"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@datadog/mobile-react-native": "^1.0.0-beta4",
|
|
47
|
+
"react-native-code-push": ">=2.0.0",
|
|
48
|
+
"react": ">=16.13.1",
|
|
49
|
+
"react-native": ">=0.63.4 <1.0"
|
|
50
|
+
},
|
|
51
|
+
"jest": {
|
|
52
|
+
"preset": "react-native",
|
|
53
|
+
"modulePathIgnorePatterns": [
|
|
54
|
+
"<rootDir>/lib/"
|
|
55
|
+
],
|
|
56
|
+
"testPathIgnorePatterns": [
|
|
57
|
+
"/__utils__/"
|
|
58
|
+
],
|
|
59
|
+
"transformIgnorePatterns": []
|
|
60
|
+
},
|
|
61
|
+
"react-native-builder-bob": {
|
|
62
|
+
"source": "src",
|
|
63
|
+
"output": "lib",
|
|
64
|
+
"targets": [
|
|
65
|
+
"commonjs",
|
|
66
|
+
"module",
|
|
67
|
+
[
|
|
68
|
+
"typescript",
|
|
69
|
+
{
|
|
70
|
+
"tsc": "./../../node_modules/.bin/tsc"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DdSdkReactNative,
|
|
3
|
+
DdSdkReactNativeConfiguration
|
|
4
|
+
} from '@datadog/mobile-react-native';
|
|
5
|
+
import codePush from 'react-native-code-push';
|
|
6
|
+
|
|
7
|
+
import { DatadogCodepush } from '..';
|
|
8
|
+
|
|
9
|
+
jest.mock('react-native-code-push', () => ({
|
|
10
|
+
getUpdateMetadata: jest.fn()
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock('@datadog/mobile-react-native', () => {
|
|
14
|
+
const actualPackage = jest.requireActual('@datadog/mobile-react-native');
|
|
15
|
+
return {
|
|
16
|
+
...actualPackage,
|
|
17
|
+
DdSdkReactNative: {
|
|
18
|
+
initialize: jest.fn()
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('AppCenter Codepush integration', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
jest.clearAllMocks();
|
|
26
|
+
});
|
|
27
|
+
describe('initialize', () => {
|
|
28
|
+
it('initializes the SDK with the correct version when using a CodePush bundle', async () => {
|
|
29
|
+
(codePush.getUpdateMetadata as jest.MockedFunction<
|
|
30
|
+
typeof codePush.getUpdateMetadata
|
|
31
|
+
>).mockResolvedValueOnce({
|
|
32
|
+
label: 'v3',
|
|
33
|
+
isMandatory: false,
|
|
34
|
+
install: jest.fn(),
|
|
35
|
+
appVersion: '1.0.0',
|
|
36
|
+
deploymentKey: '1',
|
|
37
|
+
description: '1',
|
|
38
|
+
failedInstall: false,
|
|
39
|
+
isFirstRun: false,
|
|
40
|
+
isPending: false,
|
|
41
|
+
packageHash: '1',
|
|
42
|
+
packageSize: 42
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const configuration = new DdSdkReactNativeConfiguration(
|
|
46
|
+
'token',
|
|
47
|
+
'env',
|
|
48
|
+
'appId',
|
|
49
|
+
true,
|
|
50
|
+
true,
|
|
51
|
+
true
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
await DatadogCodepush.initialize(configuration);
|
|
55
|
+
|
|
56
|
+
expect(DdSdkReactNative.initialize).toHaveBeenCalledTimes(1);
|
|
57
|
+
expect(DdSdkReactNative.initialize).toHaveBeenCalledWith(
|
|
58
|
+
expect.objectContaining({ versionSuffix: 'codepush.v3' })
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('initializes the SDK with the correct version when not using a CodePush bundle', async () => {
|
|
63
|
+
(codePush.getUpdateMetadata as jest.MockedFunction<
|
|
64
|
+
typeof codePush.getUpdateMetadata
|
|
65
|
+
>).mockResolvedValueOnce(null);
|
|
66
|
+
|
|
67
|
+
const configuration = new DdSdkReactNativeConfiguration(
|
|
68
|
+
'token',
|
|
69
|
+
'env',
|
|
70
|
+
'appId',
|
|
71
|
+
true,
|
|
72
|
+
true,
|
|
73
|
+
true
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
await DatadogCodepush.initialize(configuration);
|
|
77
|
+
|
|
78
|
+
expect(DdSdkReactNative.initialize).toHaveBeenCalledTimes(1);
|
|
79
|
+
expect(
|
|
80
|
+
Object.keys(
|
|
81
|
+
(DdSdkReactNative.initialize as jest.MockedFunction<
|
|
82
|
+
typeof DdSdkReactNative.initialize
|
|
83
|
+
>).mock.calls[0]
|
|
84
|
+
)
|
|
85
|
+
).not.toContain('versionSuffix');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DdSdkReactNative } from '@datadog/mobile-react-native';
|
|
2
|
+
import type { DdSdkReactNativeConfiguration } from '@datadog/mobile-react-native';
|
|
3
|
+
import codePush from 'react-native-code-push';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Use this class instead of DdSdkReactNative to initialize the Datadog SDK when using AppCenter CodePush.
|
|
7
|
+
*/
|
|
8
|
+
export const DatadogCodepush = {
|
|
9
|
+
async initialize(
|
|
10
|
+
configuration: DdSdkReactNativeConfiguration
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
const codePushUpdateMetadata = await codePush.getUpdateMetadata();
|
|
13
|
+
if (codePushUpdateMetadata) {
|
|
14
|
+
configuration.versionSuffix = `codepush.${codePushUpdateMetadata.label}`;
|
|
15
|
+
}
|
|
16
|
+
return DdSdkReactNative.initialize(configuration);
|
|
17
|
+
}
|
|
18
|
+
};
|