This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
/
TelemetryInitializerBase.cs
55 lines (46 loc) · 1.75 KB
/
TelemetryInitializerBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers
{
using System;
using System.Diagnostics;
using Extensibility.Implementation.Tracing;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
public abstract class TelemetryInitializerBase : ITelemetryInitializer
{
private IHttpContextAccessor httpContextAccessor;
public TelemetryInitializerBase(IHttpContextAccessor httpContextAccessor)
{
if (httpContextAccessor == null)
{
throw new ArgumentNullException("httpContextAccessor");
}
this.httpContextAccessor = httpContextAccessor;
}
public void Initialize(ITelemetry telemetry)
{
var context = this.httpContextAccessor.HttpContext;
if (context == null)
{
AspNetCoreEventSource.Instance.LogTelemetryInitializerBaseInitializeContextNull();
return;
}
lock (context)
{
var request = context.Features.Get<RequestTelemetry>();
if (request == null)
{
AspNetCoreEventSource.Instance.LogTelemetryInitializerBaseInitializeRequestNull();
return;
}
this.OnInitializeTelemetry(context, request, telemetry);
}
}
protected abstract void OnInitializeTelemetry(
HttpContext platformContext,
RequestTelemetry requestTelemetry,
ITelemetry telemetry);
}
}