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,703 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Prabhavathi Manchala 1,050 Reputation points Microsoft External Staff
    2025-04-29T19:08:24.8233333+00:00

    Hi Devarakonda Amani (SEBT),

    Hey there! It sounds like you're looking to migrate from using the Instrumentation Key to the Connection String for Application Insights in your Java Spring Boot application, and you want to do this using an ARM template. Here’s a step-by-step guide on how to do this:

    Updating the ARM Template

    1). Modify the Template: Update your template.json to include the connection string as follows:

    {
      "properties": {
        "appInsightsConfiguration": {
          "connectionString": "<YOUR_APP_INSIGHTS_CONNECTION_STRING>"
        },
        ...
      }
    }
    

    Make sure to replace <YOUR_APP_INSIGHTS_CONNECTION_STRING> with the actual connection string from your Application Insights resource.

    2). Deployment: Deploy your ARM template using Azure CLI or your preferred method. This will ensure that your Application Insights resource is configured to use the connection string.

    Referencing the Connection String in Spring Boot

    You can set the connection string in your Spring Boot application via properties or environment variables:

    1). application.properties or application.yml: Add the following line to your application.properties or application.yml file:

    applicationinsights.connection.string=<YOUR_APP_INSIGHTS_CONNECTION_STRING>
    

    OR

    applicationinsights:
      connection:
        string: <YOUR_APP_INSIGHTS_CONNECTION_STRING>
    

    2). Environment Variable: Alternatively, set the following environment variable for your deployment:

    export APPLICATIONINSIGHTS_CONNECTION_STRING="<YOUR_APP_INSIGHTS_CONNECTION_STRING>"
    

    This takes precedence over the configuration file.

    Code Changes

    In many cases, you won't need to change your application code if you simply switch the way you provide the connection string. However, if you're setting up the connection string programmatically or wish to validate the configuration, ensure you reference the setting correctly.

    Best Practices and Pitfalls

    • Testing: After the migration, test your application to make sure telemetry is being sent correctly to the Application Insights resource.
    • Monitor for Issues: Watch for any exceptions or issues in your logs related to telemetry sent to Application Insights.
    • Environment-specific Configurations: If deploying to different environments (dev, test, production), ensure that each environment has the correct connection string set, either programmatically or through environment variables.

    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.

    If you have any further questions or need clarification on any specific part, feel free to ask!


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.