public Scope StartAspNetCorePipelineScope(Tracer tracer, HttpContext httpContext, HttpRequest request, string resourceName) { string host = request.Host.Value; string httpMethod = request.Method?.ToUpperInvariant() ?? "UNKNOWN"; string url = request.GetUrl(); resourceName ??= GetDefaultResourceName(request); SpanContext propagatedContext = ExtractPropagatedContext(request); var tagsFromHeaders = ExtractHeaderTags(request, tracer); AspNetCoreTags tags; if (tracer.Settings.RouteTemplateResourceNamesEnabled) { var originalPath = request.PathBase.HasValue ? request.PathBase.Add(request.Path) : request.Path; httpContext.Features.Set(new RequestTrackingFeature(originalPath)); tags = new AspNetCoreEndpointTags(); } else { tags = new AspNetCoreTags(); } var scope = tracer.StartActiveInternal(_requestInOperationName, propagatedContext, tags: tags); scope.Span.DecorateWebServerSpan(resourceName, httpMethod, host, url, tags, tagsFromHeaders); tags.SetAnalyticsSampleRate(_integrationId, tracer.Settings, enabledWithGlobalSetting: true); tracer.TracerManager.Telemetry.IntegrationGeneratedSpan(_integrationId); return(scope); }
private void OnHostingHttpRequestInStart(object arg) { var tracer = _tracer ?? Tracer.Instance; if (!tracer.Settings.IsIntegrationEnabled(IntegrationName)) { return; } var httpContext = HttpRequestInStartHttpContextFetcher.Fetch <HttpContext>(arg); HttpRequest request = httpContext.Request; string host = request.Host.Value; string httpMethod = request.Method?.ToUpperInvariant() ?? "UNKNOWN"; string url = GetUrl(request); string absolutePath = request.Path.Value; if (request.PathBase.HasValue) { absolutePath = request.PathBase.Value + absolutePath; } string resourceUrl = UriHelpers.GetRelativeUrl(absolutePath, tryRemoveIds: true) .ToLowerInvariant(); string resourceName = $"{httpMethod} {resourceUrl}"; SpanContext propagatedContext = ExtractPropagatedContext(request); var tagsFromHeaders = ExtractHeaderTags(request, tracer); var tags = new AspNetCoreTags(); var scope = tracer.StartActiveWithTags(HttpRequestInOperationName, propagatedContext, tags: tags); tags.InstrumentationName = ComponentName; scope.Span.DecorateWebServerSpan(resourceName, httpMethod, host, url, tags, tagsFromHeaders); // set analytics sample rate if enabled var analyticsSampleRate = tracer.Settings.GetIntegrationAnalyticsSampleRate(IntegrationName, enabledWithGlobalSetting: true); if (analyticsSampleRate != null) { tags.AnalyticsSampleRate = analyticsSampleRate; } }