/// <summary>
        /// OnMethodEnd callback
        /// </summary>
        /// <typeparam name="TTarget">Type of the target</typeparam>
        /// <typeparam name="TValidationResult">Type of the validation result value</typeparam>
        /// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
        /// <param name="validationResult">IValidationResult 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 <TValidationResult> OnMethodEnd <TTarget, TValidationResult>(TTarget instance, TValidationResult validationResult, Exception exception, CallTargetState state)
            where TValidationResult : IValidationResult
        {
            Scope scope = state.Scope;

            if (state.Scope is null)
            {
                return(new CallTargetReturn <TValidationResult>(validationResult));
            }

            try
            {
                if (exception != null)
                {
                    scope.Span?.SetException(exception);
                }
                else
                {
                    GraphQLCommon.RecordExecutionErrorsIfPresent(scope.Span, ErrorType, validationResult.Errors);
                }
            }
            finally
            {
                scope.Dispose();
            }

            return(new CallTargetReturn <TValidationResult>(validationResult));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// OnAsyncMethodEnd callback
        /// </summary>
        /// <typeparam name="TTarget">Type of the target</typeparam>
        /// <typeparam name="TExecutionResult">Type of the execution result value</typeparam>
        /// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
        /// <param name="executionResult">ExecutionResult 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 TExecutionResult OnAsyncMethodEnd <TTarget, TExecutionResult>(TTarget instance, TExecutionResult executionResult, Exception exception, CallTargetState state)
        {
            Scope scope = state.Scope;

            if (state.Scope is null)
            {
                return(executionResult);
            }

            try
            {
                if (exception != null)
                {
                    scope.Span?.SetException(exception);
                }
                else if (state.State is IExecutionContext context)
                {
                    GraphQLCommon.RecordExecutionErrorsIfPresent(scope.Span, ErrorType, context.Errors);
                }
            }
            finally
            {
                scope.Dispose();
            }

            return(executionResult);
        }