Skip to content

Commit

Permalink
httpwebrequest context propagation when filter is applied (#1562)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Nov 17, 2020
1 parent d24a042 commit 68adae6
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,30 @@ private static bool IsRequestInstrumented(HttpWebRequest request)

private static void ProcessRequest(HttpWebRequest request)
{
if (!WebRequestActivitySource.HasListeners() || IsRequestInstrumented(request) || !Options.EventFilter(request))
if (!WebRequestActivitySource.HasListeners() || !Options.EventFilter(request))
{
// No subscribers to the ActivitySource or User provider Filter is
// filtering this request.
// Propagation must still be done in such cases, to allow
// downstream services to continue from parent context, if any.
// Eg: Parent could be the Asp.Net activity.
InstrumentRequest(request, Activity.Current?.Context ?? default);
return;
}

if (IsRequestInstrumented(request))
{
// No subscribers to the ActivitySource or this request was instrumented by previous
// This request was instrumented by previous
// ProcessRequest, such is the case with redirect responses where the same request is sent again.
return;
}

var activity = WebRequestActivitySource.StartActivity(ActivityName, ActivityKind.Client);
var activityContext = Activity.Current?.Context ?? default;

// Propagation must still be done in all cases, to allow
// downstream services to continue from parent context, if any.
// Eg: Parent could be the Asp.Net activity.
InstrumentRequest(request, activityContext);
if (activity == null)
{
Expand Down

0 comments on commit 68adae6

Please sign in to comment.