Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Liudmila Molkova committed Apr 11, 2019
1 parent c039272 commit 03d7d25
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,15 @@ public void OnHttpRequestInStart(HttpContext httpContext)
// with W3C support on .NET https://github.com/dotnet/corefx/issues/30331

newActivity = new Activity(ActivityCreatedByHostingDiagnosticListener);
newActivity.SetParentId(StringUtilities.GenerateTraceId());
if (this.enableW3CHeaders)
{
newActivity.GenerateW3CContext();
newActivity.SetParentId(newActivity.GetTraceId());
}
else
{
newActivity.SetParentId(W3CUtilities.GenerateTraceId());
}
// end of workaround
}

Expand Down Expand Up @@ -257,7 +265,9 @@ public void OnBeginRequest(HttpContext httpContext, long timestamp)
InjectionGuardConstants.RequestHeaderMaxLength);
}
}
else if(!activity.IsW3CActivity())

// no headers
else if (originalParentId == null)
{
// As a first step in supporting W3C protocol in ApplicationInsights,
// we want to generate Activity Ids in the W3C compatible format.
Expand All @@ -266,8 +276,16 @@ public void OnBeginRequest(HttpContext httpContext, long timestamp)
// So if there is no current Activity (i.e. there were no Request-Id header in the incoming request), we'll override ParentId on
// the current Activity by the properly formatted one. This workaround should go away
// with W3C support on .NET https://github.com/dotnet/corefx/issues/30331

activity.SetParentId(StringUtilities.GenerateTraceId());

if (this.enableW3CHeaders)
{
activity.GenerateW3CContext();
activity.SetParentId(activity.GetTraceId());
}
else
{
activity.SetParentId(W3CUtilities.GenerateTraceId());
}

// end of workaround
}
Expand Down Expand Up @@ -337,6 +355,10 @@ private RequestTelemetry InitializeRequestTelemetry(HttpContext httpContext, Act
requestTelemetry.Context.Operation.Id = activity.RootId;
requestTelemetry.Id = activity.Id;
}
else
{
activity.UpdateTelemetry(requestTelemetry, false);
}

foreach (var prop in activity.Baggage)
{
Expand Down Expand Up @@ -490,10 +512,6 @@ private void SetW3CContext(IHeaderDictionary requestHeaders, Activity activity,
InjectionGuardConstants.TraceParentHeaderMaxLength);
activity.SetTraceparent(parentTraceParent);
}
else
{
activity.GenerateW3CContext();
}

string[] traceStateValues = HttpHeadersUtilities.SafeGetCommaSeparatedHeaderValues(requestHeaders, W3C.W3CConstants.TraceStateHeader,
InjectionGuardConstants.TraceStateHeaderMaxLength, InjectionGuardConstants.TraceStateMaxPairs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,6 @@ public void OnBeginRequestWithW3CSupportAndNoHeadersIsTrackedCorrectly(bool isAs

var activityInitializedByW3CHeader = Activity.Current;

if (!isAspNetCore2)
{
Assert.Null(activityInitializedByW3CHeader.ParentId);

This comment has been minimized.

Copy link
@lmolkova

lmolkova Apr 11, 2019

Member

just a meaningless requirement.

}
Assert.NotNull(activityInitializedByW3CHeader.GetTraceId());
Assert.Equal(32, activityInitializedByW3CHeader.GetTraceId().Length);
Assert.Equal(16, activityInitializedByW3CHeader.GetSpanId().Length);
Expand Down

0 comments on commit 03d7d25

Please sign in to comment.