|
18 | 18 |
|
19 | 19 | using System; |
20 | 20 | using System.Collections.Generic; |
| 21 | +using System.Diagnostics; |
21 | 22 | using System.Linq; |
22 | 23 | using System.Net; |
23 | 24 | using System.Security.Cryptography.X509Certificates; |
@@ -608,6 +609,62 @@ private async Task LongRunningDeadlineAbort_WaitsUntilDeadlineAbortIsFinished(st |
608 | 609 | Assert.IsTrue(serverCallContext._callComplete); |
609 | 610 | } |
610 | 611 |
|
| 612 | + [Test] |
| 613 | + public void Initialize_MethodInPath_SetsMethodOnActivity() |
| 614 | + { |
| 615 | + using (new ActivityReplacer()) |
| 616 | + { |
| 617 | + // Arrange |
| 618 | + var httpContext = new DefaultHttpContext(); |
| 619 | + httpContext.Request.Path = "/Package.Service/Method"; |
| 620 | + var context = CreateServerCallContext(httpContext); |
| 621 | + |
| 622 | + // Act |
| 623 | + context.Initialize(); |
| 624 | + |
| 625 | + // Assert |
| 626 | + Assert.AreEqual("/Package.Service/Method", Activity.Current.Tags.Single(t => t.Key == "GrpcMethod").Value); |
| 627 | + } |
| 628 | + } |
| 629 | + |
| 630 | + [Test] |
| 631 | + public async Task EndCallAsync_StatusSet_SetsStatusOnActivity() |
| 632 | + { |
| 633 | + using (new ActivityReplacer()) |
| 634 | + { |
| 635 | + // Arrange |
| 636 | + var httpContext = new DefaultHttpContext(); |
| 637 | + var context = CreateServerCallContext(httpContext); |
| 638 | + context.Status = new Status(StatusCode.ResourceExhausted, string.Empty); |
| 639 | + |
| 640 | + // Act |
| 641 | + context.Initialize(); |
| 642 | + await context.EndCallAsync(); |
| 643 | + |
| 644 | + // Assert |
| 645 | + Assert.AreEqual("8", Activity.Current.Tags.Single(t => t.Key == "GrpcStatus").Value); |
| 646 | + } |
| 647 | + } |
| 648 | + |
| 649 | + [Test] |
| 650 | + public async Task ProcessHandlerErrorAsync_Exception_SetsStatusOnActivity() |
| 651 | + { |
| 652 | + using (new ActivityReplacer()) |
| 653 | + { |
| 654 | + // Arrange |
| 655 | + var httpContext = new DefaultHttpContext(); |
| 656 | + var context = CreateServerCallContext(httpContext); |
| 657 | + context.Status = new Status(StatusCode.ResourceExhausted, string.Empty); |
| 658 | + |
| 659 | + // Act |
| 660 | + context.Initialize(); |
| 661 | + await context.ProcessHandlerErrorAsync(new Exception(), "MethodName"); |
| 662 | + |
| 663 | + // Assert |
| 664 | + Assert.AreEqual("2", Activity.Current.Tags.Single(t => t.Key == "GrpcStatus").Value); |
| 665 | + } |
| 666 | + } |
| 667 | + |
611 | 668 | private HttpContextServerCallContext CreateServerCallContext(HttpContext httpContext, ILogger? logger = null) |
612 | 669 | { |
613 | 670 | return new HttpContextServerCallContext(httpContext, new GrpcServiceOptions(), logger ?? NullLogger.Instance); |
|
0 commit comments