1
0
Форкнуть 0

Removed telemetry initializer from this repo to reuse the one referred from windowsserver repo

This commit is contained in:
Cijo Thomas 2018-04-26 11:35:00 -07:00
Родитель f41fe0bab2
Коммит 39a90749f8
4 изменённых файлов: 5 добавлений и 137 удалений

Просмотреть файл

@ -1,5 +1,9 @@
# Changelog
## Version 2.3.0-beta2
-Removed DomainNameRoleInstanceTelemetryInitializer as its is deprecated.
-Reuse AzureWebAppRoleEnvironmentTelemetryInitializer from WindowsServer repo instead of outdated implementation in this repo.
## Version 2.3.0-beta1
- Changed behavior for `TelemetryConfiguration.Active` and `TelemetryConfiguration` dependency injection singleton: with this version every WebHost has its own `TelemetryConfiguration` instance. Changes done for `TelemetryConfiguration.Active` do not affect telemetry reported by the SDK; use `TelemetryConfiguration` instance obtained through the dependency injection. [Fix NullReferenceException when sending http requests in scenario with multiple web hosts sharing the same process](https://github.com/Microsoft/ApplicationInsights-dotnet/issues/613)
- Updated Javascript Snippet with latest from [Github/ApplicationInsights-JS](https://github.com/Microsoft/ApplicationInsights-JS)

Просмотреть файл

@ -134,8 +134,7 @@ namespace Microsoft.Extensions.DependencyInjection
{
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<ITelemetryInitializer, ApplicationInsights.AspNetCore.TelemetryInitializers.AzureWebAppRoleEnvironmentTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, ApplicationInsights.AspNetCore.TelemetryInitializers.DomainNameRoleInstanceTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, AzureWebAppRoleEnvironmentTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, ComponentVersionTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, ClientIpHeaderTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, OperationNameTelemetryInitializer>();

Просмотреть файл

@ -1,70 +0,0 @@
namespace Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers
{
using System;
using System.Threading;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.AspNetCore.Http;
/// <summary>
/// A telemetry initializer that will gather Azure Web App Role Environment context information.
/// </summary>
public class AzureWebAppRoleEnvironmentTelemetryInitializer : TelemetryInitializerBase
{
/// <summary>Azure Web App name corresponding to the resource name.</summary>
private const string WebAppNameEnvironmentVariable = "WEBSITE_SITE_NAME";
/// <summary>Azure Web App host that contains site name and slot: site-slot.</summary>
private const string WebAppHostNameEnvironmentVariable = "WEBSITE_HOSTNAME";
private string roleInstanceName;
private string roleName;
/// <summary>
/// Initializes a new instance of the <see cref="AzureWebAppRoleEnvironmentTelemetryInitializer" /> class.
/// </summary>
/// <param name="httpContextAccessor">HTTP context accessor.</param>
public AzureWebAppRoleEnvironmentTelemetryInitializer(IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor)
{
}
/// <summary>
/// Initializes role name, role instance name and node name for Azure Web App case.
/// </summary>
/// <param name="platformContext">Platform context.</param>
/// <param name="requestTelemetry">Request telemetry.</param>
/// <param name="telemetry">Telemetry item.</param>
protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
{
if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleName))
{
string name = LazyInitializer.EnsureInitialized(ref this.roleName, this.GetRoleName);
telemetry.Context.Cloud.RoleName = name;
}
if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleInstance))
{
string name = LazyInitializer.EnsureInitialized(ref this.roleInstanceName, this.GetRoleInstanceName);
telemetry.Context.Cloud.RoleInstance = name;
}
InternalContext internalContext = telemetry.Context.GetInternalContext();
if (string.IsNullOrEmpty(internalContext.NodeName))
{
string name = LazyInitializer.EnsureInitialized(ref this.roleInstanceName, this.GetRoleInstanceName);
internalContext.NodeName = name;
}
}
private string GetRoleName()
{
return Environment.GetEnvironmentVariable(WebAppNameEnvironmentVariable) ?? string.Empty;
}
private string GetRoleInstanceName()
{
return Environment.GetEnvironmentVariable(WebAppHostNameEnvironmentVariable) ?? string.Empty;
}
}
}

Просмотреть файл

@ -1,65 +0,0 @@
namespace Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers
{
using System;
using System.Globalization;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.AspNetCore.Http;
/// <summary>
/// A telemetry initializer that populates cloud context role instance.
/// </summary>
public class DomainNameRoleInstanceTelemetryInitializer : TelemetryInitializerBase
{
private string roleInstanceName;
/// <summary>
/// Initializes a new instance of the <see cref="DomainNameRoleInstanceTelemetryInitializer" /> class.
/// </summary>
/// <param name="httpContextAccessor">HTTP context accessor.</param>
public DomainNameRoleInstanceTelemetryInitializer(IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor)
{
}
/// <summary>
/// Initializes role instance name and node name with the host name.
/// </summary>
/// <param name="platformContext">Platform context.</param>
/// <param name="requestTelemetry">Request telemetry.</param>
/// <param name="telemetry">Telemetry item.</param>
protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
{
if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleInstance))
{
var name = LazyInitializer.EnsureInitialized(ref this.roleInstanceName, this.GetMachineName);
telemetry.Context.Cloud.RoleInstance = name;
}
InternalContext internalContext = telemetry.Context.GetInternalContext();
if (string.IsNullOrEmpty(internalContext.NodeName))
{
var name = LazyInitializer.EnsureInitialized(ref this.roleInstanceName, this.GetMachineName);
internalContext.NodeName = name;
}
}
private string GetMachineName()
{
string hostName = Dns.GetHostName();
// Issue #61: For dnxcore machine name does not have domain name like in full framework
#if !NETSTANDARD1_6
string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
if (!hostName.EndsWith(domainName, StringComparison.OrdinalIgnoreCase))
{
hostName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", hostName, domainName);
}
#endif
return hostName;
}
}
}