Skip to content

Commit 2001b7c

Browse files
authored
Merge pull request #85908 from mrbullwinkle/mrb_08_19_2019_netcore_endpoint_mod
update app insights code samples
2 parents e30f073 + 46cc518 commit 2001b7c

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

articles/azure-government/documentation-government-services-monitoringandmanagement.md

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ In order to send data from Application Insights to the Azure Government region,
208208
</ApplicationInsights>
209209
```
210210

211-
### .NET Core
211+
### ASP.NET Core
212212

213213
Modify the appsettings.json file in your project as follows to adjust the main endpoint:
214214

@@ -224,18 +224,72 @@ Modify the appsettings.json file in your project as follows to adjust the main e
224224
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:
225225

226226
```csharp
227+
using Microsoft.ApplicationInsights.Extensibility;
227228
using Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId;
228-
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse; //place at top of Startup.cs file
229+
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse;
230+
using Microsoft.ApplicationInsights.Channel;
231+
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel; //place at top of Startup.cs file
229232
230233
services.ConfigureTelemetryModule<QuickPulseTelemetryModule>((module, o) => module.QuickPulseServiceEndpoint="https://quickpulse.applicationinsights.us/QuickPulseService.svc");
231234

232-
services.AddSingleton(new ApplicationInsightsApplicationIdProvider() { ProfileQueryEndpoint = "https://dc.applicationinsights.us/api/profiles/{0}/appId" });
235+
services.AddSingleton<IApplicationIdProvider, ApplicationInsightsApplicationIdProvider>(_ => new ApplicationInsightsApplicationIdProvider() { ProfileQueryEndpoint = "https://dc.applicationinsights.us/api/profiles/{0}/appId" });
233236

234-
services.AddSingleton<ITelemetryChannel>(new ServerTelemetryChannel() { EndpointAddress = "https://dc.applicationinsights.us/v2/track" });
237+
services.AddSingleton<ITelemetryChannel>(_ => new ServerTelemetryChannel() { EndpointAddress = "https://dc.applicationinsights.us/v2/track" });
235238

236239
//place in ConfigureServices method. If present, place this prior to services.AddApplicationInsightsTelemetry("instrumentation key");
237240
```
238241

242+
### Azure Functions
243+
244+
Please install following packages into your Function project:
245+
246+
- Microsoft.ApplicationInsights version 2.10.0
247+
- Microsoft.ApplicationInsights.PerfCounterCollector version 2.10.0
248+
- Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel version 2.10.0
249+
250+
And also add (or modify) the startup code for your Function application:
251+
252+
```csharp
253+
[assembly: FunctionsStartup(typeof(Example.Startup))]
254+
namespace Example
255+
{
256+
class Startup : FunctionsStartup
257+
{
258+
public override void Configure(IFunctionsHostBuilder builder)
259+
{
260+
var quickPulseFactory = builder.Services.FirstOrDefault(sd => sd.ServiceType == typeof(ITelemetryModule) &&
261+
sd.ImplementationType == typeof(QuickPulseTelemetryModule));
262+
if (quickPulseFactory != null)
263+
{
264+
builder.Services.Remove(quickPulseFactory);
265+
}
266+
267+
var appIdFactory = builder.Services.FirstOrDefault(sd => sd.ServiceType == typeof(IApplicationIdProvider));
268+
if (appIdFactory != null)
269+
{
270+
builder.Services.Remove(appIdFactory);
271+
}
272+
273+
var channelFactory = builder.Services.FirstOrDefault(sd => sd.ServiceType == typeof(ITelemetryChannel));
274+
if (channelFactory != null)
275+
{
276+
builder.Services.Remove(channelFactory);
277+
}
278+
279+
builder.Services.AddSingleton<ITelemetryModule, QuickPulseTelemetryModule>(_ =>
280+
new QuickPulseTelemetryModule
281+
{
282+
QuickPulseServiceEndpoint = "https://quickpulse.applicationinsights.us/QuickPulseService.svc"
283+
});
284+
285+
builder.Services.AddSingleton<IApplicationIdProvider, ApplicationInsightsApplicationIdProvider>(_ => new ApplicationInsightsApplicationIdProvider() { ProfileQueryEndpoint = "https://dc.applicationinsights.us/api/profiles/{0}/appId" });
286+
287+
builder.Services.AddSingleton<ITelemetryChannel>(_ => new ServerTelemetryChannel() { EndpointAddress = "https://dc.applicationinsights.us/v2/track" });
288+
}
289+
}
290+
}
291+
```
292+
239293
### Java
240294

241295
Modify the applicationinsights.xml file to change the default endpoint address.

0 commit comments

Comments
 (0)