elastic/apm-agent-android

Add possibility to set serverUrl via ElasticApmConfiguration

Closed this issue · 3 comments

Add possiblity to add servicerUrl during ElasticApmAgent initilization. Application can have different servers based on enviorments, flavors etc.

Hi @ubaierbhat - Thank you for your feedback.

I think you should be able to address this use case by passing a Connectivity object with your server endpoint during the ElasticApmAgent initialization like so:

import import co.elastic.apm.android.sdk.connectivity.Connectivity;
//...
String serverUrl = "https://...";
Connectivity myCustomConnectivity = Connectivity.simple(serverUrl); // there are other methods such as Connectivity.withApiKey and Connectivity.withSecretToken in case you need those extra parameters.
ElasticApmAgent.initialize(appContext, myCustomConnectivity);

I hope it helps for your case, you can find more info on currently available configurations in here.

Thank you. The Connectivity object did the job. It wasn't clear from the documentation. serverUrl is a required field in the Gradle build script. We have to provide a dummy URL there and then override it when initializing the agent. Maybe serverUrl can be made optional in Gradle and checked during runtime, not compile time?

Good to know it worked! Thanks for your feedback, I believe it's okay to remove the validation in Gradle for the serverUrl as long as we specify in the docs that a runtime exception could happen if it's not set in either place. I've created this issue for it: #182 - I'll close this issue for now, though feel free to reopen it if needed.