How do I migrate from using an Instrumentation Key to a Connection String in Application Insights for a Java Spring Boot application using an ARM template (template.json)?

Devarakonda Amani (SEBT) 0 Reputation points
2025-04-29T14:38:45.23+00:00

I am currently using Application Insights in a Java Spring Boot application, where the telemetry is configured using the legacy Instrumentation Key (InstrumentationKey). I understand that Microsoft now recommends using Connection Strings (connectionString) instead of Instrumentation Keys for better flexibility and future support.

I am deploying my application and its associated resources using an ARM (Azure Resource Manager) template (template.json). I would like to understand the correct process to migrate from using the Instrumentation Key to the Connection String within this ARM template and ensure that my Java Spring Boot application reads the Connection String properly.

Specifically, I need guidance on:

How to update the ARM template to expose the connectionString instead of the instrumentationKey.

How to reference and inject this connection string into the Spring Boot application during deployment.

Any changes needed in the Spring Boot code or configuration (e.g., application.properties or application.yml) to support the connection string.

Best practices or potential pitfalls to be aware of during this migration.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,808 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alekhya Vaddepally 1,340 Reputation points Microsoft External Staff Moderator
    2025-05-12T17:57:12.55+00:00

    Hi Devarakonda Amani (SEBT)
    T the coupled code tightly caused by the app using a connection string in the spring boot application and applicationisights.attach (). To support more scalable and maintainable setups, we recommend using the application Insights Java agent, which enables a complete telemetry collection (request, dependence, log) without the need for any code change. This approach keeps your application relaxed and avoids the requirement of clear SDK calls such as applicationinsights.attach (). For Azure App Service, you can automate this setup:

    Deployment of Java Agent (Applicationinsights -Gent.jar) with your application (eg,/home/site/wwwroot/).

    Setting the following application settings via azure portal or ARM template: Java_opts = -Javaagent: /home/site/wwwroot/applicationinsights-gent-3.5.0.jar Applicationinsights_connection_string = <Your connection string> This configuration ensures dynamic, environment-operated telemetry setup without any tight coupling in your application code. If you prefer a programmatic followback, a reflection-based dynamic attachment method can be used, which handles the absence of application by application and avoids breaking your application. We recommend agent-based setup as it aligns with microsoft best practices, is future proof, and avoids the need for any code-level changes in the atmosphere.

    Please accept as "Yes" if the answer provided is useful, so that you can help others in the community looking for remediation for similar issues.

    Let me know if you have any further Queries.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.