AspNetCore instrumentation internal logging improvements. (#3998)
This commit is contained in:
parent
61ba77df6e
commit
aee29efc6f
|
|
@ -28,45 +28,45 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
public static AspNetCoreInstrumentationEventSource Log = new();
|
||||
|
||||
[NonEvent]
|
||||
public void RequestFilterException(Exception ex)
|
||||
public void RequestFilterException(string handlerName, string eventName, string operationName, Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
|
||||
{
|
||||
this.RequestFilterException(ex.ToInvariantString());
|
||||
this.RequestFilterException(handlerName, eventName, operationName, ex.ToInvariantString());
|
||||
}
|
||||
}
|
||||
|
||||
[Event(1, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(1, handlerName, eventName);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Request is filtered out. EventName: '{0}'.", Level = EventLevel.Verbose)]
|
||||
public void RequestIsFilteredOut(string eventName)
|
||||
{
|
||||
this.WriteEvent(2, eventName);
|
||||
}
|
||||
|
||||
[Event(3, Message = "Filter threw exception. Request will not be collected. Exception {0}.", Level = EventLevel.Error)]
|
||||
public void RequestFilterException(string exception)
|
||||
{
|
||||
this.WriteEvent(3, exception);
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void EnrichmentException(Exception ex)
|
||||
public void EnrichmentException(string handlerName, string eventName, string operationName, Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
|
||||
{
|
||||
this.EnrichmentException(ex.ToInvariantString());
|
||||
this.EnrichmentException(handlerName, eventName, operationName, ex.ToInvariantString());
|
||||
}
|
||||
}
|
||||
|
||||
[Event(4, Message = "Enrich threw exception. Exception {0}.", Level = EventLevel.Error)]
|
||||
public void EnrichmentException(string exception)
|
||||
[Event(1, Message = "Payload is NULL, span will not be recorded. HandlerName: '{0}', EventName: '{1}', OperationName: '{2}'.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName, string operationName)
|
||||
{
|
||||
this.WriteEvent(4, exception);
|
||||
this.WriteEvent(1, handlerName, eventName, operationName);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Request is filtered out. HandlerName: '{0}', EventName: '{1}', OperationName: '{2}'.", Level = EventLevel.Verbose)]
|
||||
public void RequestIsFilteredOut(string handlerName, string eventName, string operationName)
|
||||
{
|
||||
this.WriteEvent(2, handlerName, eventName, operationName);
|
||||
}
|
||||
|
||||
[Event(3, Message = "Filter threw exception, request will not be collected. HandlerName: '{0}', EventName: '{1}', OperationName: '{2}', Exception: {3}.", Level = EventLevel.Error)]
|
||||
public void RequestFilterException(string handlerName, string eventName, string operationName, string exception)
|
||||
{
|
||||
this.WriteEvent(3, handlerName, eventName, operationName, exception);
|
||||
}
|
||||
|
||||
[Event(4, Message = "Enrich threw exception. HandlerName: '{0}', EventName: '{1}', OperationName: '{2}', Exception: {3}.", Level = EventLevel.Warning)]
|
||||
public void EnrichmentException(string handlerName, string eventName, string operationName, string exception)
|
||||
{
|
||||
this.WriteEvent(4, handlerName, eventName, operationName, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
HttpContext context = payload as HttpContext;
|
||||
if (context == null)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStartActivity));
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStartActivity), activity.OperationName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
{
|
||||
if (this.options.Filter?.Invoke(context) == false)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName);
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestIsFilteredOut(nameof(HttpInListener), nameof(this.OnStartActivity), activity.OperationName);
|
||||
activity.IsAllDataRequested = false;
|
||||
activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;
|
||||
return;
|
||||
|
|
@ -180,7 +180,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestFilterException(ex);
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestFilterException(nameof(HttpInListener), nameof(this.OnStartActivity), activity.OperationName, ex);
|
||||
activity.IsAllDataRequested = false;
|
||||
activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;
|
||||
return;
|
||||
|
|
@ -223,7 +223,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(ex);
|
||||
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(nameof(HttpInListener), nameof(this.OnStartActivity), activity.OperationName, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
HttpContext context = payload as HttpContext;
|
||||
if (context == null)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStopActivity));
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStopActivity), activity.OperationName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +265,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(ex);
|
||||
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(nameof(HttpInListener), nameof(this.OnStopActivity), activity.OperationName, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -353,7 +353,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
// We need to use reflection here as the payload type is not a defined public type.
|
||||
if (!this.stopExceptionFetcher.TryFetch(payload, out Exception exc) || exc == null)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnException));
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnException), activity.OperationName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +370,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(ex);
|
||||
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(nameof(HttpInListener), nameof(this.OnException), activity.OperationName, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
{
|
||||
private const string HttpServerDurationMetricName = "http.server.duration";
|
||||
private const string OnStopEvent = "Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop";
|
||||
private const string EventName = "OnStopActivity";
|
||||
|
||||
private readonly Meter meter;
|
||||
private readonly AspNetCoreMetricsInstrumentationOptions options;
|
||||
|
|
@ -48,7 +49,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
var context = payload as HttpContext;
|
||||
if (context == null)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInMetricsListener), nameof(this.OnEventWritten));
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInMetricsListener), EventName, HttpServerDurationMetricName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -56,13 +57,13 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
{
|
||||
if (this.options.Filter?.Invoke(HttpServerDurationMetricName, context) == false)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestIsFilteredOut(HttpServerDurationMetricName);
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestIsFilteredOut(nameof(HttpInMetricsListener), EventName, HttpServerDurationMetricName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestFilterException(ex);
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestFilterException(nameof(HttpInMetricsListener), EventName, HttpServerDurationMetricName, ex);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +106,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(ex);
|
||||
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(nameof(HttpInMetricsListener), EventName, HttpServerDurationMetricName, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue