cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding Dynatrace gradle plugin in android

devggaurav
Newcomer

I am trying to add dynatrace gradle plugin in my application, when I am adding plugin by following the documentation and adding it to top level gradle, getting this issue 

it is too late to add actions as the callbacks already executed. did you try to call beforevariants or onvariants from the old variant api 'applicationvariants' for instance ? you should always call before variants or variants directly from the android components dsl block.

and when using it in app level gradle its not working, also tried turning off dynatrace.ignoreBuildwarning 
I am using groovy gradle and its an old project. please suggest something if someone has tried this already 



14 REPLIES 14

Peter_Youssef
Champion

Hello @devggaurav 

  • It's better to remove the old instrumentation configurations from the mobile development part and from Dynatrace as well.
  • Remove the caches.
  • Ensure the Cluster AG is having publicly accessible IP address and the RUM constraints are allowed.
  • Create a new mobile app in Dynatrace and use the cluster AG as beacon endpoint or if you're using a
  • Follow the Gradle instrumentation from scratch, hopefully you won't expose further issues.

DT Resources:

2024-10-17_16h57_41.png

If The mobile app servers are monitored by Oneagent use the third option 

2024-10-17_17h01_05.png

For the ENV AG

2024-10-17_17h02_14.png

KR,

Peter

I tried same applicationId and beaconUrl with a dummy app first, can it be a case that same applicationID and beaconUrl can not be used for two apps ? 

Hello @devggaurav 

For the RUM either mobile /  web  / custom to work perfectly:

  1. Dedicated Application to each app so it's impossible to use the same app id for duplicated instrumentation.
  2. The beacon should be unique as well.
  3. So based on the instrumentation method your configuration parameters should be unique.

It's better to start a fresh instrumentation in collaborative manner including NW and FW team allowing the attached https://docs.dynatrace.com/docs/platform-modules/digital-experience/web-applications/initial-setup/f...

and DT admin creates deletes all this old mobile app related configurations and create a new app, ask for the new configurations from the instrumentation wizard it will contain the application ID and beacon endpoint definitely.

Start an new instrumentation journey and keep the good work up 👨‍💻:dynaspin:😉😊

KR,

Peter

Can you suggest oneAgent SDK documentation for mobile application ? will that have some banefits ? which one is more convenient way to use ? 

Hello @devggaurav 

It depends on the mobile development framework you will instrument Android 😊or iOS 🤗or what exactly to provide the proper resources.

As simple as that:

  1. Instrumentation via OneAgent SDK for Android 
  2. Mobile Apps Instrumentations 

2024-10-17_19h11_51.png

2024-10-17_19h13_47.png

Tip:

  • If you're not the mobile app developer, engage the mobile app in call and share Dynatrace documentation as per the development framework, it will be easy to decide the most convenient method.
  • If the mobile app servers are monitored in Dynatrace, it will facilitate the instrumentation and detection of calling services, ....etc.

Hoping this add value.

BR, 

Peter

Theoretically, the applicationId and beaconUrl can be used for multiple applications, because there is no limitation by Dynatrace. But this approach should be avoided.
Dynatrace recommends to use a different applicationId for every mobile application, because the  dashboards will give you a proper overview of the application health state based on all reported data.
Some customers prefer to combine their iOS and Android apps into one mobile application and then use the OS filtering option to get the platform-specific metrics. This is the only scenario, where the usage of the same applicationId value is fine.

I successfully added oneAgent SDK in my android application, with different applicationID and beacon URL, and enabled all, but I am not able to trace web requests from app automatically on dashboard, I want to track all of them , not using any third party web request, all are http, is there some config I am missing 

.withUserOptIn(true)
.withCrashReporting(true)
.withActivityMonitoring(true)
.withDebugLogging(true)
.withStartupLoadBalancing(true)
.withHybridMonitoring(true)

Hello @devggaurav 

Good to hear that.

Kindly follow the attached procedure to configure the web request tracing : web-request-monitoring 

BR,

Peter

It says by default it monitors all web request, and I have not disabled it, I am using oneAgent SDK, So do I need to perform something else to make web request monitoring 

You have to use the Dynatrace Android Gradle plugin because it adds the auto-instrumentation step to the Android app build.
When you are using the standalone manual instrumentation option, you have to instrument all web requests manually.

So when we use OneAgent SDK on android, the web request will not be monitored automatically, it can only be supported by Android Gradle plugin ? 

Yes. If you want auto-instrumentation, you have to use the Dynatrace Android Gradle plugin.

We can achieve tracking all api's using one agent sdk as well by creating an interceptor 

class DynatraceInterceptor: Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val uniqueRequestTag = Dynatrace.getRequestTag()
val timing = Dynatrace.getWebRequestTiming(uniqueRequestTag)
val newRequest = request.newBuilder()
.addHeader(Dynatrace.getRequestTagHeader(), uniqueRequestTag)
.build()

timing.startWebRequestTiming()
return try {
val response = chain.proceed(newRequest)
timing.stopWebRequestTiming(request.url.toUrl(), response.code, response.message)
response
} catch (e: Exception) {
timing.stopWebRequestTiming(request.url.toUrl(), -1, e.toString())
e.printStackTrace()
throw e
}
}
}


and this inteceptor at your httpClient for android mostly its retrofit

val client = OkHttpClient.Builder()
.addInterceptor(DynatraceInterceptor())
.build()

and you can now track all api request without changes and using one agent SDK

Thomas_Wirth1
Dynatrace Champion
Dynatrace Champion

The mentioned error message is generated by the Android Gradle plugin, when another plugin or the user tries to use its API after the step is executed. The Dynatrace Android Gradle plugin is using the API from the Android Gradle plugin to include the auto-instrumentation step into the Android app build process. It is using the android components feature to interact with the Android Gradle plugin and interacts with it before any action is executed.

It seems there is an incompatibility with your build, because you or a plugin is changing the order in which the project setup is executed. Without any build files, we can't further troubleshoot your problem. You can create a support ticket and upload your build.gradle files. Then somebody from the support team will assist you in the troubleshooting effort.
For example, the usage of the Gradle API evaluationDependsOn will change the execution order significantly and therefore the instruction in your Gradle files must be called in the correct order to have a successful build.


You wrote in another message that you tried it with a dummy project. The mentioned API is normally not used in dummy projects. Did you instrument a Flutter or ReactNative app? For these apps, Dynatrace provides the Dynatrace Flutter plugin and the Dynatrace ReactNative plugin.

Featured Posts