Skip to content

Commit b3f5117

Browse files
committed
Feature for setting activity tags on creation
1 parent 944f0f5 commit b3f5117

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ private void RecordRequestStartMetrics(HttpContext httpContext)
388388
private Activity? StartActivity(HttpContext httpContext, bool loggingEnabled, bool diagnosticListenerActivityCreationEnabled, out bool hasDiagnosticListener)
389389
{
390390
hasDiagnosticListener = false;
391-
391+
var tagsForCreation = httpContext.Features.Get<IHttpActivityCreationTagsFeature>()?.ActivityCreationTags;
392392
var headers = httpContext.Request.Headers;
393393
var activity = ActivityCreator.CreateFromRemote(
394394
_activitySource,
@@ -402,7 +402,7 @@ private void RecordRequestStartMetrics(HttpContext httpContext)
402402
},
403403
ActivityName,
404404
ActivityKind.Server,
405-
tags: null,
405+
tags: tagsForCreation,
406406
links: null,
407407
loggingEnabled || diagnosticListenerActivityCreationEnabled);
408408
if (activity is null)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics;
5+
6+
namespace Microsoft.AspNetCore.Http.Features;
7+
8+
/// <summary>
9+
/// Provides a mechanism to add tags to the <see cref="System.Diagnostics.Activity"/> at creation time for incoming HTTP requests.
10+
/// These tags can be used for tracing when making sampling decisions.
11+
/// </summary>
12+
public interface IHttpActivityCreationTagsFeature
13+
{
14+
/// <summary>
15+
/// A collection of tags to be added to the <see cref="System.Diagnostics.Activity"/> when it is created for the current HTTP request.
16+
/// These tags are available at Activity creation time and can be used for sampling decisions.
17+
/// </summary>
18+
/// <returns>An <see cref="ActivityTagsCollection"/> containing tags to add to the Activity at creation time.</returns>
19+
ActivityTagsCollection? ActivityCreationTags { get; }
20+
}
21+

0 commit comments

Comments
 (0)