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

add filter option #70

Merged
merged 1 commit into from
Jan 25, 2025
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 @@ -25,6 +25,11 @@ public HubInstrumentationFilter(ILoggerFactory loggerFactory, IOptions<HubInstru
HubInvocationContext invocationContext,
Func<HubInvocationContext, ValueTask<object?>> next)
{
if (_options.Filter?.Invoke(invocationContext) == false)
{
return await next(invocationContext);
}

var hubName = invocationContext.Hub.GetType().Name;
var methodName = invocationContext.HubMethodName;
var address = invocationContext.Context.GetHttpContext()?.Request.Host.Value;
Expand Down
19 changes: 19 additions & 0 deletions src/AspNetCore.SignalR.OpenTelemetry/HubInstrumentationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
using System;
using System.Diagnostics;
using Microsoft.AspNetCore.SignalR;

namespace AspNetCore.SignalR.OpenTelemetry;

public sealed class HubInstrumentationOptions
{
public Action<Activity, Exception>? OnException { get; set; }

/// <summary>
/// Gets or sets a filter function that determines whether or not to collect telemetry on a per invocation basis.
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item>
/// If filter is <see langword="null" />, all invocations are collected.
/// </item>
/// <item>
/// If filter returns <see langword="true" />, the invocation is collected.
/// </item>
/// <item>
/// If filter returns <see langword="false" /> the invocation is NOT collected.
/// </item>
/// </list>
/// </remarks>
public Func<HubInvocationContext, bool>? Filter { get; set; }
}
Loading