Skip to content

Commit

Permalink
Add span links to the StartActiveInternal and propagate it into our S…
Browse files Browse the repository at this point in the history
…pan constructor, since it is a first-class field
  • Loading branch information
zacharycmontoya committed Jan 9, 2025
1 parent 5d3f014 commit eeb0838
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,10 @@ public Scope StartAspNetCorePipelineScope(Tracer tracer, Security security, Http
var routeTemplateResourceNames = tracer.Settings.RouteTemplateResourceNamesEnabled;
var tags = routeTemplateResourceNames ? new AspNetCoreEndpointTags() : new AspNetCoreTags();

var scope = tracer.StartActiveInternal(_requestInOperationName, extractedContext.SpanContext, tags: tags);
var scope = tracer.StartActiveInternal(_requestInOperationName, extractedContext.SpanContext, tags: tags, links: extractedContext.Links);
scope.Span.DecorateWebServerSpan(resourceName, httpMethod, host, url, userAgent, tags);
AddHeaderTagsToSpan(scope.Span, request, tracer);

foreach (var link in extractedContext.Links)
{
// TODO: We should probably just add this as another argument in StartActiveInternal
scope.Span.AddLink(link);
}

var originalPath = request.PathBase.HasValue ? request.PathBase.Add(request.Path) : request.Path;
httpContext.Features.Set(new RequestTrackingFeature(originalPath, scope));

Expand Down
8 changes: 7 additions & 1 deletion tracer/src/Datadog.Trace/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using Datadog.Trace.Debugger.ExceptionAutoInstrumentation;
Expand Down Expand Up @@ -37,12 +38,17 @@ internal Span(SpanContext context, DateTimeOffset? start)
{
}

internal Span(SpanContext context, DateTimeOffset? start, ITags tags)
internal Span(SpanContext context, DateTimeOffset? start, ITags tags, IEnumerable<SpanLink> links = null)
{
Tags = tags ?? new CommonTags();
Context = context;
StartTime = start ?? Context.TraceContext.Clock.UtcNow;

foreach (var link in links ?? Enumerable.Empty<SpanLink>())
{
AddLink(link);
}

if (IsLogLevelDebugEnabled)
{
WriteCtorDebugMessage();
Expand Down
7 changes: 4 additions & 3 deletions tracer/src/Datadog.Trace/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,10 @@ internal SpanContext CreateSpanContext(ISpanContext parent = null, string servic
/// and the span count metric is incremented. Alternatively, if this is not being called from an
/// automatic integration, call <c>TelemetryFactory.Metrics.RecordCountSpanCreated()</c> directory instead.
/// </remarks>
internal Scope StartActiveInternal(string operationName, ISpanContext parent = null, string serviceName = null, DateTimeOffset? startTime = null, bool finishOnClose = true, ITags tags = null)
internal Scope StartActiveInternal(string operationName, ISpanContext parent = null, string serviceName = null, DateTimeOffset? startTime = null, bool finishOnClose = true, ITags tags = null, IEnumerable<SpanLink> links = null)
{
var span = StartSpan(operationName, tags, parent, serviceName, startTime);
var span = StartSpan(operationName, tags, parent, serviceName, startTime, links: links);

return TracerManager.ScopeManager.Activate(span, finishOnClose);
}

Expand All @@ -494,7 +495,7 @@ internal Scope StartActiveInternal(string operationName, ISpanContext parent = n
/// and the span count metric is incremented. Alternatively, if this is not being called from an
/// automatic integration, call <c>TelemetryFactory.Metrics.RecordCountSpanCreated()</c> directly instead.
/// </remarks>
internal Span StartSpan(string operationName, ITags tags = null, ISpanContext parent = null, string serviceName = null, DateTimeOffset? startTime = null, TraceId traceId = default, ulong spanId = 0, string rawTraceId = null, string rawSpanId = null, bool addToTraceContext = true)
internal Span StartSpan(string operationName, ITags tags = null, ISpanContext parent = null, string serviceName = null, DateTimeOffset? startTime = null, TraceId traceId = default, ulong spanId = 0, string rawTraceId = null, string rawSpanId = null, bool addToTraceContext = true, IEnumerable<SpanLink> links = null)
{
var spanContext = CreateSpanContext(parent, serviceName, traceId, spanId, rawTraceId, rawSpanId);

Expand Down

0 comments on commit eeb0838

Please sign in to comment.