Skip to content

Rename metrics tag exception.type to error.type #51084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Hosting/Hosting/src/Internal/HostingMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public void RequestEnd(string protocol, bool isHttps, string scheme, string meth
tags.Add("http.route", route);
}
// This exception is only present if there is an unhandled exception.
// An exception caught by ExceptionHandlerMiddleware and DeveloperExceptionMiddleware isn't thrown to here. Instead, those middleware add exception.type to custom tags.
// An exception caught by ExceptionHandlerMiddleware and DeveloperExceptionMiddleware isn't thrown to here. Instead, those middleware add error.type to custom tags.
if (exception != null)
{
tags.Add("exception.type", exception.GetType().FullName);
tags.Add("error.type", exception.GetType().FullName);
}
if (customTags != null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Hosting/Hosting/test/HostingMetricsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ static void AssertRequestDuration(CollectedMeasurement<double> measurement, stri
Assert.Equal(statusCode, (int)measurement.Tags["http.response.status_code"]);
if (exceptionName == null)
{
Assert.False(measurement.Tags.ContainsKey("exception.type"));
Assert.False(measurement.Tags.ContainsKey("error.type"));
}
else
{
Assert.Equal(exceptionName, (string)measurement.Tags["exception.type"]);
Assert.Equal(exceptionName, (string)measurement.Tags["error.type"]);
}
if (unhandledRequest ?? false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/Diagnostics/src/DiagnosticsMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void RequestException(string exceptionName, ExceptionResult result, strin
private void RequestExceptionCore(string exceptionName, ExceptionResult result, string? handler)
{
var tags = new TagList();
tags.Add("exception.type", exceptionName);
tags.Add("error.type", exceptionName);
tags.Add("aspnetcore.diagnostics.exception.result", GetExceptionResult(result));
if (handler != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/Diagnostics/src/DiagnosticsTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void ReportUnhandledException(ILogger logger, HttpContext context,

if (context.Features.Get<IHttpMetricsTagsFeature>() is { } tagsFeature)
{
tagsFeature.Tags.Add(new KeyValuePair<string, object?>("exception.type", ex.GetType().FullName));
tagsFeature.Tags.Add(new KeyValuePair<string, object?>("error.type", ex.GetType().FullName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public async Task UnhandledError_ExceptionNameTagAdded()
{
Assert.True(m.Value > 0);
Assert.Equal(500, (int)m.Tags["http.response.status_code"]);
Assert.Equal("System.Exception", (string)m.Tags["exception.type"]);
Assert.Equal("System.Exception", (string)m.Tags["error.type"]);
});
Assert.Collection(requestExceptionCollector.GetMeasurementSnapshot(),
m => AssertRequestException(m, "System.Exception", "unhandled"));
Expand All @@ -588,7 +588,7 @@ public async Task UnhandledError_ExceptionNameTagAdded()
private static void AssertRequestException(CollectedMeasurement<long> measurement, string exceptionName, string result, string handler = null)
{
Assert.Equal(1, measurement.Value);
Assert.Equal(exceptionName, (string)measurement.Tags["exception.type"]);
Assert.Equal(exceptionName, (string)measurement.Tags["error.type"]);
Assert.Equal(result, measurement.Tags["aspnetcore.diagnostics.exception.result"].ToString());
if (handler == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public async Task Metrics_ExceptionThrown_Unhandled_Reported()
private static void AssertRequestException(CollectedMeasurement<long> measurement, string exceptionName, string result, string handler = null)
{
Assert.Equal(1, measurement.Value);
Assert.Equal(exceptionName, (string)measurement.Tags["exception.type"]);
Assert.Equal(exceptionName, (string)measurement.Tags["error.type"]);
Assert.Equal(result, measurement.Tags["aspnetcore.diagnostics.exception.result"].ToString());
if (handler == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ public async Task UnhandledError_ExceptionNameTagAdded()
{
Assert.True(m.Value > 0);
Assert.Equal(404, (int)m.Tags["http.response.status_code"]);
Assert.Equal("System.Exception", (string)m.Tags["exception.type"]);
Assert.Equal("System.Exception", (string)m.Tags["error.type"]);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void ConnectionStopCore(in ConnectionMetricsContext metricsContext, Exce
{
if (exception != null)
{
tags.Add("exception.type", exception.GetType().FullName);
tags.Add("error.type", exception.GetType().FullName);
}

// Add custom tags for duration.
Expand Down Expand Up @@ -298,7 +298,7 @@ private void TlsHandshakeStopCore(in ConnectionMetricsContext metricsContext, lo
}
if (exception != null)
{
tags.Add("exception.type", exception.GetType().FullName);
tags.Add("error.type", exception.GetType().FullName);
}

var duration = Stopwatch.GetElapsedTime(startTimestamp, currentTimestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public async Task Http1Connection_Error()
Assert.Collection(connectionDuration.GetMeasurementSnapshot(), m =>
{
AssertDuration(m, "127.0.0.1", localPort: 0, "tcp", "ipv4", httpVersion: null);
Assert.Equal("System.InvalidOperationException", (string)m.Tags["exception.type"]);
Assert.Equal("System.InvalidOperationException", (string)m.Tags["error.type"]);
});
Assert.Collection(activeConnections.GetMeasurementSnapshot(), m => AssertCount(m, 1, "127.0.0.1", localPort: 0, "tcp", "ipv4"), m => AssertCount(m, -1, "127.0.0.1", localPort: 0, "tcp", "ipv4"));
Assert.Collection(queuedConnections.GetMeasurementSnapshot(), m => AssertCount(m, 1, "127.0.0.1", localPort: 0, "tcp", "ipv4"), m => AssertCount(m, -1, "127.0.0.1", localPort: 0, "tcp", "ipv4"));
Expand Down