@dynatrace/react-native-plugin 2.335.1 → 2.337.2
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 +145 -61
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/dynatrace/android/agent/DynatraceRNBridgeImpl.kt +1 -1
- package/files/plugin.gradle +1 -1
- package/instrumentation/BabelPluginDynatrace.js +1 -1
- package/instrumentation/DynatraceInstrumentation.js +1 -1
- package/instrumentation/libs/community/Picker.js +1 -1
- package/instrumentation/libs/react-navigation/ReactNavigation.js +9 -0
- package/instrumentation/libs/withOnPressMonitoring.js +59 -14
- package/lib/core/Dynatrace.js +3 -0
- package/lib/core/DynatraceBridge.js +5 -7
- package/lib/core/configuration/ActionNameOptions.js +2 -0
- package/lib/core/configuration/Configuration.js +5 -1
- package/lib/core/configuration/ConfigurationBuilder.js +11 -1
- package/lib/core/configuration/ConfigurationDefaults.js +3 -1
- package/lib/core/configuration/ConfigurationHandler.js +64 -0
- package/lib/core/configuration/ConfigurationPreset.js +6 -0
- package/lib/core/configuration/ManualStartupConfiguration.js +9 -1
- package/lib/features/ui-interaction/Runtime.js +31 -19
- package/lib/next/Dynatrace.js +44 -0
- package/lib/next/configuration/INativeRuntimeConfiguration.js +9 -0
- package/lib/next/configuration/RuntimeConfigurationObserver.js +50 -6
- package/lib/next/events/EventPipeline.js +14 -6
- package/lib/next/events/HttpRequestEventData.js +26 -30
- package/lib/next/provider/TimestampProvider.js +20 -7
- package/lib/next/util/TraceContextUtils.js +108 -0
- package/package.json +4 -3
- package/react-native-dynatrace.podspec +1 -1
- package/scripts/Android.js +27 -10
- package/scripts/Config.js +1 -1
- package/scripts/Ios.js +288 -71
- package/scripts/PathsConstants.js +34 -20
- package/scripts/core/InstrumentCall.js +7 -1
- package/scripts/util/SourceMapUtil.js +49 -11
- package/types.d.ts +178 -39
|
@@ -9,6 +9,14 @@ const ValueRestrictionModifier_1 = require("./modifier/ValueRestrictionModifier"
|
|
|
9
9
|
const ModifyEventValidation_1 = require("./modifier/ModifyEventValidation");
|
|
10
10
|
const EventSpecContstants_1 = require("./spec/EventSpecContstants");
|
|
11
11
|
const StringLengthEventModifier_1 = require("./modifier/StringLengthEventModifier");
|
|
12
|
+
const DECISION_REASON_TEXT = {
|
|
13
|
+
third_gen_disabled: '3rd generation RUM is disabled',
|
|
14
|
+
runtime_config_unavailable: 'Runtime configuration is not yet available',
|
|
15
|
+
data_collection_off: 'Data collection is disabled',
|
|
16
|
+
agent_inactive: 'Agent is inactive',
|
|
17
|
+
traffic_control_active: 'Traffic control is limiting data transmission',
|
|
18
|
+
crash_reporting_disabled: 'Crash reporting is disabled',
|
|
19
|
+
};
|
|
12
20
|
class EventPipelineImpl {
|
|
13
21
|
constructor() {
|
|
14
22
|
this.customEventModifierChain = new ModifyEventValidation_1.ModifyEventValidation();
|
|
@@ -25,12 +33,12 @@ class EventPipelineImpl {
|
|
|
25
33
|
];
|
|
26
34
|
}
|
|
27
35
|
insertEvent(event) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.logger.debug(
|
|
36
|
+
const decision = ConfigurationHandler_1.ConfigurationHandler.getThirdGenDataReportingDecision();
|
|
37
|
+
if (!decision.allowed) {
|
|
38
|
+
const reasonText = decision.reason
|
|
39
|
+
? DECISION_REASON_TEXT[decision.reason]
|
|
40
|
+
: 'Unknown reason';
|
|
41
|
+
this.logger.debug(`3rd gen event suppressed: ${reasonText}`);
|
|
34
42
|
return;
|
|
35
43
|
}
|
|
36
44
|
this.logger.debug(`insertEvent(${JSON.stringify(event)})`);
|
|
@@ -5,6 +5,8 @@ const TimestampProvider_1 = require("../provider/TimestampProvider");
|
|
|
5
5
|
const SendEventValidation_1 = require("./modifier/SendEventValidation");
|
|
6
6
|
const EventModifierUtil_1 = require("./modifier/EventModifierUtil");
|
|
7
7
|
const EventBuilderUtil_1 = require("./EventBuilderUtil");
|
|
8
|
+
const TraceContextUtils_1 = require("../util/TraceContextUtils");
|
|
9
|
+
const ConfigurationHandler_1 = require("../../core/configuration/ConfigurationHandler");
|
|
8
10
|
const logger = new ConsoleLogger_1.ConsoleLogger('HttpRequestEventData');
|
|
9
11
|
class HttpRequestEventData {
|
|
10
12
|
constructor(url, requestMethod) {
|
|
@@ -43,7 +45,9 @@ class HttpRequestEventData {
|
|
|
43
45
|
return this;
|
|
44
46
|
}
|
|
45
47
|
withTraceparentHeader(traceparentHeader) {
|
|
46
|
-
|
|
48
|
+
if (traceparentHeader !== undefined) {
|
|
49
|
+
this.traceparentHeader = traceparentHeader;
|
|
50
|
+
}
|
|
47
51
|
return this;
|
|
48
52
|
}
|
|
49
53
|
addEventProperty(key, value) {
|
|
@@ -59,13 +63,8 @@ class HttpRequestEventData {
|
|
|
59
63
|
const sanitizedStatusCode = this.sanitizeStatusCode();
|
|
60
64
|
const sanitizedBytesReceived = this.sanitizeBytesReceived();
|
|
61
65
|
const sanitizedBytesSent = this.sanitizeBytesSent();
|
|
62
|
-
const parsedTraceparentHeader = this.traceparentHeader &&
|
|
63
|
-
|
|
64
|
-
const traceContextHint = !this.traceparentHeader
|
|
65
|
-
? "api_unused"
|
|
66
|
-
: parsedTraceparentHeader
|
|
67
|
-
? "api_set"
|
|
68
|
-
: "invalid";
|
|
66
|
+
const parsedTraceparentHeader = this.traceparentHeader && (0, TraceContextUtils_1.parseTraceparent)(this.traceparentHeader);
|
|
67
|
+
const traceContextHint = this.getTraceContextHint(parsedTraceparentHeader);
|
|
69
68
|
const hasFailedRequest = this.isStatusCodeError() || !!this.error;
|
|
70
69
|
const sanitizedEventProperties = SendEventValidation_1.SendEventValidation.modifyEvent(this.rawEventProperties);
|
|
71
70
|
(0, EventModifierUtil_1.flagEventProperties)(sanitizedEventProperties);
|
|
@@ -76,9 +75,27 @@ class HttpRequestEventData {
|
|
|
76
75
|
],
|
|
77
76
|
})), (0, EventBuilderUtil_1.includeIfDefined)("http.response.status_code", sanitizedStatusCode)), (0, EventBuilderUtil_1.includeIfDefined)("http.response.reason_phrase", this.reasonPhrase)), (0, EventBuilderUtil_1.includeIfDefined)("request.bytes_sent", sanitizedBytesSent)), (0, EventBuilderUtil_1.includeIfDefined)("request.bytes_received", sanitizedBytesReceived)), { ["characteristics.has_request"]: true, ["characteristics.is_api_reported"]: true }), (0, EventBuilderUtil_1.includeIfTrue)("characteristics.has_failed_request", hasFailedRequest)), (0, EventBuilderUtil_1.includeIfTrue)("characteristics.has_error", hasFailedRequest)), (this.error !== undefined && Object.assign({ ["characteristics.has_exception"]: true, ["exception.type"]: this.error.name, ["exception.message"]: this.error.message }, (0, EventBuilderUtil_1.includeIfDefined)("exception.stack_trace", this.error.stack)))), (parsedTraceparentHeader && {
|
|
78
77
|
["trace.id"]: parsedTraceparentHeader.traceId,
|
|
79
|
-
["span.id"]: parsedTraceparentHeader.
|
|
78
|
+
["span.id"]: parsedTraceparentHeader.parentId,
|
|
80
79
|
})), (0, EventBuilderUtil_1.includeIfTrue)("dt.support.api.has_dropped_properties", this.hasDroppedProperties));
|
|
81
80
|
}
|
|
81
|
+
getTraceContextHint(parsedTraceparentHeader) {
|
|
82
|
+
if (!ConfigurationHandler_1.ConfigurationHandler.isConfigurationAvailable() ||
|
|
83
|
+
!ConfigurationHandler_1.ConfigurationHandler.getTracestateKeyPrefix()) {
|
|
84
|
+
return "not_initialized";
|
|
85
|
+
}
|
|
86
|
+
if (!ConfigurationHandler_1.ConfigurationHandler.getTraceContextEnabled()) {
|
|
87
|
+
return "disabled";
|
|
88
|
+
}
|
|
89
|
+
if (!this.traceparentHeader) {
|
|
90
|
+
return "api_unused";
|
|
91
|
+
}
|
|
92
|
+
if (parsedTraceparentHeader) {
|
|
93
|
+
return "api_set";
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return "invalid";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
82
99
|
hasValidMandatoryAttributes() {
|
|
83
100
|
let isValid = true;
|
|
84
101
|
if (this.isInvalidUrl(this.url)) {
|
|
@@ -138,27 +155,6 @@ class HttpRequestEventData {
|
|
|
138
155
|
isStatusCodeError() {
|
|
139
156
|
return (this.statusCode && 400 <= this.statusCode && this.statusCode <= 599);
|
|
140
157
|
}
|
|
141
|
-
parseTraceparent(header) {
|
|
142
|
-
const traceparentRegex = /^00-([0-9a-f]{32})-([0-9a-f]{16})-0[01]$/;
|
|
143
|
-
const match = header.match(traceparentRegex);
|
|
144
|
-
if (!match) {
|
|
145
|
-
logger.debug("The provided traceparent header does not match the format: '00-<trace-id-32-HEXDIG>-<parent-id-16-HEXDIG>-<trace-flags-2-HEXDIG>'");
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
const [, traceId, spanId] = match;
|
|
149
|
-
if (this.allZeros(traceId)) {
|
|
150
|
-
logger.debug('Trace ID in traceparent header must not be all zeros');
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
if (this.allZeros(spanId)) {
|
|
154
|
-
logger.debug('Parent ID in traceparent header must not be all zeros');
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
return { traceId, spanId };
|
|
158
|
-
}
|
|
159
|
-
allZeros(str) {
|
|
160
|
-
return /^0*$/.test(str);
|
|
161
|
-
}
|
|
162
158
|
}
|
|
163
159
|
exports.default = HttpRequestEventData;
|
|
164
160
|
HttpRequestEventData.allowedRequestMethods = [
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultTimestampProvider =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.defaultTimestampProvider = void 0;
|
|
4
|
+
let baseRealtimeMs = null;
|
|
5
|
+
let baseMonotonicMs = null;
|
|
6
|
+
const getMonotonicNow = () => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (typeof ((_a = globalThis.performance) === null || _a === void 0 ? void 0 : _a.now) === 'function') {
|
|
9
|
+
return globalThis.performance.now();
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.defaultTimestampProvider =
|
|
11
|
+
return Date.now();
|
|
12
|
+
};
|
|
13
|
+
exports.defaultTimestampProvider = {
|
|
14
|
+
getCurrentTimestamp: () => {
|
|
15
|
+
const currentMonotonicMs = getMonotonicNow();
|
|
16
|
+
if (baseRealtimeMs == null || baseMonotonicMs == null) {
|
|
17
|
+
baseRealtimeMs = Date.now();
|
|
18
|
+
baseMonotonicMs = currentMonotonicMs;
|
|
19
|
+
return baseRealtimeMs;
|
|
20
|
+
}
|
|
21
|
+
return baseRealtimeMs + (currentMonotonicMs - baseMonotonicMs);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trimTraceState = exports.generateTracestate = exports.generateTraceparentHeader = exports.parseTraceparent = void 0;
|
|
4
|
+
const ConsoleLogger_1 = require("../../core/logging/ConsoleLogger");
|
|
5
|
+
const ConfigurationHandler_1 = require("../../core/configuration/ConfigurationHandler");
|
|
6
|
+
const logger = new ConsoleLogger_1.ConsoleLogger('TraceContextUtils');
|
|
7
|
+
const parseTraceparent = (traceparent) => {
|
|
8
|
+
const traceparentRegex = /^[0-9a-f]{2}-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/i;
|
|
9
|
+
const match = traceparentRegex.exec(traceparent);
|
|
10
|
+
if (!match) {
|
|
11
|
+
logger.debug("The traceparent header doesn't match the format: '<version-2-hex>-<trace-id-32-hex>-<parent-id-16-hex>-<flags-2-hex>'");
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const [, traceId, parentId] = match;
|
|
15
|
+
if (allZeros(traceId)) {
|
|
16
|
+
logger.debug('Trace ID in traceparent header must not be all zeros');
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
if (allZeros(parentId)) {
|
|
20
|
+
logger.debug('Parent ID in traceparent header must not be all zeros');
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return { traceId, parentId };
|
|
24
|
+
};
|
|
25
|
+
exports.parseTraceparent = parseTraceparent;
|
|
26
|
+
const allZeros = (str) => /^0*$/.test(str);
|
|
27
|
+
const generateTraceparentHeader = () => {
|
|
28
|
+
let traceId = randomHex(32);
|
|
29
|
+
if (/^0+$/.test(traceId)) {
|
|
30
|
+
traceId = '1' + traceId.slice(1);
|
|
31
|
+
}
|
|
32
|
+
let spanId = randomHex(16);
|
|
33
|
+
if (/^0+$/.test(spanId)) {
|
|
34
|
+
spanId = '1' + spanId.slice(1);
|
|
35
|
+
}
|
|
36
|
+
return `00-${traceId}-${spanId}-01`;
|
|
37
|
+
};
|
|
38
|
+
exports.generateTraceparentHeader = generateTraceparentHeader;
|
|
39
|
+
const randomHex = (length) => {
|
|
40
|
+
let hex = '';
|
|
41
|
+
while (hex.length < length) {
|
|
42
|
+
hex += Math.floor(Math.random() * 0xffffffff)
|
|
43
|
+
.toString(16)
|
|
44
|
+
.padStart(8, '0');
|
|
45
|
+
}
|
|
46
|
+
return hex.slice(0, length);
|
|
47
|
+
};
|
|
48
|
+
const generateTracestate = (parentId, existingTracestate) => {
|
|
49
|
+
const instanceId = ConfigurationHandler_1.ConfigurationHandler.getInstanceId();
|
|
50
|
+
const sessionId = ConfigurationHandler_1.ConfigurationHandler.getSessionId();
|
|
51
|
+
const applicationId = ConfigurationHandler_1.ConfigurationHandler.getApplicationId();
|
|
52
|
+
const tracestateKeyPrefix = ConfigurationHandler_1.ConfigurationHandler.getTracestateKeyPrefix();
|
|
53
|
+
if (!ConfigurationHandler_1.ConfigurationHandler.getTraceContextEnabled() ||
|
|
54
|
+
!(instanceId && sessionId && applicationId && tracestateKeyPrefix)) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const version = 1;
|
|
58
|
+
const originMarker = 'dtr';
|
|
59
|
+
const capture = 0;
|
|
60
|
+
let tracestate = `${tracestateKeyPrefix}@${originMarker}=${version};${parentId};${capture};${formatApplicationId(applicationId)};${instanceId};${sessionId}`;
|
|
61
|
+
if (typeof existingTracestate === 'string' && existingTracestate.trim()) {
|
|
62
|
+
tracestate += `,${existingTracestate}`;
|
|
63
|
+
}
|
|
64
|
+
return (0, exports.trimTraceState)(tracestate);
|
|
65
|
+
};
|
|
66
|
+
exports.generateTracestate = generateTracestate;
|
|
67
|
+
const formatApplicationId = (applicationId) => applicationId.split('-').slice(0, 3).join('');
|
|
68
|
+
const findLastLongSegmentIndex = (segments, longSegmentLength) => {
|
|
69
|
+
for (let i = segments.length - 1; i > 0; i--) {
|
|
70
|
+
if (segments[i].length > longSegmentLength) {
|
|
71
|
+
return i;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return -1;
|
|
75
|
+
};
|
|
76
|
+
const trimTraceState = (tracestate, maxLength = 512, longSegmentLength = 128, maxSegments = 32) => {
|
|
77
|
+
let segments = tracestate.split(',');
|
|
78
|
+
let length = tracestate.length;
|
|
79
|
+
if (length <= maxLength && segments.length <= maxSegments) {
|
|
80
|
+
return tracestate;
|
|
81
|
+
}
|
|
82
|
+
if (segments.length > maxSegments) {
|
|
83
|
+
segments = segments.slice(0, maxSegments);
|
|
84
|
+
length =
|
|
85
|
+
segments.reduce((sum, s) => sum + s.length, 0) +
|
|
86
|
+
(segments.length - 1);
|
|
87
|
+
}
|
|
88
|
+
let hasLongSegments = true;
|
|
89
|
+
while (length > maxLength && segments.length > 1) {
|
|
90
|
+
let removed = '';
|
|
91
|
+
if (hasLongSegments) {
|
|
92
|
+
const idx = findLastLongSegmentIndex(segments, longSegmentLength);
|
|
93
|
+
if (idx > 0) {
|
|
94
|
+
removed = segments.splice(idx, 1)[0];
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
hasLongSegments = false;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
removed = segments.pop();
|
|
103
|
+
}
|
|
104
|
+
length -= removed.length + 1;
|
|
105
|
+
}
|
|
106
|
+
return segments.join(',');
|
|
107
|
+
};
|
|
108
|
+
exports.trimTraceState = trimTraceState;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynatrace/react-native-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.337.2",
|
|
4
4
|
"description": "This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types.d.ts",
|
|
@@ -53,12 +53,11 @@
|
|
|
53
53
|
"jscodeshift": "^17.3.0",
|
|
54
54
|
"plist": "^3.1.0",
|
|
55
55
|
"proxy-polyfill": "^0.3.2",
|
|
56
|
-
"semver": "^7.
|
|
56
|
+
"semver": "^7.8.0"
|
|
57
57
|
},
|
|
58
58
|
"homepage": "https://www.dynatrace.com/",
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@babel/core": ">=7.4.4",
|
|
61
|
-
"@react-native-picker/picker": ">=1.0.0",
|
|
62
61
|
"diff": "^8.0.2",
|
|
63
62
|
"react": ">=16.11.0",
|
|
64
63
|
"react-native": ">=0.62.0"
|
|
@@ -77,6 +76,7 @@
|
|
|
77
76
|
"@babel/plugin-transform-optional-chaining": "^7.27.1",
|
|
78
77
|
"@babel/preset-env": "^7.27.2",
|
|
79
78
|
"@babel/preset-react": "^7.27.1",
|
|
79
|
+
"@react-native-picker/picker": "^2.11.4",
|
|
80
80
|
"@react-native/babel-preset": "^0.80.1",
|
|
81
81
|
"@react-navigation/core": "^7.13.0",
|
|
82
82
|
"@react-navigation/drawer": "^7.7.2",
|
|
@@ -171,6 +171,7 @@
|
|
|
171
171
|
"lib/next/events/interface/*.js",
|
|
172
172
|
"lib/next/events/modifier/*.js",
|
|
173
173
|
"lib/next/events/spec/*.js",
|
|
174
|
+
"lib/next/util/*.js",
|
|
174
175
|
"lib/next/provider/*.js",
|
|
175
176
|
"lib/features/ui-interaction/*.js",
|
|
176
177
|
"src/lib/core/interface/NativeDynatraceBridge.ts",
|
|
@@ -111,7 +111,7 @@ Pod::Spec.new do |s|
|
|
|
111
111
|
#
|
|
112
112
|
|
|
113
113
|
s.dependency "React"
|
|
114
|
-
s.dependency 'Dynatrace', '~> 8.
|
|
114
|
+
s.dependency 'Dynatrace', '~> 8.337.1.1003'
|
|
115
115
|
|
|
116
116
|
# Allows for better compatibility for older and newer versions
|
|
117
117
|
if defined?(install_modules_dependencies)
|
package/scripts/Android.js
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ensureRuntimeScriptApplied = exports.writeGradleConfig = exports.instrumentAndroidPlatform = exports.GRADLE_APPLY_RUNTIME_SCRIPT = exports.GRADLE_APPLY_BUILDSCRIPT = exports.GRADLE_DYNATRACE_FILE = void 0;
|
|
4
|
+
exports.ensureRuntimeScriptApplied = exports.writeGradleConfig = exports.instrumentAndroidPlatform = exports.GRADLE_APPLY_RUNTIME_SCRIPT_KTS = exports.GRADLE_APPLY_RUNTIME_SCRIPT = exports.GRADLE_APPLY_BUILDSCRIPT_KTS = exports.GRADLE_APPLY_BUILDSCRIPT = exports.GRADLE_DYNATRACE_FILE_KTS = exports.GRADLE_DYNATRACE_FILE = void 0;
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const Logger_1 = require("./Logger");
|
|
7
7
|
const FileOperationHelper_1 = require("./FileOperationHelper");
|
|
8
8
|
const PathsConstants_1 = require("./PathsConstants");
|
|
9
9
|
const GRADLE_CONFIG_IDENTIFIER = '// AUTO - INSERTED';
|
|
10
10
|
exports.GRADLE_DYNATRACE_FILE = `apply from: "./${PathsConstants_1.DYNATRACE_CONFIG_GRADLE_FILE}"`;
|
|
11
|
+
exports.GRADLE_DYNATRACE_FILE_KTS = `apply(from = "./${PathsConstants_1.DYNATRACE_CONFIG_GRADLE_FILE}")`;
|
|
11
12
|
const LEGACY_GRADLE_DYNATRACE_NODE_MODULES = 'node_modules/@dynatrace/react-native-plugin/files/dynatrace.gradle';
|
|
12
13
|
const GRADLE_BUILDSCRIPT_IDENTIFIER = 'buildscript';
|
|
13
14
|
exports.GRADLE_APPLY_BUILDSCRIPT = 'apply from: "../node_modules/@dynatrace/react-native-plugin/files/plugin.gradle", to: buildscript';
|
|
15
|
+
exports.GRADLE_APPLY_BUILDSCRIPT_KTS = 'apply(from = "../node_modules/@dynatrace/react-native-plugin/files/plugin.gradle", to = buildscript)';
|
|
14
16
|
const GRADLE_REACT_NATIVE_PLUGIN = 'apply plugin: "com.facebook.react.rootproject"';
|
|
15
17
|
exports.GRADLE_APPLY_RUNTIME_SCRIPT = 'apply from: "../../node_modules/@dynatrace/react-native-plugin/files/plugin-runtime.gradle"';
|
|
18
|
+
exports.GRADLE_APPLY_RUNTIME_SCRIPT_KTS = 'apply(from = "../../node_modules/@dynatrace/react-native-plugin/files/plugin-runtime.gradle")';
|
|
19
|
+
const isKotlinDslGradleFile = (pathToGradle) => pathToGradle.endsWith('.gradle.kts');
|
|
20
|
+
const getGradleStatements = (pathToGradle) => isKotlinDslGradleFile(pathToGradle)
|
|
21
|
+
? {
|
|
22
|
+
applyBuildscript: exports.GRADLE_APPLY_BUILDSCRIPT_KTS,
|
|
23
|
+
dynatraceFile: exports.GRADLE_DYNATRACE_FILE_KTS,
|
|
24
|
+
runtimeScript: exports.GRADLE_APPLY_RUNTIME_SCRIPT_KTS,
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
applyBuildscript: exports.GRADLE_APPLY_BUILDSCRIPT,
|
|
28
|
+
dynatraceFile: exports.GRADLE_DYNATRACE_FILE,
|
|
29
|
+
runtimeScript: exports.GRADLE_APPLY_RUNTIME_SCRIPT,
|
|
30
|
+
};
|
|
16
31
|
const instrumentAndroidPlatform = (pathToGradle, remove) => {
|
|
17
32
|
const path = FileOperationHelper_1.default.checkIfFileExistsSync(pathToGradle);
|
|
18
|
-
if (!path.endsWith('.gradle')) {
|
|
19
|
-
throw new Error("Can't find .gradle file. gradle path must
|
|
33
|
+
if (!path.endsWith('.gradle') && !path.endsWith('.gradle.kts')) {
|
|
34
|
+
throw new Error("Can't find .gradle(.kts) file. gradle path must include build.gradle or build.gradle.kts!");
|
|
20
35
|
}
|
|
21
36
|
changeReactNativeBuildGradleFile(path, remove);
|
|
22
37
|
};
|
|
@@ -60,11 +75,11 @@ const removeDynatraceFromGradle = (lines, indices, pathToGradle) => {
|
|
|
60
75
|
}
|
|
61
76
|
return modified;
|
|
62
77
|
};
|
|
63
|
-
const addDynatraceToGradle = (lines, indices, pathToGradle) => {
|
|
78
|
+
const addDynatraceToGradle = (lines, indices, pathToGradle, statements) => {
|
|
64
79
|
let modified = false;
|
|
65
80
|
if (indices.dynatraceFileIndex !== -1 &&
|
|
66
81
|
lines[indices.dynatraceFileIndex].includes(LEGACY_GRADLE_DYNATRACE_NODE_MODULES)) {
|
|
67
|
-
lines[indices.dynatraceFileIndex] =
|
|
82
|
+
lines[indices.dynatraceFileIndex] = statements.dynatraceFile;
|
|
68
83
|
Logger_1.default.logMessageSync('Migrated old node_modules dynatrace.gradle path to local path in build.gradle', Logger_1.default.INFO);
|
|
69
84
|
modified = true;
|
|
70
85
|
}
|
|
@@ -73,12 +88,12 @@ const addDynatraceToGradle = (lines, indices, pathToGradle) => {
|
|
|
73
88
|
if (buildscriptIndex === -1) {
|
|
74
89
|
throw new Error('Could not find Buildscript block in build.gradle.');
|
|
75
90
|
}
|
|
76
|
-
lines.splice(buildscriptIndex + 1, 0,
|
|
91
|
+
lines.splice(buildscriptIndex + 1, 0, statements.applyBuildscript);
|
|
77
92
|
modified = true;
|
|
78
93
|
}
|
|
79
94
|
if (indices.dynatraceFileIndex === -1) {
|
|
80
95
|
const pluginLineIndex = lines.findIndex((line) => line.includes(GRADLE_REACT_NATIVE_PLUGIN));
|
|
81
|
-
lines.splice(pluginLineIndex !== -1 ? pluginLineIndex : lines.length, 0,
|
|
96
|
+
lines.splice(pluginLineIndex !== -1 ? pluginLineIndex : lines.length, 0, statements.dynatraceFile);
|
|
82
97
|
modified = true;
|
|
83
98
|
}
|
|
84
99
|
if (modified) {
|
|
@@ -93,10 +108,11 @@ const changeReactNativeBuildGradleFile = (pathToGradle, remove) => {
|
|
|
93
108
|
const gradleFileContent = FileOperationHelper_1.default.readTextFromFileSync(pathToGradle);
|
|
94
109
|
const modifiedFileContent = removeOldDynatraceClasspath(gradleFileContent);
|
|
95
110
|
const gradleFileContentLines = modifiedFileContent.split('\n');
|
|
111
|
+
const statements = getGradleStatements(pathToGradle);
|
|
96
112
|
const indices = findGradleLineIndices(gradleFileContentLines);
|
|
97
113
|
const modified = remove
|
|
98
114
|
? removeDynatraceFromGradle(gradleFileContentLines, indices, pathToGradle)
|
|
99
|
-
: addDynatraceToGradle(gradleFileContentLines, indices, pathToGradle);
|
|
115
|
+
: addDynatraceToGradle(gradleFileContentLines, indices, pathToGradle, statements);
|
|
100
116
|
if (modified) {
|
|
101
117
|
const fullGradleFile = gradleFileContentLines.join('\n');
|
|
102
118
|
FileOperationHelper_1.default.writeTextToFileSync(pathToGradle, fullGradleFile);
|
|
@@ -152,9 +168,10 @@ const removeOldGradleConfig = (gradleFileContent) => {
|
|
|
152
168
|
const ensureRuntimeScriptApplied = (pathToGradle) => {
|
|
153
169
|
const gradleContent = FileOperationHelper_1.default.readTextFromFileSync(pathToGradle);
|
|
154
170
|
const gradleLines = gradleContent.split('\n');
|
|
155
|
-
const
|
|
171
|
+
const { runtimeScript } = getGradleStatements(pathToGradle);
|
|
172
|
+
const alreadyApplied = gradleLines.some((line) => line.includes('plugin-runtime.gradle'));
|
|
156
173
|
if (!alreadyApplied) {
|
|
157
|
-
gradleLines.push(
|
|
174
|
+
gradleLines.push(runtimeScript);
|
|
158
175
|
FileOperationHelper_1.default.writeTextToFileSync(pathToGradle, gradleLines.join('\n'));
|
|
159
176
|
Logger_1.default.logMessageSync(`Added runtime script to ${pathToGradle}`, Logger_1.default.INFO);
|
|
160
177
|
}
|
package/scripts/Config.js
CHANGED
|
@@ -11,11 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.checkConfiguration = exports.addDefaultConfigs = exports.readConfig = exports.readConfigDefault = exports.defaultConfig = exports.ERROR_CONFIG_NOT_AVAILABLE = void 0;
|
|
14
|
+
const path = require("node:path");
|
|
14
15
|
const FileOperationHelper_1 = require("./FileOperationHelper");
|
|
15
16
|
const Logger_1 = require("./Logger");
|
|
16
17
|
const PathsConstants_1 = require("./PathsConstants");
|
|
17
18
|
const CustomArgumentUtil_1 = require("./util/CustomArgumentUtil");
|
|
18
|
-
const path = require("path");
|
|
19
19
|
exports.ERROR_CONFIG_NOT_AVAILABLE = '-1';
|
|
20
20
|
exports.defaultConfig = {
|
|
21
21
|
react: {
|