/// <summary>
        /// Closes the current scope and makes its parent scope active
        /// </summary>
        internal void Close()
        {
            _scopeManager.Close(this);

            if (_finishOnClose)
            {
                Span.Finish();
            }
        }
        /// <summary>
        /// OnMethodEnd callback
        /// </summary>
        /// <typeparam name="TTarget">Type of the target</typeparam>
        /// <typeparam name="TReturn">Type of the return value</typeparam>
        /// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
        /// <param name="returnValue">Task of HttpResponse message instance</param>
        /// <param name="exception">Exception instance in case the original code threw an exception.</param>
        /// <param name="state">Calltarget state value</param>
        /// <returns>A response value, in an async scenario will be T of Task of T</returns>
        public static CallTargetReturn <TReturn> OnMethodEnd <TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
        {
            IntegrationState integrationState = (IntegrationState)state.State;

            if (integrationState.Scope != null)
            {
                // Before returning the control flow we need to restore the parent Scope setted by ScopeFactory.CreateOutboundHttpScope
                // This doesn't affect to OnAsyncMethodEnd async continuation, an ExecutionContext is captured
                // by the inner await.
                IScopeManager scopeManager = ((IDatadogTracer)Tracer.Instance).ScopeManager;
                if (scopeManager.Active == integrationState.Scope)
                {
                    scopeManager.Close(integrationState.Scope);
                }
            }

            return(new CallTargetReturn <TReturn>(returnValue));
        }