Skip to content

Feature for setting activity tags on creation #62090

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 @@ -388,7 +388,7 @@ private void RecordRequestStartMetrics(HttpContext httpContext)
private Activity? StartActivity(HttpContext httpContext, bool loggingEnabled, bool diagnosticListenerActivityCreationEnabled, out bool hasDiagnosticListener)
{
hasDiagnosticListener = false;

var tagsForCreation = httpContext.Features.Get<IHttpActivityCreationTagsFeature>()?.ActivityCreationTags;
var headers = httpContext.Request.Headers;
var activity = ActivityCreator.CreateFromRemote(
_activitySource,
Expand All @@ -402,7 +402,7 @@ private void RecordRequestStartMetrics(HttpContext httpContext)
},
ActivityName,
ActivityKind.Server,
tags: null,
tags: tagsForCreation,
links: null,
loggingEnabled || diagnosticListenerActivityCreationEnabled);
if (activity is null)
Expand Down
18 changes: 18 additions & 0 deletions src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.Http.Features;

/// <summary>
/// Provides a mechanism to add tags to the <see cref="System.Diagnostics.Activity"/> at creation time for incoming HTTP requests.
/// These tags can be used for tracing when making sampling decisions.
/// </summary>
public interface IHttpActivityCreationTagsFeature
{
/// <summary>
/// A collection of tags to be added to the <see cref="System.Diagnostics.Activity"/> when it is created for the current HTTP request.
/// These tags are available at Activity creation time and can be used for sampling decisions.
/// </summary>
/// <returns>Tags to add to the Activity at creation time.</returns>
IEnumerable<KeyValuePair<string, object?>>? ActivityCreationTags { get; }
}
2 changes: 2 additions & 0 deletions src/Http/Http.Features/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature
Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature.ActivityCreationTags.get -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
Loading