ApplicationInsights-Java icon indicating copy to clipboard operation
ApplicationInsights-Java copied to clipboard

Allow connectionString to be overridden multiple times without restarting the AppInsights Agent

Open slavik112211 opened this issue 6 months ago • 5 comments

Is your feature request related to a problem? Please describe. As per your documentation, it's possible to override connection strings per each httpPathPrefix: https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#connection-string-overrides-preview

{
  "preview": {
    "connectionStringOverrides": [
      {
        "httpPathPrefix": "/myapp1",
        "connectionString": "..."
      },
      {
        "httpPathPrefix": "/myapp2",
        "connectionString": "..."
      }
    ]
  }
}

This config is being processed in the following class of AppInsights Agent: InheritedConnectionStringSpanProcessor.java:L58-L62

I understand that this feature is geared towards a use-case where an app being instrumented with AppInsights is an MVC app, and a connectionStringOverride is applied at a Controller method level, where each Controller method has a different PathPrefix. I.e. this use-case is described in OpenTelemetryAPI documentation as creating a custom span per controller method: https://opentelemetry.io/docs/instrumentation/java/manual/#create-spans

Describe the solution you would like We are looking for a way to change connectionString multiple times throughout application lifecycle, not per httpPathPrefix

Ideally we would be able to run ConnectionString.configure() and change to a desired connectionString, and ApplicationInsight agent taking that into account, and posting metrics to a newly specified location.

com.microsoft.applicationinsights.connectionstring.ConnectionString.configure(CONNECTION_STRING)

Currently ConnectionString.configure(CONNECTION_STRING) can be run only once to set ConnectionString: https://github.com/microsoft/ApplicationInsights-Java/blob/main/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/classicsdk/BytecodeUtilImpl.java#L70-L73

We need a way to determine custom OpenTelemetry spans, and have a different ConnectionString per each of these spans.

Describe alternatives you have considered Describe any alternative solutions or features you've considered.

Additional context Our app is not Spring MVC app that has different httpPathPrefix, but is rather a SpringBoot cron-executed org.springframework.boot.CommandLineRunner task, that runs periodically, and needs to send AppInsights telemetry to 3 different AppInsights containers.

slavik112211 avatar Dec 23 '23 03:12 slavik112211