Skip to content
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

Align transaction names with Java #659

Merged
merged 5 commits into from
Dec 18, 2020
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## vNext

- Align transaction names with Java. (#659) @Tyrrrz

## 3.0.0-alpha.7

* Ref moved SentryId from namespace Sentry.Protocol to Sentry (#643) @lucas-zimerman
Expand Down
10 changes: 10 additions & 0 deletions src/Sentry.AspNetCore/Extensions/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,15 @@ internal static class HttpContextExtensions
// then there is no way for us to extract anything that resembles a route template.
return null;
}

public static string GetTransactionName(this HttpContext context)
{
// Try to get the route template or fallback to the request path

var method = context.Request.Method.ToUpperInvariant();
var route = context.TryGetRouteTemplate() ?? context.Request.Path;

return $"{method} {route}";
}
}
}
2 changes: 1 addition & 1 deletion src/Sentry.AspNetCore/ScopeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static void Populate(this Scope scope, HttpContext context, SentryAspNetC
scope.SetTag("route.area", area);
}

scope.TransactionName = context.TryGetRouteTemplate() ?? context.Request.Path;
scope.TransactionName = context.GetTransactionName();
}
catch(Exception e)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Sentry.AspNetCore/SentryMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public async Task InvokeAsync(HttpContext context)
});

var transaction = hub.CreateTransaction(
// Try to get the route template or fallback to the request path
context.TryGetRouteTemplate() ?? context.Request.Path,
context.GetTransactionName(),
"http.server"
);

Expand Down
3 changes: 2 additions & 1 deletion test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ public void Populate_RouteData_SetToScope()
var features = new FeatureCollection();
features.Set<IRoutingFeature>(routeFeature);
_ = _httpContext.Features.Returns(features);
_ = _httpContext.Request.Method.Returns("GET");

_sut.Populate(_httpContext, SentryAspNetCoreOptions);

Assert.Equal($"{controller}.{action}", _sut.TransactionName);
Assert.Equal($"GET {controller}.{action}", _sut.TransactionName);
}

public static IEnumerable<object[]> InvalidRequestBodies()
Expand Down