Browse Source

Application insights integration. (#586)

pull/587/head 4.7.3
Sebastian Stehle 5 years ago
committed by GitHub
parent
commit
6ba16f8316
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      backend/extensions/Squidex.Extensions/APM/ApplicationInsights/ApplicationInsightsPlugin.cs
  2. 1
      backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj

48
backend/extensions/Squidex.Extensions/APM/ApplicationInsights/ApplicationInsightsPlugin.cs

@ -0,0 +1,48 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Plugins;
namespace Squidex.Extensions.APM.ApplicationInsights
{
public sealed class ApplicationInsightsPlugin : IPlugin, IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{
return builder =>
{
var client = builder.ApplicationServices.GetRequiredService<TelemetryClient>();
Profiler.SpanStarted += session =>
{
session.Listen(client.StartOperation<RequestTelemetry>(session.Key));
};
next(builder);
};
}
public void ConfigureServices(IServiceCollection services, IConfiguration config)
{
var isEnabled = config.GetValue<bool>("logging:applicationInsights");
if (isEnabled)
{
services.AddSingleton<IStartupFilter>(this);
services.AddApplicationInsightsTelemetry();
}
}
}
}

1
backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj

@ -15,6 +15,7 @@
<PackageReference Include="CoreTweet" Version="1.0.0.483" />
<PackageReference Include="Datadog.Trace" Version="1.19.2" />
<PackageReference Include="Elasticsearch.Net" Version="7.9.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.15.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.7" />
<PackageReference Include="Microsoft.OData.Core" Version="7.7.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />

Loading…
Cancel
Save