Skip to content

Commit

Permalink
Fix error.type
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Mar 11, 2024
1 parent e920468 commit ccb1d4f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ private void OnException(Activity activity, HttpContext context, Exception excep
}

activity.SetStatus(ActivityStatusCode.Error, exception.Message);
activity.SetTag(SemanticConventions.AttributeErrorType, exception.GetType().FullName);

try
{
Expand Down
1 change: 1 addition & 0 deletions src/Shared/SemanticConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ internal static class SemanticConventions
public const string AttributeExceptionType = "exception.type";
public const string AttributeExceptionMessage = "exception.message";
public const string AttributeExceptionStacktrace = "exception.stacktrace";
public const string AttributeErrorType = "error.type";

// v1.21.0
// https://github.com/open-telemetry/semantic-conventions/blob/v1.21.0/docs/http/http-metrics.md#http-server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class HttpInListenerTests
[InlineData("https://localhost:1843/subroute/10", "https", "/subroute/10", null, "localhost", 1843, "GET", "GET", null, 4, "subroute/{customerId}")]
[InlineData("http://localhost/api/value", "http", "/api/value", null, "localhost", 80, "GET", "GET", null, 0, null, false, "/api/value")] // Request will be filtered
[InlineData("http://localhost/api/value", "http", "/api/value", null, "localhost", 80, "GET", "GET", null, 0, null, false, "{ThrowException}")] // Filter user code will throw an exception
[InlineData("http://localhost/", "http", "/", null, "localhost", 80, "GET", "GET", null, 0, null, false, null, true)] // Test RecordException option
[InlineData("http://localhost/", "http", "/", null, "localhost", 80, "GET", "GET", null, 0, null, false, null, true, "System.InvalidOperationException")] // Test RecordException option
public void AspNetRequestsAreCollectedSuccessfully(
string url,
string expectedUrlScheme,
Expand All @@ -49,7 +49,8 @@ public void AspNetRequestsAreCollectedSuccessfully(
string routeTemplate,
bool setStatusToErrorInEnrich = false,
string? filter = null,
bool recordException = false)
bool recordException = false,
string? expectedErrorType = null)
{
HttpContext.Current = RouteTestHelper.BuildHttpContext(url, routeType, routeTemplate, requestMethod);

Expand Down Expand Up @@ -133,6 +134,7 @@ public void AspNetRequestsAreCollectedSuccessfully(
Assert.Equal(expectedUrlQuery, span.GetTagValue("url.query"));
Assert.Equal(expectedUrlScheme, span.GetTagValue("url.scheme"));
Assert.Equal("Custom User Agent v1.2.3", span.GetTagValue("user_agent.original"));
Assert.Equal(expectedErrorType, span.GetTagValue("error.type"));

if (recordException)
{
Expand Down Expand Up @@ -257,7 +259,8 @@ void EnrichAction(Activity activity, string method, object obj)

break;

default:
case "OnException":
Assert.True(obj is Exception);
break;
}
}
Expand Down

0 comments on commit ccb1d4f

Please sign in to comment.