diff --git a/source/code/go/src/plugins/telemetry.go b/source/code/go/src/plugins/telemetry.go index 5fc0fa843..4f22b8c03 100644 --- a/source/code/go/src/plugins/telemetry.go +++ b/source/code/go/src/plugins/telemetry.go @@ -42,6 +42,7 @@ const ( envAKSResourceID = "AKS_RESOURCE_ID" envACSResourceName = "ACS_RESOURCE_NAME" envAppInsightsAuth = "APPLICATIONINSIGHTS_AUTH" + envAppInsightsEndpoint = "APPLICATIONINSIGHTS_ENDPOINT" metricNameAvgFlushRate = "ContainerLogAvgRecordsFlushedPerSec" metricNameAvgLogGenerationRate = "ContainerLogsGeneratedPerSec" metricNameLogSize = "ContainerLogsSize" @@ -141,7 +142,15 @@ func InitializeTelemetryClient(agentVersion string) (int, error) { return -1, err } - TelemetryClient = appinsights.NewTelemetryClient(string(decIkey)) + appInsightsEndpoint := os.Getenv(envAppInsightsEndpoint) + telemetryClientConfig := appinsights.NewTelemetryConfiguration(string(decIkey)) + // endpoint override required only for sovereign clouds + if appInsightsEndpoint != "" { + Log("Overriding the default AppInsights EndpointUrl with %s", appInsightsEndpoint) + telemetryClientConfig.EndpointUrl = envAppInsightsEndpoint + } + TelemetryClient = appinsights.NewTelemetryClientFromConfig(telemetryClientConfig) + telemetryOffSwitch := os.Getenv("DISABLE_TELEMETRY") if strings.Compare(strings.ToLower(telemetryOffSwitch), "true") == 0 { Log("Appinsights telemetry is disabled \n") diff --git a/source/code/plugin/ApplicationInsightsUtility.rb b/source/code/plugin/ApplicationInsightsUtility.rb index 5dc2bfab8..bb4831701 100644 --- a/source/code/plugin/ApplicationInsightsUtility.rb +++ b/source/code/plugin/ApplicationInsightsUtility.rb @@ -18,6 +18,7 @@ class ApplicationInsightsUtility @@EnvAksRegion = "AKS_REGION" @@EnvAgentVersion = "AGENT_VERSION" @@EnvApplicationInsightsKey = "APPLICATIONINSIGHTS_AUTH" + @@EnvApplicationInsightsEndpoint = "APPLICATIONINSIGHTS_ENDPOINT" @@EnvControllerType = "CONTROLLER_TYPE" @@CustomProperties = {} @@ -62,6 +63,7 @@ def initializeUtility() @@CustomProperties["AgentVersion"] = ENV[@@EnvAgentVersion] @@CustomProperties["ControllerType"] = ENV[@@EnvControllerType] encodedAppInsightsKey = ENV[@@EnvApplicationInsightsKey] + appInsightsEndpoint = ENV[@@EnvApplicationInsightsEndpoint] #Check if telemetry is turned off telemetryOffSwitch = ENV["DISABLE_TELEMETRY"] @@ -70,7 +72,16 @@ def initializeUtility() @@Tc = ApplicationInsights::TelemetryClient.new elsif !encodedAppInsightsKey.nil? decodedAppInsightsKey = Base64.decode64(encodedAppInsightsKey) - @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey + #override ai endpoint if its available otherwise use default. + if appInsightsEndpoint && !appInsightsEndpoint.nil? && !appInsightsEndpoint.empty? + $log.info("AppInsightsUtility: Telemetry client uses overrided endpoint url : #{appInsightsEndpoint}") + telemetrySynchronousSender = ApplicationInsights::Channel::SynchronousSender.new appInsightsEndpoint + telemetrySynchronousQueue = ApplicationInsights::Channel::SynchronousQueue.new(telemetrySynchronousSender) + telemetryChannel = ApplicationInsights::Channel::TelemetryChannel.new nil, telemetrySynchronousQueue + @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey, telemetryChannel + else + @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey + end end rescue => errorStr $log.warn("Exception in AppInsightsUtility: initilizeUtility - error: #{errorStr}")