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 long running activity tag for SignalR connections #32084

Merged
merged 4 commits into from
Jun 7, 2021
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 @@ -115,6 +115,9 @@ public async Task ExecuteNegotiateAsync(HttpContext context, HttpConnectionDispa

private async Task ExecuteAsync(HttpContext context, ConnectionDelegate connectionDelegate, HttpConnectionDispatcherOptions options, ConnectionLogScope logScope)
{
// set a tag to allow Application Performance Management tools to differentiate long running requests for reporting purposes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen APM written out like this before

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know what it stood for and in 1 year I definitely wont remember.

context.Features.Get<IHttpActivityFeature>()?.Activity.AddTag("http.long_running", "true");
BrennanConroy marked this conversation as resolved.
Show resolved Hide resolved

var supportedTransports = options.Transports;

// Server sent events transport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Pipelines;
using System.Linq;
Expand Down Expand Up @@ -2078,7 +2079,7 @@ public async Task WriteThatIsDisposedBeforeCompleteReturns404()
TransportMaxBufferSize = 13,
ApplicationMaxBufferSize = 13
};

var connection = manager.CreateConnection(options);
connection.TransportType = HttpTransportType.LongPolling;

Expand Down Expand Up @@ -2594,6 +2595,53 @@ public async Task DisposeLongPollingConnectionDisposesServiceScope()
}
}

private class TestActivityFeature : IHttpActivityFeature
{
public TestActivityFeature(Activity activity)
{
Activity = activity;
}

public Activity Activity { get; set; }
}

[Fact]
public async Task LongRunningActivityTagSetOnExecuteAsync()
{
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.ServerSentEvents;

var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var services = new ServiceCollection();
services.AddSingleton<NeverEndingConnectionHandler>();
var context = MakeRequest("/foo", connection, services);
var cts = new CancellationTokenSource();
context.RequestAborted = cts.Token;
SetTransport(context, HttpTransportType.ServerSentEvents);

var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseConnectionHandler<NeverEndingConnectionHandler>();
var app = builder.Build();

var activityFeature = new TestActivityFeature(new Activity("name"));
activityFeature.Activity.Start();
context.Features.Set<IHttpActivityFeature>(activityFeature);

_ = dispatcher.ExecuteAsync(context, new HttpConnectionDispatcherOptions(), app);

Assert.Equal("true", Activity.Current.GetTagItem("http.long_running"));

connection.Transport.Output.Complete();

await connection.ConnectionClosed.WaitForCancellationAsync().DefaultTimeout();

activityFeature.Activity.Dispose();
}
}

private static async Task CheckTransportSupported(HttpTransportType supportedTransports, HttpTransportType transportType, int status, ILoggerFactory loggerFactory)
{
var manager = CreateConnectionManager(loggerFactory);
Expand Down