microsoft/cpp_client_telemetry

Change CFG_STR_COLLECTOR_URL after initializing

TedaLIEz opened this issue · 4 comments

Suppose I have initialized two logger instances as follows:

val httpClient = HttpClient(context.applicationContext)
OfflineRoom.connectContext(context.applicationContext)
val logConfiguration = LogManager.logConfigurationFactory()
// Internally, the logger will use a different cache file for each tenant
logConfiguration[LogConfigurationKey.CFG_STR_COLLECTOR_URL] = url1
logConfiguration[LogConfigurationKey.CFG_STR_PRIMARY_TOKEN] = tenantToken
// Initialize will send HTTP requests
logger1 = LogManager.initialize(tenantToken1, logConfiguration)
logger2 = LogManager.initialize(tenantToken1, logConfiguration)

And I want to send telemetry to the backend at url1 via logger1:

logger1.logEvent(xxx, xxx);

Later, I want to log my event to url2 (this usually happens when we need to make our app EUDB compliant). Should I use the following code to change the collector URL?

val logConfiguration = LogManager.logConfigurationFactory()
// Internally, the logger will use a different cache file for each tenant
logConfiguration[LogConfigurationKey.CFG_STR_COLLECTOR_URL] = url2
logConfiguration[LogConfigurationKey.CFG_STR_PRIMARY_TOKEN] = tenantToken
logger2 = LogManager.initialize(tenantToken1, logConfiguration)

logger2.logEvent(xxx, xxx);   // Send event to url2

What's the option here to change the collector URL after we have initialized the logger instance?

@anod @lalitb friendly ping for this issue.

anod commented

This is example how we change url and tenant

#1158 (comment)

Before switching to a new instance we call

        logManager.uploadNow()
        logManager.pauseTransmission()
        logManager.flush()

Hi @anod, I have a question about the LogManager class. If I call LogManager#uploadNow(), pauseTransmission(), or flush(), will these methods apply to all the logger instances that were created by the manager instance?

If I call LogManager#uploadNow(), pauseTransmission(), or flush(), will these methods apply to all the logger instances that were created by the manager instance?

Yes that's true.