|
| 1 | +--- |
| 2 | +title: Azure Monitor - Azure Application Insights override default SDK endpoints | Microsoft Docs |
| 3 | +description: Modify default Azure Application Insights SDK endpoints for regions like Azure Government. |
| 4 | +services: application-insights |
| 5 | +author: mrbullwinkle |
| 6 | +manager: carmonm |
| 7 | +ms.assetid: 3b722e47-38bd-4667-9ba4-65b7006c074c |
| 8 | +ms.service: application-insights |
| 9 | +ms.workload: tbd |
| 10 | +ms.tgt_pltfrm: ibiza |
| 11 | +ms.topic: conceptual |
| 12 | +ms.date: 06/10/2019 |
| 13 | +ms.author: mbullwin |
| 14 | +--- |
| 15 | + |
| 16 | + # Application Insights overriding default endpoints |
| 17 | + |
| 18 | +To send data from Application Insights to certain regions, you'll need to override the default endpoint addresses. Each SDK requires slightly different modifications, all of which are described in this article. These changes require adjusting the sample code and replacing the placeholder values for `QuickPulse_Endpoint_Address`, `TelemetryChannel_Endpoint_Address`, and `Profile_Query_Endpoint_address` with the actual endpoint addresses for your specific region. The end of this article contains links to the endpoint addresses for regions where this configuration is required. |
| 19 | + |
| 20 | +## SDK code changes |
| 21 | + |
| 22 | +### .NET with applicationinsights.config |
| 23 | + |
| 24 | +```xml |
| 25 | +<ApplicationInsights> |
| 26 | + ... |
| 27 | + <TelemetryModules> |
| 28 | + <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector"> |
| 29 | + <QuickPulseServiceEndpoint>Custom_QuickPulse_Endpoint_Address</QuickPulseServiceEndpoint> |
| 30 | + </Add> |
| 31 | + </TelemetryModules> |
| 32 | + ... |
| 33 | + <TelemetryChannel> |
| 34 | + <EndpointAddress>TelemetryChannel_Endpoint_Address</EndpointAddress> |
| 35 | + </TelemetryChannel> |
| 36 | + ... |
| 37 | + <ApplicationIdProvider Type="Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider, Microsoft.ApplicationInsights"> |
| 38 | + <ProfileQueryEndpoint>Profile_Query_Endpoint_address</ProfileQueryEndpoint> |
| 39 | + </ApplicationIdProvider> |
| 40 | + ... |
| 41 | +</ApplicationInsights> |
| 42 | +``` |
| 43 | + |
| 44 | +### .NET Core |
| 45 | + |
| 46 | +Modify the appsettings.json file in your project as follows to adjust the main endpoint: |
| 47 | + |
| 48 | +```json |
| 49 | +"ApplicationInsights": { |
| 50 | + "InstrumentationKey": "instrumentationkey", |
| 51 | + "TelemetryChannel": { |
| 52 | + "EndpointAddress": "TelemetryChannel_Endpoint_Address" |
| 53 | + } |
| 54 | + } |
| 55 | +``` |
| 56 | + |
| 57 | +The values for Live Metrics and the Profile Query Endpoint can only be set via code. To override the default values for all endpoint values via code, make the following changes in the `ConfigureServices` method of the `Startup.cs` file: |
| 58 | + |
| 59 | +```csharp |
| 60 | +using Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId; |
| 61 | +using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse; //place at top of Startup.cs file |
| 62 | +
|
| 63 | + services.ConfigureTelemetryModule<QuickPulseTelemetryModule>((module, o) => module.QuickPulseServiceEndpoint="QuickPulse_Endpoint_Address"); |
| 64 | + |
| 65 | + services.AddSingleton(new ApplicationInsightsApplicationIdProvider() { ProfileQueryEndpoint = "Profile_Query_Endpoint_address" }); |
| 66 | + |
| 67 | + services.AddSingleton<ITelemetryChannel>(new ServerTelemetryChannel() { EndpointAddress = "TelemetryChannel_Endpoint_Address" }); |
| 68 | + |
| 69 | + //place in ConfigureServices method. If present, place this prior to services.AddApplicationInsightsTelemetry("instrumentation key"); |
| 70 | +``` |
| 71 | + |
| 72 | +### Java |
| 73 | + |
| 74 | +Modify the applicationinsights.xml file to change the default endpoint address. |
| 75 | + |
| 76 | +```xml |
| 77 | +<?xml version="1.0" encoding="utf-8"?> |
| 78 | +<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"> |
| 79 | + <InstrumentationKey>ffffeeee-dddd-cccc-bbbb-aaaa99998888</InstrumentationKey> |
| 80 | + <TelemetryModules> |
| 81 | + <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule"/> |
| 82 | + <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebSessionTrackingTelemetryModule"/> |
| 83 | + <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebUserTrackingTelemetryModule"/> |
| 84 | + </TelemetryModules> |
| 85 | + <TelemetryInitializers> |
| 86 | + <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationIdTelemetryInitializer"/> |
| 87 | + <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationNameTelemetryInitializer"/> |
| 88 | + <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebSessionTelemetryInitializer"/> |
| 89 | + <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserTelemetryInitializer"/> |
| 90 | + <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserAgentTelemetryInitializer"/> |
| 91 | + </TelemetryInitializers> |
| 92 | + <!--Add the following Channel value to modify the Endpoint address--> |
| 93 | + <Channel type="com.microsoft.applicationinsights.channel.concrete.inprocess.InProcessTelemetryChannel"> |
| 94 | + <EndpointAddress>TelemetryChannel_Endpoint_Address</EndpointAddress> |
| 95 | + </Channel> |
| 96 | +</ApplicationInsights> |
| 97 | +``` |
| 98 | + |
| 99 | +### Spring Boot |
| 100 | + |
| 101 | +Modify the `application.properties` file and add: |
| 102 | + |
| 103 | +```yaml |
| 104 | +azure.application-insights.channel.in-process.endpoint-address= TelemetryChannel_Endpoint_Address |
| 105 | +``` |
| 106 | + |
| 107 | +### Node.js |
| 108 | + |
| 109 | +```javascript |
| 110 | +var appInsights = require("applicationinsights"); |
| 111 | +appInsights.setup('INSTRUMENTATION_KEY'); |
| 112 | +appInsights.defaultClient.config.endpointUrl = "TelemetryChannel_Endpoint_Address"; // ingestion |
| 113 | +appInsights.defaultClient.config.profileQueryEndpoint = "Profile_Query_Endpoint_address"; // appid/profile lookup |
| 114 | +appInsights.defaultClient.config.quickPulseHost = "QuickPulse_Endpoint_Address"; //live metrics |
| 115 | +appInsights.Configuration.start(); |
| 116 | +``` |
| 117 | + |
| 118 | +The endpoints can also be configured through environment variables: |
| 119 | + |
| 120 | +``` |
| 121 | +Instrumentation Key: “APPINSIGHTS_INSTRUMENTATIONKEY” |
| 122 | +Profile Endpoint: “Profile_Query_Endpoint_address” |
| 123 | +Live Metrics Endpoint: "QuickPulse_Endpoint_Address" |
| 124 | +``` |
| 125 | + |
| 126 | +### JavaScript |
| 127 | + |
| 128 | +```javascript |
| 129 | +<script type="text/javascript"> |
| 130 | +var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var aiName=window[sdkInstance],aisdk=window[aiName]||function(e){function n(e){i[e]=function(){var n=arguments;i.queue.push(function(){i[e].apply(i,n)})}}var i={config:e};i.initialize=!0;var a=document,t=window;setTimeout(function(){var n=a.createElement("script");n.src=e.url||"https://az416426.vo.msecnd.net/next/ai.2.min.js",a.getElementsByTagName("script")[0].parentNode.appendChild(n)});try{i.cookie=a.cookie}catch(e){}i.queue=[],i.version=2;for(var r=["Event","PageView","Exception","Trace","DependencyData","Metric","PageViewPerformance"];r.length;)n("track"+r.pop());n("startTrackPage"),n("stopTrackPage");var o="Track"+r[0];if(n("start"+o),n("stop"+o),!(!0===e.disableExceptionTracking||e.extensionConfig&&e.extensionConfig.ApplicationInsightsAnalytics&&!0===e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)){n("_"+(r="onerror"));var s=t[r];t[r]=function(e,n,a,t,o){var c=s&&s(e,n,a,t,o);return!0!==c&&i["_"+r]({message:e,url:n,lineNumber:a,columnNumber:t,error:o}),c},e.autoExceptionInstrumented=!0}return i} |
| 131 | +( |
| 132 | + { |
| 133 | + instrumentationKey:"INSTRUMENTATION_KEY", |
| 134 | + endpointUrl: "TelemetryChannel_Endpoint_Address" |
| 135 | + } |
| 136 | +); |
| 137 | +window[aiName]=aisdk,aisdk.queue&&0===aisdk.queue.length&&aisdk.trackPageView({}); |
| 138 | +</script> |
| 139 | + |
| 140 | +``` |
| 141 | + |
| 142 | +## Regions that require endpoint modification |
| 143 | + |
| 144 | +Currently the only region that requires endpoint modifications is [Azure Government](https://docs.microsoft.com/azure/azure-government/documentation-government-services-monitoringandmanagement#application-insights). |
| 145 | + |
| 146 | +## Next step |
| 147 | + |
| 148 | +- To learn more about the custom modifications for Azure Government, consult the detailed guidance for [Azure monitoring and management](https://docs.microsoft.com/azure/azure-government/documentation-government-services-monitoringandmanagement#application-insights). |
0 commit comments