01 Mar 2025
10:42 PM
- last edited on
03 Mar 2025
10:53 AM
by
MaciejNeumann
Hi all,
Im trying to learn the Dynatrace capacities with web and mobile app, so i build something to play 🙂
So, i have this code
// Initializes and configures WebView
private fun setupWebView() {
val myWebView: WebView = findViewById(R.id.main_webview)
Dynatrace.instrumentWebView(myWebView)
myWebView.settings.javaScriptEnabled = true
myWebView.loadUrl("http://192.168.0.102:8079") // ez travel on vm
binding.mainWebview.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
return false // Ensures URLs open inside WebView, NOT Chrome
}
}
}
I have mobile and web sessions, but they are splited, i want to map mobile to web sessions so i follow this documentation
Can I have some lights why Im not able to map sessions?
Thanks,
RD
04 Mar 2025 08:26 AM
Hey RD,
Usually auto instrumentation would take care for you so you don't need to call instrumentWebView. This call also only adds the JavaScript interface. Still you need to use the Hybrid Monitoring configuration flag. Did you do that? Additionally one thing that you are probably missing is setting the configuration for domains. The Android agent doesn't know that your VM is on 192.168.0.102, so you need to configure this domain in order for the cookies to be set there.
The cookies (dtAdk) will allow the session merge.
06 Mar 2025 06:10 PM
Thanks Matthias for the answer but i could not find the result that i wanted., yet 🤓
Let me explain better what i want to do.
I have a web page that will be access by web view in mobile and browser.
I would like to map the mobile session to the web session.
But this not always happen.
Having this in consideration i still need to have the Hybrid Monitoring configuration flag?
This means that i have to add this to code
DynatraceConfigurationBuilder("<YourApplicationID>", "<ProvidedBeaconURL>")
.withHybridMonitoring(true)
07 Mar 2025 09:35 AM
DynatraceConfigurationBuilder is something that you are using when doing a manual startup. So you are doing manual starting?
But in general your answer is correct. Additionally as said above you also need to call the builder API for adding domains.
08 Mar 2025 01:53 AM
Ok, lets see the key points:
My build gradle of the project:
dynatrace {
configurations {
sampleConfig {
autoStart {
applicationId 'applicationId'
beaconUrl 'https://beaconUrl.bf.dynatrace.com/mbeacon'
}
userOptIn false
agentBehavior.startupLoadBalancing true
sessionReplay.enabled false
exclude.classes "com.dynatrace.sample.android.app.MinimalActivity"
hybridWebView {
enabled true
domains ["192.168.0.102"]
}
}
}
}
Code
// Initializes and configures WebView
private fun setupWebView() {
DynatraceConfigurationBuilder("appID", "https://bc.bf.dynatrace.com/mbeacon")
.withHybridMonitoring(true)
.withMonitoredDomains("192.168.0.102")
.buildConfiguration()
val myWebView: WebView = findViewById(R.id.main_webview)
Dynatrace.instrumentWebView(myWebView)
myWebView.settings.javaScriptEnabled = true
myWebView.loadUrl("http://192.168.0.102:9200/")
binding.mainWebview.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
return false // Ensures URLs open inside WebView, NOT Chrome
}
}
}
I have tried every combination but it seems that the problem is between the keyboard and the pc 👀
10 Mar 2025 10:10 AM
The DynatraceConfigurationBuilder is not needed as you are doing auto instrumentation through the build.gradle configuration anyways. Also the instrumentWebview is usually not needed, but not 100% sure because you are excluding the MinimalActivity.
Anyways, please adapt the configuration
hybridWebView {
enabled true
domains '192.168.0.102'
}
In general if you want to add more values it is something like this:
hybridWebView {
enabled true
domains '192.168.0.102', '...', '...'
}
Maybe also add 'debug.agentLogging true' to the configuration so you can see logs.
No worries. We are getting there. Thanks for your input.