title: Application Insights support multiple environment for Java
body: <p>I am building a Java webapp (Spring webapp using Maven build) on Azure and using Application Insights for monitoring. I used the reference link <a href="https://azure.microsoft.com/en-us/documentation/articles/app-insights-java-get-started/" rel="nofollow">https://azure.microsoft.com/en-us/documentation/articles/app-insights-java-get-started/</a>.</p>
  
  <p>Since I use multiple environments I planned to pass the App Insights instrumentation Key as a system property from azure portal APP_SETTING (<code>JAVA_OPTS</code> value as <code>-Dappinsight.instrumentation.key=xxxxxxx</code>).</p>
  
  <p>I have added required Maven dependencies and my <code>src\main\resources\ApplicationInsights.xml</code> has the App Insight instrumentation key reference as:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30"&gt;
  
  
    &lt;!-- The key from the portal: --&gt;
  
    &lt;InstrumentationKey&gt;${appinsight.instrumentation.key}&lt;/InstrumentationKey&gt;
  
  
    &lt;!-- HTTP request component (not required for bare API) --&gt;
  
    &lt;TelemetryModules&gt;
      &lt;Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule"/&gt;
      &lt;Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebSessionTrackingTelemetryModule"/&gt;
      &lt;Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebUserTrackingTelemetryModule"/&gt;
    &lt;/TelemetryModules&gt;
  
    &lt;!-- Events correlation (not required for bare API) --&gt;
    &lt;!-- These initializers add context data to each event --&gt;
  
    &lt;TelemetryInitializers&gt;
      &lt;Add   type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationIdTelemetryInitializer"/&gt;
      &lt;Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationNameTelemetryInitializer"/&gt;
      &lt;Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebSessionTelemetryInitializer"/&gt;
      &lt;Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserTelemetryInitializer"/&gt;
      &lt;Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserAgentTelemetryInitializer"/&gt;
  
    &lt;/TelemetryInitializers&gt;
  &lt;/ApplicationInsights&gt;
  </code></pre>
  
  <p>But it doesn't work. When I hardcode the key directly, it works. </p>
  
  <p>Is there any specific way of referencing the system properties for Application insights in Spring?</p>