Skip to content

Commit 551a690

Browse files
committed
WN Update SignalR ActivitySource
1 parent 38acaae commit 551a690

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+86165
-23
lines changed

aspnetcore/release-notes/aspnetcore-9/includes/signalr-distributed-tracing-improvements.md

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,11 @@ The following example uses the [.NET Aspire dashboard](/dotnet/aspire/fundamenta
1919

2020
Add the following startup code to the `Program.cs` file:
2121

22-
```csharp
23-
// Set OTEL_EXPORTER_OTLP_ENDPOINT environment variable depending on where your OTEL endpoint is
24-
var builder = WebApplication.CreateBuilder(args);
25-
26-
builder.Services.AddRazorPages();
27-
builder.Services.AddSignalR();
28-
29-
builder.Services.AddOpenTelemetry()
30-
.WithTracing(tracing =>
31-
{
32-
if (builder.Environment.IsDevelopment())
33-
{
34-
// We want to view all traces in development
35-
tracing.SetSampler(new AlwaysOnSampler());
36-
}
37-
38-
tracing.AddAspNetCoreInstrumentation();
39-
tracing.AddSource("Microsoft.AspNetCore.SignalR.Server");
40-
});
41-
42-
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter());
43-
```
22+
[!code-csharp[](~/release-notes/aspnetcore-9/samples/SignalRChatTraceExample/Program.cs?name=snippet_trace_signalr_server&highlight=1,13-26)]
4423

4524
The following is example output from the Aspire Dashboard:
4625

47-
:::image type="content" source="~/release-notes/aspnetcore-9/_static/signalr-activites-events.png" alt-text="Activity list for SignalR Hub method call events":::
26+
:::image type="content" source="~/release-notes/aspnetcore-9/_static/signalr-activities-events.png" alt-text="Activity list for SignalR Hub method call events":::
4827

4928
#### .NET SignalR client ActivitySource
5029

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.AspNetCore.SignalR;
2+
3+
namespace SignalRChat.Hubs
4+
{
5+
public class ChatHub : Hub
6+
{
7+
public async Task SendMessage(string user, string message)
8+
{
9+
await Clients.All.SendAsync("ReceiveMessage", user, message);
10+
}
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
5+
namespace SignalRChat.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@page
2+
<div class="container">
3+
<div class="row p-1">
4+
<div class="col-1">User</div>
5+
<div class="col-5"><input type="text" id="userInput" /></div>
6+
</div>
7+
<div class="row p-1">
8+
<div class="col-1">Message</div>
9+
<div class="col-5"><input type="text" class="w-100" id="messageInput" /></div>
10+
</div>
11+
<div class="row p-1">
12+
<div class="col-6 text-end">
13+
<input type="button" id="sendButton" value="Send Message" />
14+
</div>
15+
</div>
16+
<div class="row p-1">
17+
<div class="col-6">
18+
<hr />
19+
</div>
20+
</div>
21+
<div class="row p-1">
22+
<div class="col-6">
23+
<ul id="messagesList"></ul>
24+
</div>
25+
</div>
26+
</div>
27+
<script src="~/js/signalr/dist/browser/signalr.js"></script>
28+
<script src="~/js/chat.js"></script>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace SignalRChat.Pages
5+
{
6+
public class IndexModel : PageModel
7+
{
8+
private readonly ILogger<IndexModel> _logger;
9+
10+
public IndexModel(ILogger<IndexModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
18+
}
19+
}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace SignalRChat.Pages
5+
{
6+
public class PrivacyModel : PageModel
7+
{
8+
private readonly ILogger<PrivacyModel> _logger;
9+
10+
public PrivacyModel(ILogger<PrivacyModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
}
18+
}
19+
20+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - SignalRChat</title>
7+
<script type="importmap"></script>
8+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
9+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
10+
<link rel="stylesheet" href="~/SignalRChat.styles.css" asp-append-version="true" />
11+
</head>
12+
<body>
13+
<header>
14+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
15+
<div class="container">
16+
<a class="navbar-brand" asp-area="" asp-page="/Index">SignalRChat</a>
17+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
18+
aria-expanded="false" aria-label="Toggle navigation">
19+
<span class="navbar-toggler-icon"></span>
20+
</button>
21+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
22+
<ul class="navbar-nav flex-grow-1">
23+
<li class="nav-item">
24+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
25+
</li>
26+
<li class="nav-item">
27+
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
28+
</li>
29+
</ul>
30+
</div>
31+
</div>
32+
</nav>
33+
</header>
34+
<div class="container">
35+
<main role="main" class="pb-3">
36+
@RenderBody()
37+
</main>
38+
</div>
39+
40+
<footer class="border-top footer text-muted">
41+
<div class="container">
42+
&copy; 2024 - SignalRChat - <a asp-area="" asp-page="/Privacy">Privacy</a>
43+
</div>
44+
</footer>
45+
46+
<script src="~/lib/jquery/dist/jquery.js"></script>
47+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
48+
<script src="~/js/site.js" asp-append-version="true"></script>
49+
50+
@await RenderSectionAsync("Scripts", required: false)
51+
</body>
52+
</html>

0 commit comments

Comments
 (0)