Esempio n. 1
0
        /// <summary>
        /// OnMethodEnd callback
        /// </summary>
        /// <typeparam name="TTarget">Type of the target</typeparam>
        /// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
        /// <param name="exception">Exception instance in case the original code threw an exception.</param>
        /// <param name="state">Calltarget state value</param>
        /// <returns>Return value of the method</returns>
        public static CallTargetReturn OnMethodEnd <TTarget>(TTarget instance, Exception exception, CallTargetState state)
        {
            if (!Tracer.Instance.Settings.IsIntegrationEnabled(IntegrationName))
            {
                return(CallTargetReturn.GetDefault());
            }

            SynchronizationContext context = SynchronizationContext.Current;

            try
            {
                SynchronizationContext.SetSynchronizationContext(null);
                // We have to ensure the flush of the buffer after we finish the tests of an assembly.
                // For some reason, sometimes when all test are finished none of the callbacks to handling the tracer disposal is triggered.
                // So the last spans in buffer aren't send to the agent.
                // Other times we reach the 500 items of the buffer in a sec and the tracer start to drop spans.
                // In a test scenario we must keep all spans.
                Tracer.Instance.FlushAsync().GetAwaiter().GetResult();
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(context);
            }

            return(CallTargetReturn.GetDefault());
        }
Esempio n. 2
0
 internal static CallTargetReturn EndInvocationVoid(Exception exception, Scope scope, ILambdaExtensionRequest requestBuilder)
 {
     scope?.Dispose();
     Flush();
     NotifyExtensionEnd(requestBuilder, scope, exception != null);
     return(CallTargetReturn.GetDefault());
 }
Esempio n. 3
0
        public static CallTargetReturn OnMethodEnd <TTarget>(TTarget instance, Exception exception, CallTargetState state)
        {
            CallTargetReturn returnValue = CallTargetReturn.GetDefault();
            string           msg         = $"{returnValue} {nameof(Noop3ArgumentsVoidIntegration)}.OnMethodEnd<{typeof(TTarget).FullName}>({instance}, {exception}, {state})";

            Console.WriteLine(msg);
            return(returnValue);
        }
        /// <summary>
        /// OnAsyncMethodEnd callback
        /// </summary>
        /// <typeparam name="TTarget">Type of the target</typeparam>
        /// <param name="instance">Instance value, aka `this` of the instrumented method.</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 OnMethodEnd<TTarget>(TTarget instance, Exception exception, CallTargetState state)
        {
            var scope = state.Scope;

            scope.DisposeWithException(exception);

            return CallTargetReturn.GetDefault();
        }
    public static CallTargetReturn EndMethod <TIntegration, TTarget>(TTarget instance, Exception exception, CallTargetState state)
    {
        if (IntegrationOptions <TIntegration, TTarget> .IsIntegrationEnabled)
        {
            return(EndMethodHandler <TIntegration, TTarget> .Invoke(instance, exception, state));
        }

        return(CallTargetReturn.GetDefault());
    }
        public static CallTargetReturn OnMethodEnd <TTarget>(TTarget instance, Exception exception, CallTargetState state)
        {
            CallTargetReturn returnValue = CallTargetReturn.GetDefault();

            Console.WriteLine($"ProfilerOK: EndMethod(0)<{typeof(Noop1ArgumentsVoidIntegration)}, {typeof(TTarget)}>({instance}, {exception?.ToString() ?? "(null)"}, {state})");
            if (instance?.GetType().Name.Contains("ThrowOnEnd") == true)
            {
                Console.WriteLine("Exception thrown.");
                throw new Exception();
            }

            return(returnValue);
        }
Esempio n. 7
0
        /// <summary>
        /// OnMethodEnd callback
        /// </summary>
        /// <typeparam name="TTarget">Type of the target</typeparam>
        /// <param name="instance">Instance value, aka `this` of the instrumented method.</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 OnMethodEnd <TTarget>(TTarget instance, Exception exception, CallTargetState state)
        {
            var span = state.Segment;

            if (span is not null)
            {
                if (exception is not null)
                {
                    span.CaptureException(exception);
                }

                span.End();
            }

            return(CallTargetReturn.GetDefault());
        }
