add event log events for correlation
This commit is contained in:
Родитель
7533468b32
Коммит
26a407e3f6
|
@ -207,12 +207,14 @@
|
||||||
InjectionGuardConstants.TraceParentHeaderMaxLength);
|
InjectionGuardConstants.TraceParentHeaderMaxLength);
|
||||||
originalParentId = parentTraceParent;
|
originalParentId = parentTraceParent;
|
||||||
traceParentPresent = true;
|
traceParentPresent = true;
|
||||||
|
AspNetCoreEventSource.Instance.HostingListenerInformational("2", "Retrieved trace parent from headers.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scenario #1. No incoming correlation headers.
|
// Scenario #1. No incoming correlation headers.
|
||||||
if (originalParentId == null)
|
if (originalParentId == null)
|
||||||
{
|
{
|
||||||
// Nothing to do here.
|
// Nothing to do here.
|
||||||
|
AspNetCoreEventSource.Instance.HostingListenerInformational("2", "OriginalParentId is null.");
|
||||||
}
|
}
|
||||||
else if (traceParentPresent)
|
else if (traceParentPresent)
|
||||||
{
|
{
|
||||||
|
@ -220,6 +222,7 @@
|
||||||
// We need to ignore the Activity created by Hosting, as it did not take W3CTraceParent into consideration.
|
// We need to ignore the Activity created by Hosting, as it did not take W3CTraceParent into consideration.
|
||||||
newActivity = new Activity(ActivityCreatedByHostingDiagnosticListener);
|
newActivity = new Activity(ActivityCreatedByHostingDiagnosticListener);
|
||||||
newActivity.SetParentId(originalParentId);
|
newActivity.SetParentId(originalParentId);
|
||||||
|
AspNetCoreEventSource.Instance.HostingListenerInformational("2", "Ignoring original Activity from Hosting to create new one using traceparent header retrieved by sdk.");
|
||||||
|
|
||||||
// read and populate tracestate
|
// read and populate tracestate
|
||||||
ReadTraceState(httpContext.Request.Headers, newActivity);
|
ReadTraceState(httpContext.Request.Headers, newActivity);
|
||||||
|
@ -238,6 +241,7 @@
|
||||||
{
|
{
|
||||||
newActivity = new Activity(ActivityCreatedByHostingDiagnosticListener);
|
newActivity = new Activity(ActivityCreatedByHostingDiagnosticListener);
|
||||||
newActivity.SetParentId(ActivityTraceId.CreateFromString(traceId), default(ActivitySpanId), ActivityTraceFlags.None);
|
newActivity.SetParentId(ActivityTraceId.CreateFromString(traceId), default(ActivitySpanId), ActivityTraceFlags.None);
|
||||||
|
AspNetCoreEventSource.Instance.HostingListenerInformational("2", "Ignoring original Activity from Hosting to create new one using w3c compatible request-id.");
|
||||||
|
|
||||||
foreach (var bag in currentActivity.Baggage)
|
foreach (var bag in currentActivity.Baggage)
|
||||||
{
|
{
|
||||||
|
@ -248,6 +252,7 @@
|
||||||
{
|
{
|
||||||
// store rootIdFromOriginalParentId in custom Property
|
// store rootIdFromOriginalParentId in custom Property
|
||||||
legacyRootId = ExtractOperationIdFromRequestId(originalParentId);
|
legacyRootId = ExtractOperationIdFromRequestId(originalParentId);
|
||||||
|
AspNetCoreEventSource.Instance.HostingListenerInformational("2", "Incoming Request-ID is not W3C Compatible, and hence will be ignored for ID generation, but stored in custom property legacy_rootID.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -581,6 +586,8 @@
|
||||||
activity.AddBaggage(itemName, itemValue);
|
activity.AddBaggage(itemName, itemValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AspNetCoreEventSource.Instance.HostingListenerVerboe("Correlation-Context retrived from header and stored into activity baggage.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,6 +600,7 @@
|
||||||
// make in the request context can continue propogation
|
// make in the request context can continue propogation
|
||||||
// of tracestate.
|
// of tracestate.
|
||||||
activity.TraceStateString = traceState;
|
activity.TraceStateString = traceState;
|
||||||
|
AspNetCoreEventSource.Instance.HostingListenerVerboe("TraceState retrived from header and stored into activity.TraceState");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,11 +681,13 @@
|
||||||
var traceId = activity.TraceId.ToHexString();
|
var traceId = activity.TraceId.ToHexString();
|
||||||
requestTelemetry.Id = FormatTelemetryId(traceId, activity.SpanId.ToHexString());
|
requestTelemetry.Id = FormatTelemetryId(traceId, activity.SpanId.ToHexString());
|
||||||
requestTelemetry.Context.Operation.Id = traceId;
|
requestTelemetry.Context.Operation.Id = traceId;
|
||||||
|
AspNetCoreEventSource.Instance.RequestTelemetryCreated("W3C", requestTelemetry.Id, traceId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
requestTelemetry.Context.Operation.Id = activity.RootId;
|
requestTelemetry.Context.Operation.Id = activity.RootId;
|
||||||
requestTelemetry.Id = activity.Id;
|
requestTelemetry.Id = activity.Id;
|
||||||
|
AspNetCoreEventSource.Instance.RequestTelemetryCreated("Hierrarchical", requestTelemetry.Id, requestTelemetry.Context.Operation.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.proactiveSamplingEnabled
|
if (this.proactiveSamplingEnabled
|
||||||
|
|
|
@ -193,7 +193,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.
|
||||||
{
|
{
|
||||||
this.WriteEvent(17, errorMessage, this.ApplicationName);
|
this.WriteEvent(17, errorMessage, this.ApplicationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs an event when a telemetry item is sampled out at head.
|
/// Logs an event when a telemetry item is sampled out at head.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -207,6 +207,42 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.
|
||||||
this.WriteEvent(18, operationId, this.ApplicationName);
|
this.WriteEvent(18, operationId, this.ApplicationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs an informational event from Hosting listeners.
|
||||||
|
/// </summary>
|
||||||
|
[Event(
|
||||||
|
19,
|
||||||
|
Message = "Hosting Major Version: '{0}'. Informational Message: '{1}'.",
|
||||||
|
Level = EventLevel.Informational)]
|
||||||
|
public void HostingListenerInformational(string hostingVersion, string message, string appDomainName = "Incorrect")
|
||||||
|
{
|
||||||
|
this.WriteEvent(19, hostingVersion, message, this.ApplicationName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs a verbose event.
|
||||||
|
/// </summary>
|
||||||
|
[Event(
|
||||||
|
20,
|
||||||
|
Message = "Message: '{0}'.",
|
||||||
|
Level = EventLevel.Verbose)]
|
||||||
|
public void HostingListenerVerboe(string message, string appDomainName = "Incorrect")
|
||||||
|
{
|
||||||
|
this.WriteEvent(20, message, this.ApplicationName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs an event for RequestTelemetry created.
|
||||||
|
/// </summary>
|
||||||
|
[Event(
|
||||||
|
21,
|
||||||
|
Message = "RequestTelemetry created. CorrelationFormat: '{0}', RequestID: '{1}', OperationId : '{2}' ",
|
||||||
|
Level = EventLevel.Informational)]
|
||||||
|
public void RequestTelemetryCreated(string correlationFormat, string requestId, string requestOperationId, string appDomainName = "Incorrect")
|
||||||
|
{
|
||||||
|
this.WriteEvent(21, correlationFormat, requestId, requestOperationId, this.ApplicationName);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Keywords for the AspNetEventSource.
|
/// Keywords for the AspNetEventSource.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
public class RequestCollectionOptions
|
public class RequestCollectionOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates new instance of <see cref="RequestCollectionOptions"/> class and fills default values.
|
/// Initializes a new instance of the <see cref="RequestCollectionOptions"/> class
|
||||||
|
/// and populates default values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RequestCollectionOptions()
|
public RequestCollectionOptions()
|
||||||
{
|
{
|
||||||
|
@ -23,17 +24,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get or sets value indicating whether Request-Context header is injected into the response.
|
/// Gets or sets a value indicating whether Request-Context header is injected into the response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool InjectResponseHeaders { get; set; }
|
public bool InjectResponseHeaders { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get or sets value indicating whether exceptions are be tracked.
|
/// Gets or sets a value indicating whether exceptions are be tracked by the RequestCOllectionModule.
|
||||||
|
/// Exceptions could be tracked by ApplicationInsightsLoggerProvider as well which is not affected by
|
||||||
|
/// this setting.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool TrackExceptions { get; set; }
|
public bool TrackExceptions { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get or sets value indicating whether W3C distributed tracing standard is enabled.
|
/// Gets or sets a value indicating whether W3C distributed tracing standard is enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnableW3CDistributedTracing { get; set; }
|
public bool EnableW3CDistributedTracing { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestTrackingTelemetryModule"/> class.
|
/// Initializes a new instance of the <see cref="RequestTrackingTelemetryModule"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RequestTrackingTelemetryModule()
|
public RequestTrackingTelemetryModule()
|
||||||
: this(null)
|
: this(null)
|
||||||
{
|
{
|
||||||
this.CollectionOptions = new RequestCollectionOptions();
|
this.CollectionOptions = new RequestCollectionOptions();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче