internal static RequestTelemetry CreateRequestTelemetryPrivate(
            this HttpContext platformContext)
        {
            if (platformContext == null)
            {
                throw new ArgumentNullException(nameof(platformContext));
            }

            var result          = new RequestTelemetry();
            var currentActivity = Activity.Current;
            var requestContext  = result.Context.Operation;

            if (currentActivity == null)
            {
                // if there was no BeginRequest, ASP.NET HttpModule did not have a chance to set current activity (and will never do it).
                currentActivity = new Activity(ActivityHelpers.RequestActivityItemName);

                if (ActivityHelpers.IsW3CTracingEnabled)
                {
                    ActivityHelpers.ExtractW3CContext(platformContext.Request, currentActivity);
                    ActivityHelpers.ExtractTracestate(platformContext.Request, currentActivity, result);
                    // length enforced in SetW3CContext
                    currentActivity.SetParentId(currentActivity.GetTraceId());
                    W3COperationCorrelationTelemetryInitializer.UpdateTelemetry(result, currentActivity, true);

                    SetLegacyContextIds(platformContext.Request, result);
                }
                else if (currentActivity.Extract(platformContext.Request.Headers))
                {
                    requestContext.ParentId = currentActivity.ParentId;
                }
                else if (ActivityHelpers.TryParseCustomHeaders(platformContext.Request, out var rootId, out var parentId))
                {
                    currentActivity.SetParentId(rootId);
                    if (!string.IsNullOrEmpty(parentId))
                    {
                        currentActivity.SetParentId(rootId);
                        if (!string.IsNullOrEmpty(parentId))
                        {
                            requestContext.ParentId = parentId;
                        }
                    }
                }
                else
                {
                    // As a first step in supporting W3C protocol in ApplicationInsights,
                    // we want to generate Activity Ids in the W3C compatible format.
                    // While .NET changes to Activity are pending, we want to ensure trace starts with W3C compatible Id
                    // as early as possible, so that everyone has a chance to upgrade and have compatibility with W3C systems once they arrive.
                    // 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
                    currentActivity.SetParentId(StringUtilities.GenerateTraceId());
                    // end of workaround
                }

                currentActivity.Start();
            }