diff --git a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs index 1a344203727c..9115f92e694d 100644 --- a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs +++ b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs @@ -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, @@ -402,7 +422,7 @@ private void RecordRequestStartMetrics(HttpContext httpContext) }, ActivityName, ActivityKind.Server, - tags: null, + tags: tagsForCreation, links: null, loggingEnabled || diagnosticListenerActivityCreationEnabled); if (activity is null)