@dynatrace/react-native-plugin 2.333.1 → 2.337.1
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 +181 -232
- package/android/build.gradle +1 -1
- package/files/plugin-runtime.gradle +27 -13
- package/files/plugin.gradle +1 -1
- package/instrumentation/BabelPluginDynatrace.js +1 -0
- package/instrumentation/DynatraceInstrumentation.js +1 -1
- package/instrumentation/jsx/JsxRuntime.js +4 -4
- package/instrumentation/libs/UserInteraction.js +114 -0
- package/instrumentation/libs/community/Picker.js +1 -1
- package/instrumentation/libs/community/gesture-handler/Touchables.InstrInfo.js +2 -0
- package/instrumentation/libs/community/gesture-handler/Touchables.js +3 -1
- package/instrumentation/libs/community/gesture-handler/index.js +3 -1
- package/instrumentation/libs/react-navigation/ReactNavigation.js +9 -0
- package/instrumentation/libs/withOnPressMonitoring.js +65 -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/dynatrace-reporter.js +0 -14
- package/lib/dynatrace-transformer.js +10 -13
- package/lib/features/ui-interaction/Config.js +8 -2
- package/lib/features/ui-interaction/Plugin.Fragment.Test.js +170 -0
- package/lib/features/ui-interaction/Plugin.js +226 -882
- package/lib/features/ui-interaction/Run.js +11 -7
- package/lib/features/ui-interaction/Runtime.js +258 -913
- package/lib/features/ui-interaction/TouchMetaResolver.js +492 -0
- package/lib/features/ui-interaction/Types.js +1 -62
- 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 +8 -10
- package/react-native-dynatrace.podspec +1 -1
- package/scripts/Android.js +96 -66
- package/scripts/Config.js +11 -1
- package/scripts/Ios.js +288 -71
- package/scripts/PathsConstants.js +34 -20
- package/scripts/core/InstrumentCall.js +8 -3
- package/scripts/core/LineOffsetAnalyzeCall.js +9 -15
- package/scripts/util/SourceMapUtil.js +49 -11
- package/types.d.ts +178 -39
- package/scripts/util/ReactOptions.js +0 -21
|
@@ -1,19 +1,33 @@
|
|
|
1
|
-
import org.gradle.
|
|
1
|
+
import org.gradle.process.ExecOperations
|
|
2
|
+
import javax.inject.Inject
|
|
3
|
+
|
|
4
|
+
abstract class RunLineOffsetTask extends DefaultTask {
|
|
5
|
+
@Internal
|
|
6
|
+
abstract DirectoryProperty getWorkingDirectory()
|
|
7
|
+
|
|
8
|
+
@Inject
|
|
9
|
+
abstract ExecOperations getExecOperations()
|
|
10
|
+
|
|
11
|
+
@TaskAction
|
|
12
|
+
void run() {
|
|
13
|
+
execOperations.exec {
|
|
14
|
+
workingDir workingDirectory.get().asFile
|
|
15
|
+
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
|
|
16
|
+
commandLine 'cmd', '/c', 'npx', 'lineOffsetDynatrace'
|
|
17
|
+
} else {
|
|
18
|
+
commandLine 'npx', 'lineOffsetDynatrace'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
2
23
|
|
|
3
24
|
android.applicationVariants.all { variant ->
|
|
4
25
|
if (variant.buildType.name == "release") {
|
|
26
|
+
def lineOffsetTask = tasks.register("runLineOffset${variant.name.capitalize()}", RunLineOffsetTask) {
|
|
27
|
+
workingDirectory = layout.projectDirectory
|
|
28
|
+
}
|
|
5
29
|
variant.mergeAssetsProvider.configure { task ->
|
|
6
|
-
task.
|
|
7
|
-
exec {
|
|
8
|
-
workingDir rootDir
|
|
9
|
-
if (DefaultNativePlatform.currentOperatingSystem.isWindows()) {
|
|
10
|
-
// On windows, npx.cmd may not be a true binary executable and may need to be interpreted by a shell instead of executed direclty
|
|
11
|
-
commandLine 'cmd', '/c', 'npx', 'lineOffsetDynatrace'
|
|
12
|
-
} else {
|
|
13
|
-
commandLine 'npx', 'lineOffsetDynatrace'
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
30
|
+
task.dependsOn(lineOffsetTask)
|
|
17
31
|
}
|
|
18
32
|
}
|
|
19
|
-
}
|
|
33
|
+
}
|
package/files/plugin.gradle
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _templateObject,_templateObject2,_templateObject3,_templateObject4,_templateObject5,_templateObject6,_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_taggedTemplateLiteral2=_interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));function _createForOfIteratorHelper(e,t){var n,r,a,i,o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return a=!(r=!0),{s:function(){o=o.call(e)},n:function(){var e=o.next();return r=e.done,e},e:function(e){a=!0,n=e},f:function(){try{r||null==o.return||o.return()}finally{if(a)throw n}}};if(Array.isArray(e)||(o=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return o&&(e=o),i=0,{s:t=function(){},n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}Object.defineProperty(exports,"__esModule",{value:!0});var reactOptions,fspath=require("path"),fs=require("fs"),core_1=require("@babel/core"),generator_1=require("@babel/generator"),PathsConstants_1=require("../scripts/PathsConstants"),Config_1=require("../scripts/Config"),GetValuesFromPackage_1=require("../lib/core/util/GetValuesFromPackage"),Types_1=require("./model/Types"),INSTRUMENTATION_LIBS="@dynatrace/react-native-plugin/instrumentation/libs",hasJSX=function(e){var t=!1;return e.traverse({"JSXElement|JSXFragment":function(){t=!0}}),t},instrumentUserInteraction=function(e){e.traverse({"FunctionDeclaration|ObjectMethod":function(e){var e=e.node,t=core_1.types.isFunctionDeclaration(e)?e.id:e.key;core_1.types.isIdentifier(t,{name:"registerComponent"})&&(t="".concat(INSTRUMENTATION_LIBS,"/UserInteraction"),e.body.body.unshift(core_1.template.statement('componentProvider = require("'.concat(t,'").wrapProvider(componentProvider);'))()))}})},instrumentAppRegistry=function(e){e.traverse({"FunctionDeclaration|ObjectMethod":function(e){var e=e.node,t=core_1.types.isFunctionDeclaration(e)?e.id:e.key;core_1.types.isIdentifier(t,{name:"runApplication"})&&e.body.body.unshift(core_1.template.statement(_templateObject=_templateObject||(0,_taggedTemplateLiteral2.default)(['require("@dynatrace/react-native-plugin").ApplicationHandler.startup();']))())}})},instrumentExceptionsManager=function(e){var t,n=null!=(t=null==(t=null==reactOptions?void 0:reactOptions.errorHandler)?void 0:t.reportFatalErrorAsCrash)&&t,r=(null==reactOptions?void 0:reactOptions.autoStart)&&(null==(t=null==reactOptions?void 0:reactOptions.errorHandler)?void 0:t.enabled);e.traverse({FunctionDeclaration:function(e){var t;core_1.types.isIdentifier(e.node.id,{name:"handleException"})&&(t=core_1.template.statement(_templateObject2=_templateObject2||(0,_taggedTemplateLiteral2.default)(['\n setTimeout(() => BODY, require("@dynatrace/react-native-plugin/lib/core/ErrorHandler")\n .reportErrorToDynatrace(e, isFatal, CRASH, AUTO));\n ']))({BODY:core_1.types.cloneNode(e.node.body),CRASH:core_1.types.booleanLiteral(n),AUTO:core_1.types.booleanLiteral(!!r)}),e.node.body.body=[t])}})},instrumentCssInterop=function(e){e.traverse({CallExpression:function(e){core_1.types.isIdentifier(e.node.callee,{name:"require"})&&(e=e.node.arguments[0],core_1.types.isStringLiteral(e))&&("react/jsx-runtime"===e.value?e.value="@dynatrace/react-native-plugin/jsx-runtime":"react/jsx-dev-runtime"===e.value&&(e.value="@dynatrace/react-native-plugin/jsx-dev-runtime"))}})},instrumentNavigation=function(e){e.traverse({VariableDeclarator:function(e){var t;core_1.types.isIdentifier(e.node.id,{name:"getRootState"})&&(t=core_1.template.statement(_templateObject3=_templateObject3||(0,_taggedTemplateLiteral2.default)(["\n require(PATH).monitorNavigation(getRootState);\n "]))({PATH:core_1.types.stringLiteral("".concat(INSTRUMENTATION_LIBS,"/react-navigation/ReactNavigation"))}),e.parentPath.insertAfter(t))}})},instrumentReactCreateElement=function(e){var t=core_1.template.statement(_templateObject4=_templateObject4||(0,_taggedTemplateLiteral2.default)(["\n require(PATH).instrumentCreateElement(module.exports);\n "]))({PATH:core_1.types.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")});e.pushContainer("body",t)},instrumentComponents=function(e,n){e.traverse({FunctionDeclaration:function(e){var t;hasJSX(e)&&(t=e.node,core_1.types.isIdentifier(t.id))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t.id.name,Types_1.Types.FunctionalComponent))},ClassDeclaration:function(e){var t;hasJSX(e)&&(t=e.node,core_1.types.isIdentifier(t.id))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t.id.name,Types_1.Types.ClassComponent))},"FunctionExpression|ArrowFunctionExpression":function(e){var t;hasJSX(e)&&(t=e.parent,void 0!==(t=core_1.types.isVariableDeclarator(t)&&core_1.types.isIdentifier(t.id)?t.id.name:core_1.types.isAssignmentExpression(t)&&core_1.types.isIdentifier(t.left)?t.left.name:void 0))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t,Types_1.Types.FunctionalComponent))}})},instrumentLifecycle=function(e){instrumentComponents(e,function(e,t){return core_1.template.statement(_templateObject5=_templateObject5||(0,_taggedTemplateLiteral2.default)(["NAME._dtInfo = { type: TYPE, name: 'NAME_STR' }"]))({NAME:core_1.types.identifier(e),TYPE:core_1.types.numericLiteral(t),NAME_STR:core_1.types.stringLiteral(e)})})},instrumentComponentNames=function(e){instrumentComponents(e,function(e){return core_1.template.statement(_templateObject6=_templateObject6||(0,_taggedTemplateLiteral2.default)(["NAME.dtName = 'NAME_STR'"]))({NAME:core_1.types.identifier(e),NAME_STR:core_1.types.stringLiteral(e)})})},instrumentInput=function(e){var l=new Map([["react-native",{proxy:"".concat(INSTRUMENTATION_LIBS,"/react-native/"),components:new Set(["TouchableHighlight","TouchableNativeFeedback","TouchableOpacity","TouchableWithoutFeedback","Button","RefreshControl","Text","Pressable","Switch"])}],["react-native-gesture-handler",{proxy:"".concat(INSTRUMENTATION_LIBS,"/community/gesture-handler/"),components:new Set(["TouchableHighlight","TouchableNativeFeedback","TouchableOpacity","TouchableWithoutFeedback","RectButton","BorderlessButton","BaseButton"])}],["@react-native-picker/picker",{proxy:"".concat(INSTRUMENTATION_LIBS,"/community/Picker"),components:new Set(["Picker","PickerIOS"])}]]);e.traverse({ImportDeclaration:function(e){if(void 0===e.node.processed){var t=e.node.source;if(l.has(t.value)){var r=l.get(t.value),n=e.node.specifiers,a=[],i=[];if(n.forEach(function(e,t){var n;core_1.types.isImportSpecifier(e)&&(n=core_1.types.isIdentifier(e.imported)?e.imported.name:e.imported.value,r.components.has(n)||(a.push(e),i.push(t)))}),a.length!==n.length){var o,s=_createForOfIteratorHelper(i.reverse());try{for(s.s();!(o=s.n()).done;){var c=o.value;n.splice(c,1)}}catch(e){s.e(e)}finally{s.f()}0<a.length&&((t=core_1.types.importDeclaration(a,core_1.types.stringLiteral(t.value))).processed=!0,e.insertBefore(t)),e.node.source=core_1.types.stringLiteral(r.proxy),e.scope.crawl()}}}},CallExpression:function(e){core_1.types.isIdentifier(e.node.callee,{name:"require"})&&(e=e.node.arguments[0],core_1.types.isStringLiteral(e))&&l.has(e.value)&&(e.value=l.get(e.value).proxy)}})},instrumentJsxNames=function(e){e.traverse({JSXOpeningElement:function(e){var t=e.node.name,t=core_1.types.isJSXIdentifier(t)?t.name:core_1.types.isJSXMemberExpression(t)?(0,generator_1.default)(t).code:void 0;t&&e.node.attributes.push(core_1.types.jsxAttribute(core_1.types.jsxIdentifier("dtName"),core_1.types.stringLiteral(t)))}})},instrumentConfigurationPreset=function(e){var t,n=(0,GetValuesFromPackage_1.getHostAppBundleInfo)(PathsConstants_1.default.getPackageJsonFile()),r={getLifecycleUpdate:reactOptions.lifecycle.includeUpdate,getLogLevel:reactOptions.debug?0:1,getBundleName:null!=(t=reactOptions.bundleName)?t:null==n?void 0:n.name,getBundleVersion:null!=(t=reactOptions.bundleVersion)?t:null==n?void 0:n.version,getActionNamePrivacy:reactOptions.input.actionNamePrivacy,getActionNamePreference:reactOptions.input.actionNamePreference,getActionNameAlgorithm:reactOptions.input.actionNameAlgorithm,isErrorHandlerEnabled:reactOptions.errorHandler.enabled,isReportFatalErrorAsCrash:reactOptions.errorHandler.reportFatalErrorAsCrash,isAutoStartupEnabled:reactOptions.autoStart};e.traverse({ClassMethod:function(e){var t;core_1.types.isIdentifier(e.node.key)&&void 0!==(t=r[e.node.key.name])&&(e=e.node.body.body[0],core_1.types.isReturnStatement(e))&&(e.argument=core_1.types.valueToNode(t))}})};exports.default=function(){return{visitor:{Program:function(e,t){reactOptions=(0,Config_1.readConfigDefault)().react;var n,r,a,i,o,s,c=t.filename;void 0!==c&&(a=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.some(function(e){return c.includes(fspath.join("node_modules",e)+fspath.sep)})},s=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.some(function(e){return c.endsWith(e)})},!(i="")===reactOptions.debugBabelPlugin&&(i=(0,generator_1.default)(e.node).code),a("@dynatrace")&&s("ConfigurationPreset.js")&&instrumentConfigurationPreset(e),a("react-native")&&s("AppRegistry.js","AppRegistryImpl.js")&&(reactOptions.autoStart&&instrumentAppRegistry(e),reactOptions.userInteraction)&&instrumentUserInteraction(e),a("react-native")&&s("ExceptionsManager.js")&&instrumentExceptionsManager(e),a("react-native-css-interop")&&s("jsx-runtime.js","jsx-dev-runtime.js")&&instrumentCssInterop(e),reactOptions.navigation.enabled&&a("@react-navigation")&&s("BaseNavigationContainer.js","BaseNavigationContainer.tsx")&&instrumentNavigation(e),a("react")&&s("index.js")&&instrumentReactCreateElement(e),null!=(n=null==(r=reactOptions.lifecycle)?void 0:r.instrument)&&n.call(r,c)&&(!c.includes("node_modules")||a("react-native")&&s("renderApplication.js"))&&hasJSX(e)&&instrumentLifecycle(e),null==(r=null==(n=reactOptions.input)?void 0:n.instrument)||!r.call(n,c)||c.includes("node_modules")&&!a("@react-navigation","react-native-drawer-layout")||instrumentInput(e),reactOptions.userInteraction&&!c.includes("node_modules")&&(instrumentJsxNames(e),instrumentComponentNames(e)),!0===reactOptions.debugBabelPlugin)&&(o=(0,generator_1.default)(e.node).code)!==i&&(s=fspath.join(PathsConstants_1.default.getBuildPath(),fspath.relative(PathsConstants_1.default.getApplicationPath(),c)+".dtx"),fs.mkdirSync(fspath.dirname(s),{recursive:!0}),fs.writeFileSync(s,o),t.set("fileDidChange",!0))}},post:function(e){var t;!0===reactOptions.debugBabelPlugin&&!0===this.get("fileDidChange")&&(t=(0,generator_1.default)(e.ast).code,e=fspath.join(PathsConstants_1.default.getBuildPath(),fspath.relative(PathsConstants_1.default.getApplicationPath(),e.opts.filename)+".dtx.downstream"),fs.mkdirSync(fspath.dirname(e),{recursive:!0}),fs.writeFileSync(e,t))}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var n=require("@babel/runtime/helpers/interopRequireDefault"),e=n(require("@babel/runtime/helpers/toConsumableArray"));function v(n,e){var r,t,i,u,o="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(o)return i=!(t=!0),{s:function(){o=o.call(n)},n:function(){var n=o.next();return t=n.done,n},e:function(n){i=!0,r=n},f:function(){try{t||null==o.return||o.return()}finally{if(i)throw r}}};if(Array.isArray(n)||(o=a(n))||e&&n&&"number"==typeof n.length)return o&&(n=o),u=0,{s:e=function(){},n:function(){return u>=n.length?{done:!0}:{done:!1,value:n[u++]}},e:function(n){throw n},f:e};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(n,e){var r;if(n)return"string"==typeof n?t(n,e):"Map"===(r="Object"===(r={}.toString.call(n).slice(8,-1))&&n.constructor?n.constructor.name:r)||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(n,e):void 0}function t(n,e){(null==e||e>n.length)&&(e=n.length);for(var r=0,t=Array(e);r<e;r++)t[r]=n[r];return t}Object.defineProperty(exports,"t",{value:!0}),exports.instrument=void 0;var d,p=require("path"),u=require("jscodeshift"),i=require("jscodeshift/src/Collection"),r=require("../scripts/FileOperationHelper"),m=require("../scripts/PathsConstants"),y=require("../lib/core/util/GetValuesFromPackage"),o=require("../scripts/util/InstrumentUtil"),g=require("../lib/features/ui-interaction/Run"),c=require("./libs/react-native/Touchables.InstrInfo"),l=require("./libs/react-native/RefreshControl.InstrInfo"),f=require("./libs/react-native/Switch.InstrInfo"),s=require("./libs/community/gesture-handler/Touchables.InstrInfo"),P=require("./libs/community/Picker.InstrInfo"),b=require("./model/Types"),T=require("./parser/ParserUtil"),q=((n=>{n[n.i=-1]="Filtered",n[n.u=0]="Normal",n[n.o=1]="ReactNative",n[n.l=2]="React",n[n.v=3]="ReactNativeCssInterop"})(d=d||{}),[]),L=(q.push.apply(q,(0,e.default)(c.instrumentationInfo)),q.push.apply(q,(0,e.default)(l.instrumentationInfo)),q.push.apply(q,(0,e.default)(f.instrumentationInfo)),q.push.apply(q,(0,e.default)(s.instrumentationInfo)),q.push.apply(q,(0,e.default)(P.instrumentationInfo)),new Set(["AppRegistry","AppRegistryImpl","renderApplication","ExceptionsManager"])),M="@dynatrace/react-native-plugin/instrumentation/libs",instrument=function(n,e,r){e=V(e);var t=W(e);if(t!==d.i){var i=!1,u=I(e,n);if(t===d.l)G(u),i=!0;else if(t===d.o)e.endsWith("AppRegistryImpl.js")?null!=r&&r.autoStart&&$(u)&&(i=!0):e.endsWith("AppRegistry.js")?null!=r&&r.autoStart&&z(u)&&(i=!0):e.endsWith("renderApplication.js")?(A(u),i=!0):e.endsWith("ExceptionsManager.js")&&(o=void 0!==r&&r.autoStart&&r.errorHandler.enabled,K(u,r.errorHandler.reportFatalErrorAsCrash,o),i=!0);else if(t===d.v)i=Q(u)||i;else{var o=J(e,r),t=[{isEnabled:function(n,e){return!0===(null==e?void 0:e.userInteraction)},p:function(n,e,r){return(0,g.runDTUserInteraction)(n,e,r)}}].filter(function(n){return n.isEnabled(e,r)});if(r.navigation.enabled&&O(e,u))i=!0;else{if(!o.input&&!o.lifecycle&&0===t.length)return null!=r&&r.debug&&console.log("Dynatrace - Filtered All: ".concat(e)),x(e),n;o.lifecycle&&A(u)&&(i=!0),o.input&&q.forEach(function(n){n=nn(u,n);u=n.root,i=i||n.m})}var a,c=v(t);try{for(c.s();!(a=c.n()).done;){var l=a.value;try{var f=l.p(u,e,r),u=f.root;f.m&&(i=!0)}catch(n){var s=n instanceof Error?n.stack||n.message:String(n);null!=r&&r.debug&&console.log("[DynatraceInstrumentationRaw]: Feature instrumentation failed for ".concat(e,": ").concat(s))}}}catch(n){c.e(n)}finally{c.f()}}var o=i?u.toSource({quote:"single"}):n;i?N(n=o,e):x(e),null!=r&&r.debug&&i&&console.log("Dynatrace - Modified Filename: "+e)}else e.includes(p.join("@dynatrace","react-native-plugin"))&&e.endsWith(p.join("lib","core","configuration","ConfigurationPreset.js"))&&void 0!==r&&(t=(0,y.getHostAppBundleInfo)(m.default.getPackageJsonFile()),o=I(e,n),void 0!==r.lifecycle&&j(o,"getLifecycleUpdate",r.lifecycle.includeUpdate),void 0!==r.debug&&j(o,"getLogLevel",r.debug?0:1),void 0!==r.bundleName?j(o,"getBundleName",r.bundleName):null!==t&&j(o,"getBundleName",null==t?void 0:t.name),void 0!==r.bundleVersion?j(o,"getBundleVersion",r.bundleVersion):null!==t&&j(o,"getBundleVersion",null==t?void 0:t.version),void 0!==r.input&&void 0!==r.input.actionNamePrivacy&&j(o,"getActionNamePrivacy",r.input.actionNamePrivacy),void 0!==r.errorHandler&&(j(o,"isErrorHandlerEnabled",r.errorHandler.enabled),j(o,"isReportFatalErrorAsCrash",r.errorHandler.reportFatalErrorAsCrash)),r.autoStart&&j(o,"isAutoStartupEnabled",r.autoStart),n=o.toSource({quote:"single"}),N(n,e));return n},O=(exports.instrument=instrument,function(n,e){return!!U(n,e)&&(n="import { monitorNavigation } from '".concat(M,"/react-navigation/ReactNavigation';"),e.find(u.ImportDeclaration).at(0).insertBefore(n),!0)}),U=function(n,e){var r=!1;return n.includes("@react-navigation")&&n.includes("core")&&(n.includes("BaseNavigationContainer.js")||n.includes("BaseNavigationContainer.tsx"))&&e.find(u.VariableDeclarator,{id:{name:"getRootState"}}).forEach(function(n){r=!0,n.parent.insertAfter("monitorNavigation(getRootState);")}),r},A=function(n){var e=n.findJSXElements(),t=!1;return 0<e.length&&(n.find(u.FunctionDeclaration).forEach(function(n){var e,r=(0,i.fromPaths)([n]);0<r.findJSXElements().length&&null!=n&&null!=n.value&&null!=n.value.id&&n.value.id.name.toString()&&(e=r.find(u.ClassDeclaration),r=r.find(u.ClassExpression),0===e.length)&&0===r.length&&(h(n,b.Types.FunctionalComponent,n.value.id.name.toString()),t=!0)}),n.find(u.ClassDeclaration).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n&&null!=n.value&&n.value.id&&n.value.id.name.toString()&&(h(n,b.Types.ClassComponent,n.value.id.name.toString()),t=!0)}),n.find(u.ArrowFunctionExpression).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n.parent&&null!=n.parent.value&&null!=n.parent.value.id&&null!=n.parent.value.id.name&&(h(n,b.Types.FunctionalComponent,n.parent.value.id.name),t=!0)}),n.find(u.FunctionExpression).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n.parent&&null!=n.parent.value&&null!=n.parent.value.id&&null!=n.parent.value.id.name&&(h(n,b.Types.FunctionalComponent,n.parent.value.id.name),t=!0)})),t},h=function(n,e,r){for(e=u.expressionStatement(u.assignmentExpression("=",u.memberExpression(u.identifier(r),u.identifier("_dtInfo")),k(e,r)));"body"!==(null==n?void 0:n.parentPath.name);)n=n.parentPath;void 0!==n.parentPath&&n.insertAfter(e)},k=function(n,e){return u.objectExpression([u.objectProperty(u.identifier("type"),u.numericLiteral(n)),u.objectProperty(u.identifier("name"),u.stringLiteral(e))])},j=function(n,e,r){var n=n.find(u.Identifier).filter(function(n){return n.node.name===e});1===n.length&&"ReturnStatement"===(n=n.paths()[0].parent.value.body.body[0]).type&&("boolean"==typeof r&&(n.argument=u.booleanLiteral(r)),"string"==typeof r&&(n.argument=u.stringLiteral(r)),"number"==typeof r)&&(n.argument=u.numericLiteral(r))},I=function(n,e){return u.withParser((0,T.chooseParser)(n,e))(e)},V=function(n){return p.isAbsolute(n)?n.replace(m.default.getApplicationPath()+p.sep,""):n},x=function(n){try{var e=p.join(m.default.getBuildPath(),n+o.INSTRUMENTED_FILE_EXTENSION);r.default.checkIfFileExistsSync(e),r.default.deleteFileSync(e)}catch(n){}},N=function(n,e){e=p.join(m.default.getBuildPath(),e);try{r.default.checkIfFileExistsSync(p.dirname(e))}catch(n){r.default.createDirectorySync(p.dirname(e))}r.default.writeTextToFileSync(e+o.INSTRUMENTED_FILE_EXTENSION,n)},J=function(n,e){var r={input:!1,lifecycle:!1};return void 0!==e&&(void 0!==e.lifecycle&&void 0!==e.lifecycle.instrument&&e.lifecycle.instrument(n)&&(r.lifecycle=!0),void 0!==e.input)&&void 0!==e.input.instrument&&e.input.instrument(n)&&(r.input=!0),r},G=function(n){var e,n=n.find(u.Program);1===n.length&&(e=u.expressionStatement(u.callExpression(u.memberExpression(u.callExpression(u.identifier("require"),[u.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")]),u.identifier("instrumentCreateElement")),[u.memberExpression(u.identifier("module"),u.identifier("exports"))])),n.paths()[0].node.body.push(e))},$=function(n){var e=n.find(u.FunctionDeclaration,{id:{name:"runApplication"}});return 1===e.length&&(D(n,{g:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),R(e.get().value.body.body,0,w("_DynatraceApplicationHandler","startup",[])),!0)},z=function(n){var e=n.find(u.ObjectMethod,{key:{name:"runApplication"}});return 1===e.length&&(D(n,{g:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),R(e.get().value.body.body,0,w("_DynatraceApplicationHandler","startup",[])),!0)},K=function(n,r,t){var i=u;n.find(i.FunctionDeclaration,{id:{name:"handleException"}}).forEach(function(n){var e=i.callExpression(i.memberExpression(i.callExpression(i.identifier("require"),[i.literal("@dynatrace/react-native-plugin/lib/core/ErrorHandler")]),i.identifier("reportErrorToDynatrace")),[i.identifier("e"),i.identifier("isFatal"),i.literal(r),i.literal(t)]),e=i.expressionStatement(i.callExpression(i.identifier("setTimeout"),[i.arrowFunctionExpression([],i.blockStatement(n.node.body.body)),e]));n.node.body.body=[e]})},Q=function(n){var e=!1,n=n.find(u.CallExpression,{callee:{name:"require"}});return n.find(u.Literal,{value:"react/jsx-runtime"}).replaceWith(function(n){n=n.node;return n.value="@dynatrace/react-native-plugin/jsx-runtime",e=!0,n}),n.find(u.Literal,{value:"react/jsx-dev-runtime"}).replaceWith(function(n){n=n.node;return n.value="@dynatrace/react-native-plugin/jsx-dev-runtime",e=!0,n}),e},R=function(n,e){for(var r=arguments.length,t=new Array(2<r?r-2:0),i=2;i<r;i++)t[i-2]=arguments[i];return n.splice.apply(n,[e,0].concat(t))},W=function(n){if(n.includes("@dynatrace"))return d.i;var e=p.extname(n);if(".js"!==e&&".ts"!==e&&".tsx"!==e&&".jsx"!==e)return d.i;for(var r=p.parse(n),t=r.dir.split(p.sep),i=0;i<t.length;i++)if("node_modules"===t[i]){if("react-native"===t[i+1]||"create-react-class"===t[i+1]||"react-clone-referenced-element"===t[i+1])return L.has(r.name)?d.o:d.i;if("react"===t[i+1]&&"index"===r.name)return d.l;if("react-native-css-interop"===t[i+1]&&("jsx-runtime"===r.name||"jsx-dev-runtime"===r.name))return d.v}return d.u},X=function(n,e,r){var t=Y(n,e,r);return Z(n,e,r)||t},Y=function(n,e,r){var t=en(n,e);return 0<t.length&&(void 0!==(t=C(t,e.reference,!1))&&(r.g=t.localName),cn(n,r),!0)},Z=function(n,e,r){var t=E(n,e.module);if(1===t.length){t=C(t,e.reference,!0);if(void 0!==t)return ln(n,r.defaultImport,t.localName,"ImportNamespaceSpecifier"===t.type),!0}return!1},nn=function(n,e){var r=JSON.parse(JSON.stringify(e.new));return{root:n,m:X(n,e.old,r)||rn(n,e.old,e.new.defaultImport)}},en=function(n,e){return n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e.module&&null!=n.node.specifiers&&n.node.specifiers.some(function(n){return S(n)&&n.imported.name===e.reference||n.local&&n.local.name===e.reference})})},S=function(n){return void 0!==n.imported},rn=function(n,e,r){var t=!1;return n.find(u.CallExpression).filter(function(n){return tn(n.node.callee)&&un(n.node.arguments[0])&&n.node.arguments[0].value===e.module&&void 0!==n.parent}).forEach(function(n){(void 0===n.parent.value.property||void 0!==n.parent.value.property&&void 0!==n.parent.value.property.name&&n.parent.value.property.name===e.reference)&&(n.node.arguments[0].value=r,t=t||!0)}),t},tn=function(n){return"require"===n.name},un=function(n){return"StringLiteral"===n.type||"Literal"===n.type},E=function(n,e){return n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e})},C=function(n,r,t){var i;return n.forEach(function(n){void 0!==n.node.specifiers&&(n.node.specifiers=n.node.specifiers.filter(function(n){var e;return S(n)&&!t?((e=n.imported.name!==r)||null==n.local||n.imported.name===n.local.name||(i={localName:n.local.name.toString(),type:n.type}),e):!(!S(n)&&t&&(null!=n.local&&(i={localName:n.local.name.toString(),type:n.type}),1))}),0===n.node.specifiers.length)&&n.prune()}),i},on=function(n,e){n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e.module}).forEach(function(n){null!=n.node.specifiers&&n.node.specifiers.push(B(e))})},an=function(n,e,r){n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e}).forEach(function(n){null!=n.node.specifiers&&n.node.specifiers.push(r)})},H=function(n,e,r){var t=n.find(u.ImportDeclaration);0<t.length?u(t.paths()[0]).insertAfter(_(e,r)):1===(t=n.find(u.Program)).length&&t.paths()[0].node.body.unshift(_(e,r))},cn=function(n,e){0<E(n,e.module).length?on(n,e):H(n,e.module,[B(e)])},ln=function(n,e,r,t){var i=E(n,e),t=(t?yn:mn)(r);0<i.length?an(n,e,t):H(n,e,[t])},D=function(n,e){n=n.find(u.VariableDeclaration);0<n.length&&u(n.paths()[0]).insertAfter(sn(e))},w=function(n,e,r){return u.expressionStatement(fn(n,e,r))},fn=function(n,e,r){return u.callExpression(pn(n,e),r)},sn=function(n){return u.variableDeclaration("var",[vn(n)])},vn=function(n){return u.variableDeclarator(void 0!==n.g?u.identifier(n.g):u.identifier(n.reference),(0<n.reference.length?dn:F)(n))},dn=function(n){return u.memberExpression(F(n),u.identifier(n.reference))},pn=function(n,e){return u.memberExpression(u.identifier(n),u.identifier(e))},F=function(n){return u.callExpression(u.identifier("require"),[u.literal(n.module)])},_=function(n,e){return u.importDeclaration(e,u.literal(n))},B=function(n){return void 0!==n.g?u.importSpecifier(u.identifier(n.reference),u.identifier(n.g)):u.importSpecifier(u.identifier(n.reference))},mn=function(n){return u.importDefaultSpecifier(u.identifier(n))},yn=function(n){return u.importNamespaceSpecifier(u.identifier(n))};
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));function _createForOfIteratorHelper(e,t){var n,r,i,o,a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(a)return i=!(r=!0),{s:function(){a=a.call(e)},n:function(){var e=a.next();return r=e.done,e},e:function(e){i=!0,n=e},f:function(){try{r||null==a.return||a.return()}finally{if(i)throw n}}};if(Array.isArray(e)||(a=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return a&&(e=a),o=0,{s:t=function(){},n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.instrument=void 0;var FileType,nodePath=require("path"),jscodeshift=require("jscodeshift"),Collection_1=require("jscodeshift/src/Collection"),FileOperationHelper_1=require("../scripts/FileOperationHelper"),PathsConstants_1=require("../scripts/PathsConstants"),GetValuesFromPackage_1=require("../lib/core/util/GetValuesFromPackage"),InstrumentUtil_1=require("../scripts/util/InstrumentUtil"),Run_1=require("../lib/features/ui-interaction/Run"),Touchables_InstrInfo_1=require("./libs/react-native/Touchables.InstrInfo"),RefreshControl_InstrInfo_1=require("./libs/react-native/RefreshControl.InstrInfo"),Switch_InstrInfo_1=require("./libs/react-native/Switch.InstrInfo"),Touchables_InstrInfo_2=require("./libs/community/gesture-handler/Touchables.InstrInfo"),Picker_InstrInfo_1=require("./libs/community/Picker.InstrInfo"),Types_1=require("./model/Types"),ParserUtil_1=require("./parser/ParserUtil"),referenceListInput=((e=>{e[e.Filtered=-1]="Filtered",e[e.Normal=0]="Normal",e[e.ReactNative=1]="ReactNative",e[e.React=2]="React",e[e.ReactNativeCssInterop=3]="ReactNativeCssInterop"})(FileType=FileType||{}),[]),whiteList=(referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Touchables_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(RefreshControl_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Switch_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Touchables_InstrInfo_2.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Picker_InstrInfo_1.instrumentationInfo)),new Set(["AppRegistry","AppRegistryImpl","renderApplication","ExceptionsManager"])),instrumentationLibraryFolder="@dynatrace/react-native-plugin/instrumentation/libs",instrument=function(e,t,n){t=correctFilename(t);var r=shouldInstrumentFile(t);if(r!==FileType.Filtered){var i=!1,o=parseSource(t,e);if(r===FileType.React)addCreateElementInstrumentation(o),i=!0;else if(r===FileType.ReactNative)t.endsWith("AppRegistryImpl.js")?null!=n&&n.autoStart&&addStartupCallRegistryImpl(o)&&(i=!0):t.endsWith("AppRegistry.js")?null!=n&&n.autoStart&&addStartupCallRegistry(o)&&(i=!0):t.endsWith("renderApplication.js")?(addInfoToComponent(o),i=!0):t.endsWith("ExceptionsManager.js")&&(a=void 0!==n&&n.autoStart&&n.errorHandler.enabled,addReportErrorToDynatraceCall(o,n.errorHandler.reportFatalErrorAsCrash,a),i=!0);else if(r===FileType.ReactNativeCssInterop)i=replaceReactWithDynatraceJsxRuntime(o)||i;else{var a=getInstrumentationList(t,n),r=[{isEnabled:function(e,t){return!0===(null==t?void 0:t.userInteraction)},run:function(e,t,n){return(0,Run_1.runDTUserInteraction)(e,t,n)}}].filter(function(e){return e.isEnabled(t,n)});if(n.navigation.enabled&&instrumentReactNavigation(t,o))i=!0;else{if(!a.input&&!a.lifecycle&&0===r.length)return null!=n&&n.debug&&console.log("Dynatrace - Filtered All: ".concat(t)),deleteTransformation(t),e;a.lifecycle&&addInfoToComponent(o)&&(i=!0),a.input&&referenceListInput.forEach(function(e){e=swapReferences(o,e);o=e.root,i=i||e.modified})}var s,l=_createForOfIteratorHelper(r);try{for(l.s();!(s=l.n()).done;){var c=s.value;try{var u=c.run(o,t,n),o=u.root;u.modified&&(i=!0)}catch(e){var f=e instanceof Error?e.stack||e.message:String(e);null!=n&&n.debug&&console.log("[DynatraceInstrumentationRaw]: Feature instrumentation failed for ".concat(t,": ").concat(f))}}}catch(e){l.e(e)}finally{l.f()}}var a=i?o.toSource({quote:"single"}):e;i?writeTransformation(e=a,t):deleteTransformation(t),null!=n&&n.debug&&i&&console.log("Dynatrace - Modified Filename: "+t)}else t.includes(nodePath.join("@dynatrace","react-native-plugin"))&&t.endsWith(nodePath.join("lib","core","configuration","ConfigurationPreset.js"))&&void 0!==n&&(r=(0,GetValuesFromPackage_1.getHostAppBundleInfo)(PathsConstants_1.default.getPackageJsonFile()),a=parseSource(t,e),void 0!==n.lifecycle&&changeConfigurationValue(a,"getLifecycleUpdate",n.lifecycle.includeUpdate),void 0!==n.debug&&changeConfigurationValue(a,"getLogLevel",n.debug?0:1),void 0!==n.bundleName?changeConfigurationValue(a,"getBundleName",n.bundleName):null!==r&&changeConfigurationValue(a,"getBundleName",null==r?void 0:r.name),void 0!==n.bundleVersion?changeConfigurationValue(a,"getBundleVersion",n.bundleVersion):null!==r&&changeConfigurationValue(a,"getBundleVersion",null==r?void 0:r.version),void 0!==(null==(r=n.input)?void 0:r.actionNamePrivacy)&&changeConfigurationValue(a,"getActionNamePrivacy",n.input.actionNamePrivacy),void 0!==(null==(r=n.input)?void 0:r.actionNamePreference)&&changeConfigurationValue(a,"getActionNamePreference",n.input.actionNamePreference),void 0!==(null==(r=n.input)?void 0:r.actionNameAlgorithm)&&changeConfigurationValue(a,"getActionNameAlgorithm",n.input.actionNameAlgorithm),void 0!==n.errorHandler&&(changeConfigurationValue(a,"isErrorHandlerEnabled",n.errorHandler.enabled),changeConfigurationValue(a,"isReportFatalErrorAsCrash",n.errorHandler.reportFatalErrorAsCrash)),n.autoStart&&changeConfigurationValue(a,"isAutoStartupEnabled",n.autoStart),e=a.toSource({quote:"single"}),writeTransformation(e,t));return e},instrumentReactNavigation=(exports.instrument=instrument,function(e,t){return!!instrumentReactBaseNavigationContainer(e,t)&&(e="import { monitorNavigation } from '".concat(instrumentationLibraryFolder,"/react-navigation/ReactNavigation';"),t.find(jscodeshift.ImportDeclaration).at(0).insertBefore(e),!0)}),instrumentReactBaseNavigationContainer=function(e,t){var n=!1;return e.includes("@react-navigation")&&e.includes("core")&&(e.includes("BaseNavigationContainer.js")||e.includes("BaseNavigationContainer.tsx"))&&t.find(jscodeshift.VariableDeclarator,{id:{name:"getRootState"}}).forEach(function(e){n=!0,e.parent.insertAfter("monitorNavigation(getRootState);")}),n},addInfoToComponent=function(e){var t=e.findJSXElements(),r=!1;return 0<t.length&&(e.find(jscodeshift.FunctionDeclaration).forEach(function(e){var t,n=(0,Collection_1.fromPaths)([e]);0<n.findJSXElements().length&&null!=e&&null!=e.value&&null!=e.value.id&&e.value.id.name.toString()&&(t=n.find(jscodeshift.ClassDeclaration),n=n.find(jscodeshift.ClassExpression),0===t.length)&&0===n.length&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.value.id.name.toString()),r=!0)}),e.find(jscodeshift.ClassDeclaration).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e&&null!=e.value&&e.value.id&&e.value.id.name.toString()&&(insertExpressionIntoNextBody(e,Types_1.Types.ClassComponent,e.value.id.name.toString()),r=!0)}),e.find(jscodeshift.ArrowFunctionExpression).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e.parent&&null!=e.parent.value&&null!=e.parent.value.id&&null!=e.parent.value.id.name&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.parent.value.id.name),r=!0)}),e.find(jscodeshift.FunctionExpression).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e.parent&&null!=e.parent.value&&null!=e.parent.value.id&&null!=e.parent.value.id.name&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.parent.value.id.name),r=!0)})),r},insertExpressionIntoNextBody=function(e,t,n){for(t=jscodeshift.expressionStatement(jscodeshift.assignmentExpression("=",jscodeshift.memberExpression(jscodeshift.identifier(n),jscodeshift.identifier("_dtInfo")),createComponentInfo(t,n)));"body"!==(null==e?void 0:e.parentPath.name);)e=e.parentPath;void 0!==e.parentPath&&e.insertAfter(t)},createComponentInfo=function(e,t){return jscodeshift.objectExpression([jscodeshift.objectProperty(jscodeshift.identifier("type"),jscodeshift.numericLiteral(e)),jscodeshift.objectProperty(jscodeshift.identifier("name"),jscodeshift.stringLiteral(t))])},changeConfigurationValue=function(e,t,n){var e=e.find(jscodeshift.Identifier).filter(function(e){return e.node.name===t});1===e.length&&"ReturnStatement"===(e=e.paths()[0].parent.value.body.body[0]).type&&("boolean"==typeof n&&(e.argument=jscodeshift.booleanLiteral(n)),"string"==typeof n&&(e.argument=jscodeshift.stringLiteral(n)),"number"==typeof n)&&(e.argument=jscodeshift.numericLiteral(n))},parseSource=function(e,t){return jscodeshift.withParser((0,ParserUtil_1.chooseParser)(e,t))(t)},correctFilename=function(e){return nodePath.isAbsolute(e)?e.replace(PathsConstants_1.default.getApplicationPath()+nodePath.sep,""):e},deleteTransformation=function(e){try{var t=nodePath.join(PathsConstants_1.default.getBuildPath(),e+InstrumentUtil_1.INSTRUMENTED_FILE_EXTENSION);FileOperationHelper_1.default.checkIfFileExistsSync(t),FileOperationHelper_1.default.deleteFileSync(t)}catch(e){}},writeTransformation=function(e,t){t=nodePath.join(PathsConstants_1.default.getBuildPath(),t);try{FileOperationHelper_1.default.checkIfFileExistsSync(nodePath.dirname(t))}catch(e){FileOperationHelper_1.default.createDirectorySync(nodePath.dirname(t))}FileOperationHelper_1.default.writeTextToFileSync(t+InstrumentUtil_1.INSTRUMENTED_FILE_EXTENSION,e)},getInstrumentationList=function(e,t){var n={input:!1,lifecycle:!1};return void 0!==t&&(void 0!==t.lifecycle&&void 0!==t.lifecycle.instrument&&t.lifecycle.instrument(e)&&(n.lifecycle=!0),void 0!==t.input)&&void 0!==t.input.instrument&&t.input.instrument(e)&&(n.input=!0),n},addCreateElementInstrumentation=function(e){var t,e=e.find(jscodeshift.Program);1===e.length&&(t=jscodeshift.expressionStatement(jscodeshift.callExpression(jscodeshift.memberExpression(jscodeshift.callExpression(jscodeshift.identifier("require"),[jscodeshift.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")]),jscodeshift.identifier("instrumentCreateElement")),[jscodeshift.memberExpression(jscodeshift.identifier("module"),jscodeshift.identifier("exports"))])),e.paths()[0].node.body.push(t))},addStartupCallRegistryImpl=function(e){var t=e.find(jscodeshift.FunctionDeclaration,{id:{name:"runApplication"}});return 1===t.length&&(addRequire(e,{customName:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),insertInArray(t.get().value.body.body,0,expressionStatement("_DynatraceApplicationHandler","startup",[])),!0)},addStartupCallRegistry=function(e){var t=e.find(jscodeshift.ObjectMethod,{key:{name:"runApplication"}});return 1===t.length&&(addRequire(e,{customName:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),insertInArray(t.get().value.body.body,0,expressionStatement("_DynatraceApplicationHandler","startup",[])),!0)},addReportErrorToDynatraceCall=function(e,n,r){var i=jscodeshift;e.find(i.FunctionDeclaration,{id:{name:"handleException"}}).forEach(function(e){var t=i.callExpression(i.memberExpression(i.callExpression(i.identifier("require"),[i.literal("@dynatrace/react-native-plugin/lib/core/ErrorHandler")]),i.identifier("reportErrorToDynatrace")),[i.identifier("e"),i.identifier("isFatal"),i.literal(n),i.literal(r)]),t=i.expressionStatement(i.callExpression(i.identifier("setTimeout"),[i.arrowFunctionExpression([],i.blockStatement(e.node.body.body)),t]));e.node.body.body=[t]})},replaceReactWithDynatraceJsxRuntime=function(e){var t=!1,e=e.find(jscodeshift.CallExpression,{callee:{name:"require"}});return e.find(jscodeshift.Literal,{value:"react/jsx-runtime"}).replaceWith(function(e){e=e.node;return e.value="@dynatrace/react-native-plugin/jsx-runtime",t=!0,e}),e.find(jscodeshift.Literal,{value:"react/jsx-dev-runtime"}).replaceWith(function(e){e=e.node;return e.value="@dynatrace/react-native-plugin/jsx-dev-runtime",t=!0,e}),t},insertInArray=function(e,t){for(var n=arguments.length,r=new Array(2<n?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];return e.splice.apply(e,[t,0].concat(r))},shouldInstrumentFile=function(e){if(e.includes("@dynatrace"))return FileType.Filtered;var t=nodePath.extname(e);if(".js"!==t&&".ts"!==t&&".tsx"!==t&&".jsx"!==t)return FileType.Filtered;for(var n=nodePath.parse(e),r=n.dir.split(nodePath.sep),i=0;i<r.length;i++)if("node_modules"===r[i]){if("react-native"===r[i+1]||"create-react-class"===r[i+1]||"react-clone-referenced-element"===r[i+1])return whiteList.has(n.name)?FileType.ReactNative:FileType.Filtered;if("react"===r[i+1]&&"index"===n.name)return FileType.React;if("react-native-css-interop"===r[i+1]&&("jsx-runtime"===n.name||"jsx-dev-runtime"===n.name))return FileType.ReactNativeCssInterop}return FileType.Normal},handleImports=function(e,t,n){var r=handleDestructuredImport(e,t,n);return handleDefaultImport(e,t,n)||r},handleDestructuredImport=function(e,t,n){var r=findImportSpecifier(e,t);return 0<r.length&&(void 0!==(r=removeImportSpecifier(r,t.reference,!1))&&(n.customName=r.localName),addReference(e,n),!0)},handleDefaultImport=function(e,t,n){var r=findImportDeclaration(e,t.module);if(1===r.length){r=removeImportSpecifier(r,t.reference,!0);if(void 0!==r)return addDefaultImport(e,n.defaultImport,r.localName,"ImportNamespaceSpecifier"===r.type),!0}return!1},swapReferences=function(e,t){var n=JSON.parse(JSON.stringify(t.new));return{root:e,modified:handleImports(e,t.old,n)||modifyRequireModule(e,t.old,t.new.defaultImport)}},findImportSpecifier=function(e,t){return e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t.module&&null!=e.node.specifiers&&e.node.specifiers.some(function(e){return isImportSpecifier(e)&&e.imported.name===t.reference||e.local&&e.local.name===t.reference})})},isImportSpecifier=function(e){return void 0!==e.imported},modifyRequireModule=function(e,t,n){var r=!1;return e.find(jscodeshift.CallExpression).filter(function(e){return isRequire(e.node.callee)&&isArgumentALiteral(e.node.arguments[0])&&e.node.arguments[0].value===t.module&&void 0!==e.parent}).forEach(function(e){(void 0===e.parent.value.property||void 0!==e.parent.value.property&&void 0!==e.parent.value.property.name&&e.parent.value.property.name===t.reference)&&(e.node.arguments[0].value=n,r=r||!0)}),r},isRequire=function(e){return"require"===e.name},isArgumentALiteral=function(e){return"StringLiteral"===e.type||"Literal"===e.type},findImportDeclaration=function(e,t){return e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t})},removeImportSpecifier=function(e,n,r){var i;return e.forEach(function(e){void 0!==e.node.specifiers&&(e.node.specifiers=e.node.specifiers.filter(function(e){var t;return isImportSpecifier(e)&&!r?((t=e.imported.name!==n)||null==e.local||e.imported.name===e.local.name||(i={localName:e.local.name.toString(),type:e.type}),t):!(!isImportSpecifier(e)&&r&&(null!=e.local&&(i={localName:e.local.name.toString(),type:e.type}),1))}),0===e.node.specifiers.length)&&e.prune()}),i},insertImportSpecifier=function(e,t){e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t.module}).forEach(function(e){null!=e.node.specifiers&&e.node.specifiers.push(importSpecifier(t))})},insertImportDefaultSpecifier=function(e,t,n){e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t}).forEach(function(e){null!=e.node.specifiers&&e.node.specifiers.push(n)})},insertImportDeclaration=function(e,t,n){var r=e.find(jscodeshift.ImportDeclaration);0<r.length?jscodeshift(r.paths()[0]).insertAfter(importDeclaration(t,n)):1===(r=e.find(jscodeshift.Program)).length&&r.paths()[0].node.body.unshift(importDeclaration(t,n))},addReference=function(e,t){0<findImportDeclaration(e,t.module).length?insertImportSpecifier(e,t):insertImportDeclaration(e,t.module,[importSpecifier(t)])},addDefaultImport=function(e,t,n,r){var i=findImportDeclaration(e,t),r=(r?importNamespaceSpecifier:importDefaultSpecifier)(n);0<i.length?insertImportDefaultSpecifier(e,t,r):insertImportDeclaration(e,t,[r])},addRequire=function(e,t){e=e.find(jscodeshift.VariableDeclaration);0<e.length&&jscodeshift(e.paths()[0]).insertAfter(requireDeclaration(t))},expressionStatement=function(e,t,n){return jscodeshift.expressionStatement(callExpression(e,t,n))},callExpression=function(e,t,n){return jscodeshift.callExpression(memberExpression(e,t),n)},requireDeclaration=function(e){return jscodeshift.variableDeclaration("var",[requireDeclarator(e)])},requireDeclarator=function(e){return jscodeshift.variableDeclarator(void 0!==e.customName?jscodeshift.identifier(e.customName):jscodeshift.identifier(e.reference),(0<e.reference.length?memberExpressionRequire:requireExpression)(e))},memberExpressionRequire=function(e){return jscodeshift.memberExpression(requireExpression(e),jscodeshift.identifier(e.reference))},memberExpression=function(e,t){return jscodeshift.memberExpression(jscodeshift.identifier(e),jscodeshift.identifier(t))},requireExpression=function(e){return jscodeshift.callExpression(jscodeshift.identifier("require"),[jscodeshift.literal(e.module)])},importDeclaration=function(e,t){return jscodeshift.importDeclaration(t,jscodeshift.literal(e))},importSpecifier=function(e){return void 0!==e.customName?jscodeshift.importSpecifier(jscodeshift.identifier(e.reference),jscodeshift.identifier(e.customName)):jscodeshift.importSpecifier(jscodeshift.identifier(e.reference))},importDefaultSpecifier=function(e){return jscodeshift.importDefaultSpecifier(jscodeshift.identifier(e))},importNamespaceSpecifier=function(e){return jscodeshift.importNamespaceSpecifier(jscodeshift.identifier(e))};
|
|
@@ -16,10 +16,10 @@ const instrumentJsxCall = (jsxFunction) => (...args) => {
|
|
|
16
16
|
? args[1].dtActionName
|
|
17
17
|
: args[0]._dtInfo.name;
|
|
18
18
|
if (args[2] !== undefined) {
|
|
19
|
-
return
|
|
19
|
+
return ReactRuntime.jsx(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps, args[2] + '_dt');
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
return
|
|
22
|
+
return ReactRuntime.jsx(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
else if (args[0]._dtInfo.type === Types_1.Types.ClassComponent &&
|
|
@@ -27,10 +27,10 @@ const instrumentJsxCall = (jsxFunction) => (...args) => {
|
|
|
27
27
|
args[0].prototype.isReactComponent !== undefined) {
|
|
28
28
|
const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: jsxFunction(...args) });
|
|
29
29
|
if (args[2] !== undefined) {
|
|
30
|
-
return
|
|
30
|
+
return ReactRuntime.jsx(ClassComponent_1.DynatraceClassComponent, wrapperProps, args[2] + '_dt');
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
return
|
|
33
|
+
return ReactRuntime.jsx(ClassComponent_1.DynatraceClassComponent, wrapperProps);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
(0, ElementHelper_1.modifyElement)(args[0], args[1]);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RootWrapper = exports.wrapProvider = exports.notifyPress = void 0;
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
const ConfigurationHandler_1 = require("../../lib/core/configuration/ConfigurationHandler");
|
|
7
|
+
const EventPipeline_1 = require("../../lib/next/events/EventPipeline");
|
|
8
|
+
const TOUCH_FLUSH_DELAY = 250;
|
|
9
|
+
let pendingTouch = null;
|
|
10
|
+
const getFiberPath = (fiber) => {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
let anyParentMasked = false;
|
|
13
|
+
let path = [];
|
|
14
|
+
let lastDtName;
|
|
15
|
+
while (fiber != null) {
|
|
16
|
+
const dtInfoName = (_a = fiber.type) === null || _a === void 0 ? void 0 : _a.dtName;
|
|
17
|
+
const dtName = (_b = fiber.memoizedProps) === null || _b === void 0 ? void 0 : _b.dtName;
|
|
18
|
+
const effectiveName = dtName !== null && dtName !== void 0 ? dtName : dtInfoName;
|
|
19
|
+
if (effectiveName && effectiveName !== lastDtName) {
|
|
20
|
+
path = [effectiveName, ...path];
|
|
21
|
+
lastDtName = effectiveName;
|
|
22
|
+
}
|
|
23
|
+
anyParentMasked =
|
|
24
|
+
anyParentMasked || ((_c = fiber.memoizedProps) === null || _c === void 0 ? void 0 : _c.dtMask) == true;
|
|
25
|
+
fiber = fiber.return;
|
|
26
|
+
}
|
|
27
|
+
return { path, anyParentMasked };
|
|
28
|
+
};
|
|
29
|
+
const flatten = (children) => Array.isArray(children) ? children.map(String).join('') : String(children);
|
|
30
|
+
function findRCTTextChild(fiber) {
|
|
31
|
+
let node = fiber.child;
|
|
32
|
+
while (node) {
|
|
33
|
+
if (node.type === 'RCTText') {
|
|
34
|
+
return node;
|
|
35
|
+
}
|
|
36
|
+
const found = findRCTTextChild(node);
|
|
37
|
+
if (found)
|
|
38
|
+
return found;
|
|
39
|
+
node = node.sibling;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const getHostComponentInfo = (event) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
let fiber = event._targetInst;
|
|
46
|
+
if (!fiber) {
|
|
47
|
+
console.warn('Assumption violated: _targetInst not found');
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
if (fiber.type === 'RNGestureHandlerButton') {
|
|
51
|
+
fiber = (_a = findRCTTextChild(fiber)) !== null && _a !== void 0 ? _a : fiber;
|
|
52
|
+
}
|
|
53
|
+
if (typeof fiber.type !== 'string') {
|
|
54
|
+
console.warn('Assumption violated: leaf fiber not a host component');
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const { path, anyParentMasked } = getFiberPath(fiber);
|
|
58
|
+
const id = path.join('/');
|
|
59
|
+
const leaf = path[path.length - 1];
|
|
60
|
+
const components = [leaf];
|
|
61
|
+
const { nameOrigin, detectedName } = fiber.type !== 'RCTText'
|
|
62
|
+
? {
|
|
63
|
+
nameOrigin: 'component',
|
|
64
|
+
detectedName: (_b = fiber.memoizedProps.accessibilityLabel) !== null && _b !== void 0 ? _b : leaf,
|
|
65
|
+
}
|
|
66
|
+
: anyParentMasked
|
|
67
|
+
? {
|
|
68
|
+
nameOrigin: 'masked',
|
|
69
|
+
detectedName: '***',
|
|
70
|
+
}
|
|
71
|
+
: {
|
|
72
|
+
nameOrigin: 'text',
|
|
73
|
+
detectedName: flatten(fiber.memoizedProps.children),
|
|
74
|
+
};
|
|
75
|
+
return { id, components, detectedName, nameOrigin };
|
|
76
|
+
};
|
|
77
|
+
const flushTouch = (responderComponentInfo) => {
|
|
78
|
+
if (!pendingTouch)
|
|
79
|
+
return;
|
|
80
|
+
const { touchedComponentInfo, positions, timeoutId } = pendingTouch;
|
|
81
|
+
clearTimeout(timeoutId);
|
|
82
|
+
pendingTouch = null;
|
|
83
|
+
const event = Object.assign({ 'characteristics.has_user_interaction': true, 'ui_element.detected_name': touchedComponentInfo.detectedName, 'ui_element.components': touchedComponentInfo.components, 'ui_element.id': touchedComponentInfo.id, 'interaction.type': 'touch', positions, 'ui_element.name_origin': touchedComponentInfo.nameOrigin }, (responderComponentInfo && {
|
|
84
|
+
'ui_element.responder.detected_name': responderComponentInfo.detectedName,
|
|
85
|
+
'ui_element.responder.components': responderComponentInfo.components,
|
|
86
|
+
'ui_element.responder.id': responderComponentInfo.id,
|
|
87
|
+
'ui_element.responder.name_origin': responderComponentInfo.nameOrigin,
|
|
88
|
+
}));
|
|
89
|
+
EventPipeline_1.EventPipeline.insertEvent(event);
|
|
90
|
+
};
|
|
91
|
+
const onTouch = (e) => {
|
|
92
|
+
if (!ConfigurationHandler_1.ConfigurationHandler.isUserInteractionEnabled())
|
|
93
|
+
return;
|
|
94
|
+
flushTouch();
|
|
95
|
+
const touchedComponentInfo = getHostComponentInfo(e);
|
|
96
|
+
if (!touchedComponentInfo)
|
|
97
|
+
return;
|
|
98
|
+
const { pageX, pageY } = e.nativeEvent;
|
|
99
|
+
const positions = [{ x: Math.trunc(pageX), y: Math.trunc(pageY) }];
|
|
100
|
+
const timeoutId = setTimeout(flushTouch, TOUCH_FLUSH_DELAY);
|
|
101
|
+
pendingTouch = { touchedComponentInfo, positions, timeoutId };
|
|
102
|
+
};
|
|
103
|
+
const notifyPress = (event) => flushTouch(getHostComponentInfo(event));
|
|
104
|
+
exports.notifyPress = notifyPress;
|
|
105
|
+
const wrapProvider = (originalProvider) => () => {
|
|
106
|
+
const Original = originalProvider();
|
|
107
|
+
return function DtRootWrapped(props) {
|
|
108
|
+
return (React.createElement(exports.RootWrapper, null,
|
|
109
|
+
React.createElement(Original, Object.assign({}, props))));
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
exports.wrapProvider = wrapProvider;
|
|
113
|
+
const RootWrapper = ({ children }) => (React.createElement(react_native_1.View, { pointerEvents: "box-none", collapsable: false, style: { flex: 1 }, onTouchStart: onTouch }, children));
|
|
114
|
+
exports.RootWrapper = RootWrapper;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
var _a, _b;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
require("proxy-polyfill");
|
|
5
|
+
const PickerRN = require("@react-native-picker/picker");
|
|
5
6
|
const Types_1 = require("../../model/Types");
|
|
6
|
-
const PickerRN = require('@react-native-picker/picker');
|
|
7
7
|
const dynatraceProxy = new Proxy(PickerRN, {
|
|
8
8
|
get: (target, property) => {
|
|
9
9
|
if (dynatraceInstrument[property] !== undefined) {
|
|
@@ -21,3 +21,5 @@ exports.instrumentationInfo.push(generateInstrumentation('TouchableOpacity'));
|
|
|
21
21
|
exports.instrumentationInfo.push(generateInstrumentation('TouchableNativeFeedback'));
|
|
22
22
|
exports.instrumentationInfo.push(generateInstrumentation('TouchableWithoutFeedback'));
|
|
23
23
|
exports.instrumentationInfo.push(generateInstrumentation('RectButton'));
|
|
24
|
+
exports.instrumentationInfo.push(generateInstrumentation('BorderlessButton'));
|
|
25
|
+
exports.instrumentationInfo.push(generateInstrumentation('BaseButton'));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RectButton = exports.TouchableWithoutFeedback = exports.TouchableNativeFeedback = exports.TouchableHighlight = exports.TouchableOpacity = void 0;
|
|
3
|
+
exports.BaseButton = exports.BorderlessButton = exports.RectButton = exports.TouchableWithoutFeedback = exports.TouchableNativeFeedback = exports.TouchableHighlight = exports.TouchableOpacity = void 0;
|
|
4
4
|
const GestureHandler = require("react-native-gesture-handler");
|
|
5
5
|
const withOnPressMonitoring_1 = require("../../withOnPressMonitoring");
|
|
6
6
|
exports.TouchableOpacity = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.TouchableOpacity, 'Touchable');
|
|
@@ -8,3 +8,5 @@ exports.TouchableHighlight = (0, withOnPressMonitoring_1.withOnPressMonitoring)(
|
|
|
8
8
|
exports.TouchableNativeFeedback = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.TouchableNativeFeedback, 'Touchable');
|
|
9
9
|
exports.TouchableWithoutFeedback = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.TouchableWithoutFeedback, 'Touchable');
|
|
10
10
|
exports.RectButton = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.RectButton, 'Button');
|
|
11
|
+
exports.BorderlessButton = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.BorderlessButton, 'Button');
|
|
12
|
+
exports.BaseButton = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.BaseButton, 'Button');
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RectButton = exports.TouchableWithoutFeedback = exports.TouchableOpacity = exports.TouchableNativeFeedback = exports.TouchableHighlight = void 0;
|
|
3
|
+
exports.BaseButton = exports.BorderlessButton = exports.RectButton = exports.TouchableWithoutFeedback = exports.TouchableOpacity = exports.TouchableNativeFeedback = exports.TouchableHighlight = void 0;
|
|
4
4
|
var Touchables_1 = require("./Touchables");
|
|
5
5
|
Object.defineProperty(exports, "TouchableHighlight", { enumerable: true, get: function () { return Touchables_1.TouchableHighlight; } });
|
|
6
6
|
Object.defineProperty(exports, "TouchableNativeFeedback", { enumerable: true, get: function () { return Touchables_1.TouchableNativeFeedback; } });
|
|
7
7
|
Object.defineProperty(exports, "TouchableOpacity", { enumerable: true, get: function () { return Touchables_1.TouchableOpacity; } });
|
|
8
8
|
Object.defineProperty(exports, "TouchableWithoutFeedback", { enumerable: true, get: function () { return Touchables_1.TouchableWithoutFeedback; } });
|
|
9
9
|
Object.defineProperty(exports, "RectButton", { enumerable: true, get: function () { return Touchables_1.RectButton; } });
|
|
10
|
+
Object.defineProperty(exports, "BorderlessButton", { enumerable: true, get: function () { return Touchables_1.BorderlessButton; } });
|
|
11
|
+
Object.defineProperty(exports, "BaseButton", { enumerable: true, get: function () { return Touchables_1.BaseButton; } });
|
|
@@ -6,6 +6,7 @@ const react_native_1 = require("react-native");
|
|
|
6
6
|
const ConsoleLogger_1 = require("../../../lib/core/logging/ConsoleLogger");
|
|
7
7
|
const DynatraceBridge_1 = require("../../../lib/core/DynatraceBridge");
|
|
8
8
|
const BaseDataEventModifier_1 = require("../../../lib/next/events/modifier/BaseDataEventModifier");
|
|
9
|
+
const ConfigurationHandler_1 = require("../../../lib/core/configuration/ConfigurationHandler");
|
|
9
10
|
const logger = new ConsoleLogger_1.ConsoleLogger('ReactNavigation');
|
|
10
11
|
let activePath = '';
|
|
11
12
|
let appState = react_native_1.AppState.currentState;
|
|
@@ -44,6 +45,10 @@ const monitorNavigation = (getRootState) => {
|
|
|
44
45
|
};
|
|
45
46
|
exports.monitorNavigation = monitorNavigation;
|
|
46
47
|
const startView = (newPath) => {
|
|
48
|
+
if (!ConfigurationHandler_1.ConfigurationHandler.isConfigurationAvailable()) {
|
|
49
|
+
logger.info('React Native plugin has not been started yet! Navigation will not be reported!');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
47
52
|
const startViewInternalEvent = new BaseDataEventModifier_1.BaseDataEventModifier().modifyEvent(Object.assign({ 'view.detected_name': newPath }, (activePath && {
|
|
48
53
|
'view.source.detected_name': activePath,
|
|
49
54
|
})));
|
|
@@ -54,6 +59,10 @@ const startView = (newPath) => {
|
|
|
54
59
|
logger.debug(`startViewinternal(${JSON.stringify(startViewInternalEvent)})`);
|
|
55
60
|
};
|
|
56
61
|
const stopView = () => {
|
|
62
|
+
if (!ConfigurationHandler_1.ConfigurationHandler.isConfigurationAvailable()) {
|
|
63
|
+
logger.info('React Native plugin has not been started yet! Navigation will not be reported!');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
57
66
|
const fn = DynatraceBridge_1.DynatraceNative === null || DynatraceBridge_1.DynatraceNative === void 0 ? void 0 : DynatraceBridge_1.DynatraceNative.stopViewInternal;
|
|
58
67
|
if (typeof fn === 'function') {
|
|
59
68
|
fn();
|
|
@@ -7,6 +7,7 @@ const ConsoleLogger_1 = require("../../lib/core/logging/ConsoleLogger");
|
|
|
7
7
|
const ConfigurationHandler_1 = require("../../lib/core/configuration/ConfigurationHandler");
|
|
8
8
|
const Dynatrace_1 = require("../../lib/core/Dynatrace");
|
|
9
9
|
const ComponentUtil_1 = require("../jsx/components/ComponentUtil");
|
|
10
|
+
const UserInteraction_1 = require("./UserInteraction");
|
|
10
11
|
const Logger = new ConsoleLogger_1.ConsoleLogger('TouchableHelper');
|
|
11
12
|
function withOnPressMonitoring(Component, fallbackName) {
|
|
12
13
|
return React.forwardRef((props, ref) => {
|
|
@@ -73,6 +74,11 @@ const wrapOnPress = (onPress, touchableName, isButtonLike, buttonLabel) => {
|
|
|
73
74
|
Logger.debug(`registerPress bridge hook failed: ${errorMsg}`);
|
|
74
75
|
}
|
|
75
76
|
}
|
|
77
|
+
if (args[0] &&
|
|
78
|
+
typeof args[0] === 'object' &&
|
|
79
|
+
'nativeEvent' in args[0]) {
|
|
80
|
+
(0, UserInteraction_1.notifyPress)(args[0]);
|
|
81
|
+
}
|
|
76
82
|
if (!ConfigurationHandler_1.ConfigurationHandler.isConfigurationAvailable()) {
|
|
77
83
|
Logger.info('React Native plugin has not been started yet! Touch will not be reported!');
|
|
78
84
|
onPress(...args);
|
|
@@ -122,30 +128,73 @@ const findTouchableName = (props) => {
|
|
|
122
128
|
return findTouchableNameRecursive(props.children);
|
|
123
129
|
};
|
|
124
130
|
exports.findTouchableName = findTouchableName;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
const findTouchableNameRecursive = (node) => {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
if (!ConfigurationHandler_1.ConfigurationHandler.isConfigurationAvailable()) {
|
|
134
|
+
return dfs(node, matchAny);
|
|
135
|
+
}
|
|
136
|
+
const algorithm = ConfigurationHandler_1.ConfigurationHandler.getActionNameAlgorithm() === 'breadth-first'
|
|
137
|
+
? bfs
|
|
138
|
+
: dfs;
|
|
139
|
+
const preference = ConfigurationHandler_1.ConfigurationHandler.getActionNamePreference();
|
|
140
|
+
if (preference === 'text') {
|
|
141
|
+
return (_a = algorithm(node, matchText)) !== null && _a !== void 0 ? _a : algorithm(node, matchAny);
|
|
128
142
|
}
|
|
143
|
+
if (preference === 'icon') {
|
|
144
|
+
return (_b = algorithm(node, matchIcon)) !== null && _b !== void 0 ? _b : algorithm(node, matchAny);
|
|
145
|
+
}
|
|
146
|
+
return algorithm(node, matchAny);
|
|
147
|
+
};
|
|
148
|
+
const dfs = (node, matcher) => {
|
|
129
149
|
if (isReactNodeIterable(node)) {
|
|
130
150
|
for (const child of node) {
|
|
131
|
-
const result =
|
|
151
|
+
const result = dfs(child, matcher);
|
|
132
152
|
if (result !== null)
|
|
133
153
|
return result;
|
|
134
154
|
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
const match = matcher(node);
|
|
158
|
+
if (match)
|
|
159
|
+
return match;
|
|
160
|
+
if (React.isValidElement(node) && hasReactNodeChildren(node)) {
|
|
161
|
+
return dfs(node.props.children, matcher);
|
|
135
162
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
163
|
+
return null;
|
|
164
|
+
};
|
|
165
|
+
const bfs = (root, matcher) => {
|
|
166
|
+
const queue = [root];
|
|
167
|
+
while (queue.length > 0) {
|
|
168
|
+
const node = queue.shift();
|
|
169
|
+
if (isReactNodeIterable(node)) {
|
|
170
|
+
queue.push(...node);
|
|
171
|
+
continue;
|
|
140
172
|
}
|
|
141
|
-
|
|
142
|
-
|
|
173
|
+
const match = matcher(node);
|
|
174
|
+
if (match)
|
|
175
|
+
return match;
|
|
176
|
+
if (React.isValidElement(node) && hasReactNodeChildren(node)) {
|
|
177
|
+
queue.push(node.props.children);
|
|
143
178
|
}
|
|
144
|
-
if (hasReactNodeChildren(node))
|
|
145
|
-
return findTouchableNameRecursive(node.props.children);
|
|
146
179
|
}
|
|
147
180
|
return null;
|
|
148
|
-
}
|
|
181
|
+
};
|
|
182
|
+
const matchText = (node) => typeof node === 'string' ? node : null;
|
|
183
|
+
const matchImage = (node) => {
|
|
184
|
+
if (React.isValidElement(node) && isReactNativeImage(node)) {
|
|
185
|
+
const uri = getUriFromSource(node.props.source);
|
|
186
|
+
return uri ? `Image Button: ${uri}` : 'Image Button';
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
};
|
|
190
|
+
const matchCustomIcon = (node) => {
|
|
191
|
+
if (React.isValidElement(node) && isCustomIcon(node)) {
|
|
192
|
+
return node.props.name;
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
};
|
|
196
|
+
const matchAny = (node) => { var _a, _b; return (_b = (_a = matchText(node)) !== null && _a !== void 0 ? _a : matchImage(node)) !== null && _b !== void 0 ? _b : matchCustomIcon(node); };
|
|
197
|
+
const matchIcon = (node) => { var _a; return (_a = matchImage(node)) !== null && _a !== void 0 ? _a : matchCustomIcon(node); };
|
|
149
198
|
function getUriFromSource(source) {
|
|
150
199
|
if (typeof source === 'object' &&
|
|
151
200
|
'uri' in source &&
|
|
@@ -155,7 +204,9 @@ function getUriFromSource(source) {
|
|
|
155
204
|
return null;
|
|
156
205
|
}
|
|
157
206
|
const isReactNodeIterable = (node) => typeof node === 'object' && node !== null && Symbol.iterator in node;
|
|
158
|
-
const isReactNativeImage = (element) => element.type === ReactNative.Image
|
|
207
|
+
const isReactNativeImage = (element) => element.type === ReactNative.Image ||
|
|
208
|
+
element.type.displayName ===
|
|
209
|
+
'CssInterop.Image';
|
|
159
210
|
const isCustomIcon = (element) => typeof element.type === 'function' &&
|
|
160
211
|
element.type.name === 'Icon' &&
|
|
161
212
|
typeof element.props === 'object' &&
|
package/lib/core/Dynatrace.js
CHANGED
|
@@ -354,4 +354,7 @@ exports.Dynatrace = {
|
|
|
354
354
|
sendHttpRequestEvent: (httpRequestEvent) => {
|
|
355
355
|
Dynatrace_1.Dynatrace.sendHttpRequestEvent(httpRequestEvent);
|
|
356
356
|
},
|
|
357
|
+
generateTraceContext(traceparent, tracestate) {
|
|
358
|
+
return Dynatrace_1.Dynatrace.generateTraceContext(traceparent, tracestate);
|
|
359
|
+
},
|
|
357
360
|
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.DynatraceNative = void 0;
|
|
4
5
|
const react_native_1 = require("react-native");
|
|
5
6
|
const isTurboModuleEnabled = globalThis.__turboModuleProxy != null;
|
|
6
|
-
|
|
7
|
-
? react_native_1.TurboModuleRegistry.get('DynatraceBridge')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
: react_native_1.NativeModules.DynatraceBridge !== undefined
|
|
11
|
-
? react_native_1.NativeModules.DynatraceBridge
|
|
12
|
-
: {};
|
|
7
|
+
const turboModule = isTurboModuleEnabled
|
|
8
|
+
? react_native_1.TurboModuleRegistry.get('DynatraceBridge')
|
|
9
|
+
: null;
|
|
10
|
+
exports.DynatraceNative = (_a = turboModule !== null && turboModule !== void 0 ? turboModule : react_native_1.NativeModules.DynatraceBridge) !== null && _a !== void 0 ? _a : {};
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Configuration = void 0;
|
|
4
4
|
const LogLevelUtil_1 = require("../logging/LogLevelUtil");
|
|
5
5
|
class Configuration {
|
|
6
|
-
constructor(beaconUrl, applicationId, reportCrash, errorHandler, reportFatalErrorAsCrash, logLevel, lifecycleUpdate, userOptIn, actionNamePrivacy, bundleName, bundleVersion) {
|
|
6
|
+
constructor(beaconUrl, applicationId, reportCrash, errorHandler, reportFatalErrorAsCrash, logLevel, lifecycleUpdate, userOptIn, actionNamePrivacy, actionNamePreference, actionNameAlgorithm, bundleName, bundleVersion) {
|
|
7
7
|
this.beaconUrl = beaconUrl;
|
|
8
8
|
this.applicationId = applicationId;
|
|
9
9
|
this.reportCrash = reportCrash;
|
|
@@ -13,6 +13,8 @@ class Configuration {
|
|
|
13
13
|
this.lifecycleUpdate = lifecycleUpdate;
|
|
14
14
|
this.userOptIn = userOptIn;
|
|
15
15
|
this.actionNamePrivacy = actionNamePrivacy;
|
|
16
|
+
this.actionNamePreference = actionNamePreference;
|
|
17
|
+
this.actionNameAlgorithm = actionNameAlgorithm;
|
|
16
18
|
this.bundleName = bundleName;
|
|
17
19
|
this.bundleVersion = bundleVersion;
|
|
18
20
|
}
|
|
@@ -29,6 +31,8 @@ class Configuration {
|
|
|
29
31
|
`, lifecycleUpdate: ${this.lifecycleUpdate}` +
|
|
30
32
|
(isAutoStart ? '' : `, userOptIn: ${this.userOptIn}`) +
|
|
31
33
|
`, actionNamePrivacy: ${this.actionNamePrivacy}` +
|
|
34
|
+
`, actionNamePreference: ${this.actionNamePreference}` +
|
|
35
|
+
`, actionNameAlgorithm: ${this.actionNameAlgorithm}` +
|
|
32
36
|
`, logLevel: ${(0, LogLevelUtil_1.LogLevelToString)(this.logLevel)}`;
|
|
33
37
|
if (this.bundleName !== undefined) {
|
|
34
38
|
configurationString += `, bundleName: ${this.bundleName}`;
|
|
@@ -18,6 +18,8 @@ class ConfigurationBuilder {
|
|
|
18
18
|
this.lifecycleUpdate = preset.getLifecycleUpdate();
|
|
19
19
|
this.userOptIn = ConfigurationDefaults_1.DEFAULT_USER_OPT_IN;
|
|
20
20
|
this.actionNamePrivacy = preset.getActionNamePrivacy();
|
|
21
|
+
this.actionNamePreference = preset.getActionNamePreference();
|
|
22
|
+
this.actionNameAlgorithm = preset.getActionNameAlgorithm();
|
|
21
23
|
this.bundleName = preset.getBundleName();
|
|
22
24
|
this.bundleVersion = preset.getBundleVersion();
|
|
23
25
|
this.autoStartup = preset.isAutoStartupEnabled();
|
|
@@ -50,6 +52,14 @@ class ConfigurationBuilder {
|
|
|
50
52
|
this.actionNamePrivacy = actionNamePrivacy;
|
|
51
53
|
return this;
|
|
52
54
|
}
|
|
55
|
+
withActionNamePreference(actionNamePreference) {
|
|
56
|
+
this.actionNamePreference = actionNamePreference;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
withActionNameAlgorithm(actionNameAlgorithm) {
|
|
60
|
+
this.actionNameAlgorithm = actionNameAlgorithm;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
53
63
|
withBundleName(bundleName) {
|
|
54
64
|
this.bundleName = bundleName;
|
|
55
65
|
return this;
|
|
@@ -66,7 +76,7 @@ class ConfigurationBuilder {
|
|
|
66
76
|
throw new Error('applicationId configuration property is empty. ' +
|
|
67
77
|
'This configuration is not possible! Please use a proper application ID.');
|
|
68
78
|
}
|
|
69
|
-
return new Configuration_1.Configuration(this.beaconUrl, this.applicationId, this.reportCrash, this.errorHandler, this.reportFatalErrorAsCrash, this.logLevel, this.lifecycleUpdate, this.userOptIn, this.actionNamePrivacy, this.bundleName, this.bundleVersion);
|
|
79
|
+
return new Configuration_1.Configuration(this.beaconUrl, this.applicationId, this.reportCrash, this.errorHandler, this.reportFatalErrorAsCrash, this.logLevel, this.lifecycleUpdate, this.userOptIn, this.actionNamePrivacy, this.actionNamePreference, this.actionNameAlgorithm, this.bundleName, this.bundleVersion);
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
exports.ConfigurationBuilder = ConfigurationBuilder;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_ACTION_NAME_PRIVACY = exports.DEFAULT_USER_OPT_IN = exports.DEFAULT_LOGLEVEL = exports.DEFAULT_FATAL_AS_CRASH = exports.DEFAULT_ERROR_HANDLER = exports.DEFAULT_REPORT_CRASH = exports.DEFAULT_LIFECYCLE_UPDATE = void 0;
|
|
3
|
+
exports.DEFAULT_ACTION_NAME_ALGORITHM = exports.DEFAULT_ACTION_NAME_PREFERENCE = exports.DEFAULT_ACTION_NAME_PRIVACY = exports.DEFAULT_USER_OPT_IN = exports.DEFAULT_LOGLEVEL = exports.DEFAULT_FATAL_AS_CRASH = exports.DEFAULT_ERROR_HANDLER = exports.DEFAULT_REPORT_CRASH = exports.DEFAULT_LIFECYCLE_UPDATE = void 0;
|
|
4
4
|
const LogLevel_1 = require("../logging/LogLevel");
|
|
5
5
|
exports.DEFAULT_LIFECYCLE_UPDATE = false;
|
|
6
6
|
exports.DEFAULT_REPORT_CRASH = true;
|
|
@@ -9,3 +9,5 @@ exports.DEFAULT_FATAL_AS_CRASH = true;
|
|
|
9
9
|
exports.DEFAULT_LOGLEVEL = LogLevel_1.LogLevel.Info;
|
|
10
10
|
exports.DEFAULT_USER_OPT_IN = false;
|
|
11
11
|
exports.DEFAULT_ACTION_NAME_PRIVACY = false;
|
|
12
|
+
exports.DEFAULT_ACTION_NAME_PREFERENCE = 'any';
|
|
13
|
+
exports.DEFAULT_ACTION_NAME_ALGORITHM = 'depth-first';
|