Esempio n. 8
0
        public static CallTargetReturn OnMethodEnd <TTarget>(TTarget instance, Exception?exception, CallTargetState state)
        {
            if (!TracerManager.Instance.DirectLogSubmission.Settings.IsIntegrationEnabled(IntegrationId.ILogger))
            {
                return(CallTargetReturn.GetDefault());
            }

            if (exception is not null)
            {
                // If there's an exception during the constructor, things aren't going to work anyway
                return(CallTargetReturn.GetDefault());
            }

            LoggerFactoryIntegrationCommon <TTarget> .AddDirectSubmissionLoggerProvider(instance);

            return(CallTargetReturn.GetDefault());
        }
        /// <summary>
        /// OnMethodEnd callback
        /// </summary>
        /// <typeparam name="TTarget">Type of the target</typeparam>
        /// <param name="instance">Instance value, aka `this` of the instrumented method.</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 OnMethodEnd <TTarget>(TTarget instance, Exception exception, CallTargetState state)
        {
            if (state.State is Action <ITypedDeliveryHandlerShimAction> updateHandlerAction &&
                instance.TryDuckCast <ITypedDeliveryHandlerShimAction>(out var shim))
            {
                try
                {
                    updateHandlerAction.Invoke(shim);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "There was an error updating the delivery report handler to ");
                    // Not ideal to close the span here immediately, but as we can't trace the result,
                    // we don't really have a choice
                    state.Scope?.Span.Finish();
                }
            }

            return(CallTargetReturn.GetDefault());
        }
 static EndMethodHandler()
 {
     try
     {
         DynamicMethod dynMethod = IntegrationMapper.CreateEndMethodDelegate(typeof(TIntegration), typeof(TTarget));
         if (dynMethod != null)
         {
             _invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
         }
     }
     catch (Exception ex)
     {
         throw new CallTargetInvokerException(ex);
     }
     finally
     {
         if (_invokeDelegate is null)
         {
             _invokeDelegate = (instance, exception, state) => CallTargetReturn.GetDefault();
         }
     }
 }
            public Task <HttpResponseMessage> PublicSendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
            {
                Task <HttpResponseMessage> result = CachedResult;
                CallTargetState            state  = CallTargetState.GetDefault();
                CallTargetReturn <Task <HttpResponseMessage> > cReturn = CallTargetReturn <Task <HttpResponseMessage> > .GetDefault();

                Exception exception = null;

                try
                {
                    try
                    {
                        state = CallTargetInvoker.BeginMethod <HttpClientHandlerIntegration, HttpClientHandler, HttpRequestMessage, CancellationToken>(this, request, cancellationToken);
                    }
                    catch (Exception ex)
                    {
                        CallTargetInvoker.LogException <HttpClientHandlerIntegration, HttpClientHandler>(ex);
                    }
                    result = CachedResult;
                }
                catch (Exception ex)
                {
                    exception = ex;
                    throw;
                }
                finally
                {
                    try
                    {
                        cReturn = CallTargetInvoker.EndMethod <HttpClientHandlerIntegration, HttpClientHandler, Task <HttpResponseMessage> >(this, result, exception, state);
                        result  = cReturn.GetReturnValue();
                    }
                    catch (Exception ex)
                    {
                        CallTargetInvoker.LogException <HttpClientHandlerIntegration, HttpClientHandler>(ex);
                    }
                }
                return(result);
            }
Esempio n. 12
0
 /// <summary>
 /// OnMethodEnd callback
 /// </summary>
 /// <typeparam name="TTarget">Type of the target</typeparam>
 /// <param name="instance">Instance value, aka `this` of the instrumented method.</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 OnMethodEnd <TTarget>(TTarget instance, Exception exception, CallTargetState state)
 {
     return(CallTargetReturn.GetDefault());
 }
 /// <summary>
 /// OnMethodEnd callback
 /// </summary>
 /// <typeparam name="TTarget">Type of the target</typeparam>
 /// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
 /// <param name="exception">Exception instance in case the original code threw an exception.</param>
 /// <param name="state">Calltarget state value</param>
 /// <returns>Return value of the method</returns>
 public static CallTargetReturn OnMethodEnd <TTarget>(TTarget instance, Exception exception, CallTargetState state)
 {
     Common.FlushSpans(NUnitIntegration.IntegrationId);
     return(CallTargetReturn.GetDefault());
 }