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

support semconv 1.24.0 #21

Merged
merged 1 commit into from
Mar 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public HubInstrumentationFilter(ILoggerFactory loggerFactory)
{
var hubName = invocationContext.Hub.GetType().Name;
var methodName = invocationContext.HubMethodName;
var address = invocationContext.Context.GetHttpContext()?.Request.Host.Value;

using var scope = HubLogger.BeginHubMethodInvocationScope(_logger, hubName, methodName);
using var activity = HubActivitySource.StartInvocationActivity(hubName, methodName);
using var activity = HubActivitySource.StartInvocationActivity(hubName, methodName, address);

try
{
Expand All @@ -52,9 +53,10 @@ public HubInstrumentationFilter(ILoggerFactory loggerFactory)
public async Task OnConnectedAsync(HubLifetimeContext context, Func<HubLifetimeContext, Task> next)
{
var hubName = context.Hub.GetType().Name;
var address = context.Context.GetHttpContext()?.Request.Host.Value;

using var scope = HubLogger.BeginHubMethodInvocationScope(_logger, hubName, nameof(OnConnectedAsync));
using var activity = HubActivitySource.StartInvocationActivity(hubName, nameof(OnConnectedAsync));
using var activity = HubActivitySource.StartInvocationActivity(hubName, nameof(OnConnectedAsync), address);

try
{
Expand Down Expand Up @@ -83,9 +85,10 @@ public async Task OnDisconnectedAsync(
Func<HubLifetimeContext, Exception?, Task> next)
{
var hubName = context.Hub.GetType().Name;
var address = context.Context.GetHttpContext()?.Request.Host.Value;

using var scope = HubLogger.BeginHubMethodInvocationScope(_logger, hubName, nameof(OnDisconnectedAsync));
using var activity = HubActivitySource.StartInvocationActivity(hubName, nameof(OnDisconnectedAsync));
using var activity = HubActivitySource.StartInvocationActivity(hubName, nameof(OnDisconnectedAsync), address);

try
{
Expand Down
17 changes: 12 additions & 5 deletions src/AspNetCore.SignalR.OpenTelemetry/Internal/HubActivitySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ internal static class HubActivitySource

private static readonly ActivitySource ActivitySource = new(Name);

internal static Activity? StartInvocationActivity(string hubName, string methodName)
internal static Activity? StartInvocationActivity(string hubName, string methodName, string? address)
{
//https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/#span-name
var activity = ActivitySource.CreateActivity($"{hubName}/{methodName}", ActivityKind.Internal);
// https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/#span-name
var activity = ActivitySource.CreateActivity($"{hubName}/{methodName}", ActivityKind.Server);

if (activity is null)
{
return null;
}

activity.SetTag("signalr.hub", hubName);
activity.SetTag("signalr.method", methodName);
// https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/#common-attributes
activity.SetTag("rpc.system", "signalr");
activity.SetTag("rpc.service", hubName);
activity.SetTag("rpc.method", methodName);

if (!string.IsNullOrEmpty(address))
{
activity.SetTag("server.address", address);
}

return activity.Start();
}
Expand Down