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 9 commits into
base: main
Choose a base branch
from
Open
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 @@ -389,6 +389,26 @@ private void RecordRequestStartMetrics(HttpContext httpContext)
{
hasDiagnosticListener = false;

var tagsForCreation = new TagList();
if (_activitySource.HasListeners() && httpContext.Request.Host.HasValue)
{
var host = httpContext.Request.Host.Host;
var port = httpContext.Request.Host.Port;
tagsForCreation.Add("server.address", host);
if (port is not null)
{
tagsForCreation.Add("server.port", port);
}
else if (string.Equals("https", httpContext.Request.Scheme, StringComparison.OrdinalIgnoreCase))
{
tagsForCreation.Add("server.port", 443);
}
else if (string.Equals("http", httpContext.Request.Scheme, StringComparison.OrdinalIgnoreCase))
{
tagsForCreation.Add("server.port", 80);
}
}

var headers = httpContext.Request.Headers;
var activity = ActivityCreator.CreateFromRemote(
_activitySource,
Expand All @@ -402,7 +422,7 @@ private void RecordRequestStartMetrics(HttpContext httpContext)
},
ActivityName,
ActivityKind.Server,
tags: null,
tags: tagsForCreation,
links: null,
loggingEnabled || diagnosticListenerActivityCreationEnabled);
if (activity is null)
Expand Down
Loading