/// <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));
        }
Beispiel #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);
        }
Beispiel #3
0
 /// <summary>
 /// OnMethodBegin callback
 /// </summary>
 /// <typeparam name="TTarget">Type of the target</typeparam>
 /// <typeparam name="TSchema">Type of the schema</typeparam>
 /// <typeparam name="TDocument">Type of the document</typeparam>
 /// <typeparam name="TRules">Type of the rules</typeparam>
 /// <typeparam name="TUserContext">Type of the user context</typeparam>
 /// <typeparam name="TInputs">Type of the inputs</typeparam>
 /// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
 /// <param name="originalQuery">The source of the original GraphQL query</param>
 /// <param name="schema">The GraphQL schema value</param>
 /// <param name="document">The GraphQL document value</param>
 /// <param name="rules">The list of validation rules</param>
 /// <param name="userContext">The user context</param>
 /// <param name="inputs">The input variables</param>
 /// <returns>Calltarget state value</returns>
 internal static CallTargetState OnMethodBegin <TTarget, TSchema, TDocument, TRules, TUserContext, TInputs>(TTarget instance, string originalQuery, TSchema schema, TDocument document, TRules rules, TUserContext userContext, TInputs inputs)
     where TDocument : IDocument
 {
     return(new CallTargetState(GraphQLCommon.CreateScopeFromValidate(Tracer.Instance, document.OriginalQuery)));
 }
 /// <summary>
 /// OnMethodBegin callback
 /// </summary>
 /// <typeparam name="TTarget">Type of the target</typeparam>
 /// <typeparam name="TContext">Type of the execution context</typeparam>
 /// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
 /// <param name="context">The execution context of the GraphQL operation.</param>
 /// <returns>Calltarget state value</returns>
 internal static CallTargetState OnMethodBegin <TTarget, TContext>(TTarget instance, TContext context)
     where TContext : IExecutionContext
 {
     return(new CallTargetState(scope: GraphQLCommon.CreateScopeFromExecuteAsync(Tracer.Instance, context), state: context));
 }