Example #1
0
        /// <summary>
        /// Calls the PreInvoke and PostInvoke methods before and after calling the next handler
        /// in the pipeline.
        /// </summary>
        public override async System.Threading.Tasks.Task <T> InvokeAsync <T>(IExecutionContext executionContext)
        {
            try
            {
                PreInvoke(executionContext);
                var response = await base.InvokeAsync <T>(executionContext).ConfigureAwait(false);

                return(response);
            }

            catch (AmazonServiceException e)
            {
                CaptureAmazonException(executionContext.RequestContext.CSMCallAttempt, e);
                throw;
            }
            catch (Exception e)
            {
                CaptureSDKExceptionMessage(executionContext.RequestContext.CSMCallAttempt, e);
                throw;
            }
            finally
            {
                CSMCallAttemptMetricsCapture(executionContext.RequestContext, executionContext.ResponseContext);
                CSMUtilities.SerializetoJsonAndPostOverUDPAsync(executionContext.RequestContext.CSMCallAttempt).ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Method that gets called in the final clause that captures data for each http request
        /// from the request and response context.
        /// </summary>
        protected static void CSMCallAttemptMetricsCapture(IRequestContext requestContext, IResponseContext responseContext)
        {
            requestContext.CSMCallAttempt.Service = requestContext.CSMCallEvent.Service;
            requestContext.CSMCallAttempt.Fqdn    = requestContext.Request.GetHeaderValue(HeaderKeys.HostHeader);

            requestContext.CSMCallAttempt.UserAgent = requestContext.Request.GetHeaderValue(HeaderKeys.UserAgentHeader);

            requestContext.CSMCallAttempt.SessionToken = requestContext.Request.GetHeaderValue(HeaderKeys.XAmzSecurityTokenHeader);

            requestContext.CSMCallAttempt.Region = requestContext.Request.DeterminedSigningRegion;

            requestContext.CSMCallAttempt.Api = CSMUtilities.
                                                GetApiNameFromRequest(requestContext.Request.RequestName, requestContext.ServiceMetaData.OperationNameMapping, requestContext.CSMCallAttempt.Service);

            requestContext.CSMCallAttempt.AccessKey = requestContext.ImmutableCredentials.AccessKey;

            requestContext.CSMCallAttempt.AttemptLatency = AWSSDKUtils.ConvertTimeSpanToMilliseconds(requestContext
                                                                                                     .Metrics.StopEvent(Metric.CSMAttemptLatency)
                                                                                                     .ElapsedTime);

            if (responseContext.HttpResponse != null)
            {
                if ((int)responseContext.HttpResponse.StatusCode > 0)
                {
                    requestContext.CSMCallAttempt.HttpStatusCode = (int)responseContext.HttpResponse.StatusCode;
                }

                requestContext.CSMCallAttempt.XAmznRequestId = responseContext.HttpResponse.GetHeaderValue(HeaderKeys.RequestIdHeader);

                requestContext.CSMCallAttempt.XAmzRequestId = responseContext.HttpResponse.GetHeaderValue(HeaderKeys.XAmzRequestIdHeader);

                requestContext.CSMCallAttempt.XAmzId2 = responseContext.HttpResponse.GetHeaderValue(HeaderKeys.XAmzId2Header);
            }
        }
Example #3
0
        /// <summary>
        /// Captures the overall execution time and logs final metrics.
        /// </summary>
        /// <typeparam name="T">The response type for the current request.</typeparam>
        /// <param name="executionContext">
        /// The execution context, it contains the request and response context.
        /// </param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        public override async System.Threading.Tasks.Task <T> InvokeAsync <T>(IExecutionContext executionContext)
        {
            executionContext.RequestContext.Metrics.AddProperty(Metric.AsyncCall, true);
            try
            {
                executionContext.RequestContext.Metrics.StartEvent(Metric.ClientExecuteTime);
                var response = await base.InvokeAsync <T>(executionContext).ConfigureAwait(false);

                return(response);
            }
            finally
            {
                var latency = AWSSDKUtils.ConvertTimeSpanToMilliseconds(executionContext.RequestContext.Metrics
                                                                        .StopEvent(Metric.ClientExecuteTime)
                                                                        .ElapsedTime);

#if BCL || CORECLR
                // capture the latency for the entire SDK call if CSM is enabled
                if (executionContext.RequestContext.CSMEnabled)
                {
                    executionContext.RequestContext.CSMCallEvent.Latency = latency;
                    CSMUtilities.SerializetoJsonAndPostOverUDPAsync(executionContext.RequestContext.CSMCallEvent).ConfigureAwait(false);
                }
#endif
                this.LogMetrics(executionContext);
            }
        }
Example #4
0
        /// <summary>
        /// Captures the overall execution time and logs final metrics.
        /// </summary>
        /// <param name="executionContext">The execution context which contains both the
        /// requests and response context.</param>
        public override void InvokeSync(IExecutionContext executionContext)
        {
            executionContext.RequestContext.Metrics.AddProperty(Metric.AsyncCall, false);
            try
            {
                executionContext.RequestContext.Metrics.StartEvent(Metric.ClientExecuteTime);
                base.InvokeSync(executionContext);
            }
            finally
            {
                var latency = AWSSDKUtils.ConvertTimeSpanToMilliseconds(executionContext.RequestContext.Metrics
                                                                        .StopEvent(Metric.ClientExecuteTime)
                                                                        .ElapsedTime);

#if BCL || CORECLR
                // capture the latency for the entire SDK call if CSM is enabled
                if (executionContext.RequestContext.CSMEnabled)
                {
                    executionContext.RequestContext.CSMCallEvent.Latency = latency;
                    CSMUtilities.SerializetoJsonAndPostOverUDP(executionContext.RequestContext.CSMCallEvent);
                }
#endif
                this.LogMetrics(executionContext);
            }
        }
 protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
 {
     if (executionContext.ResponseContext.AsyncResult.Exception != null)
     {
         CaptureCSMCallEventExceptionData(executionContext.RequestContext, executionContext.ResponseContext.AsyncResult.Exception);
     }
     CSMCallEventMetricsCapture(ExecutionContext.CreateFromAsyncContext(executionContext));
     CSMUtilities.BeginSerializetoJsonAndPostOverUDP(executionContext.RequestContext.CSMCallEvent);
     base.InvokeAsyncCallback(executionContext);
 }
Example #6
0
        /// <summary>
        /// Captures the overall execution time and logs final metrics.
        /// </summary>
        /// <param name="executionContext">The execution context, it contains the
        /// request and response context.</param>
        protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
        {
            var latency = AWSSDKUtils.ConvertTimeSpanToMilliseconds(executionContext.RequestContext.Metrics
                                                                    .StopEvent(Metric.ClientExecuteTime)
                                                                    .ElapsedTime);

#if BCL
            // capture the latency for the entire SDK call if CSM is enabled
            if (executionContext.RequestContext.CSMEnabled)
            {
                executionContext.RequestContext.CSMCallEvent.Latency = latency;
                CSMUtilities.BeginSerializetoJsonAndPostOverUDP(executionContext.RequestContext.CSMCallEvent);
            }
#endif
            this.LogMetrics(ExecutionContext.CreateFromAsyncContext(executionContext));
            base.InvokeAsyncCallback(executionContext);
        }
 /// <summary>
 /// Invokes the CSM handler and captures data for the CSM events.
 /// </summary>
 public override void InvokeSync(IExecutionContext executionContext)
 {
     try
     {
         PreInvoke(executionContext);
         base.InvokeSync(executionContext);
     }
     catch (Exception e)
     {
         CaptureCSMCallEventExceptionData(executionContext.RequestContext, e);
         throw;
     }
     finally
     {
         CSMCallEventMetricsCapture(executionContext);
         CSMUtilities.SerializetoJsonAndPostOverUDP(executionContext.RequestContext.CSMCallEvent);
     }
 }
Example #8
0
        /// <summary>
        /// Calls the PreInvoke and PostInvoke methods before and after calling the next handler
        /// in the pipeline.
        /// </summary>
        public override async System.Threading.Tasks.Task <T> InvokeAsync <T>(IExecutionContext executionContext)
        {
            try
            {
                PreInvoke(executionContext);
                var response = await base.InvokeAsync <T>(executionContext).ConfigureAwait(false);

                return(response);
            }
            catch (Exception e)
            {
                CaptureCSMCallEventExceptionData(executionContext.RequestContext);
                throw;
            }
            finally
            {
                CSMCallEventMetricsCapture(executionContext);
                CSMUtilities.SerializetoJsonAndPostOverUDPAsync(executionContext.RequestContext.CSMCallEvent).ConfigureAwait(false);
            }
        }
Example #9
0
 /// <summary>
 /// Invokes the CSM handler and captures data for the CSM attempts.
 /// </summary>
 public override void InvokeSync(IExecutionContext executionContext)
 {
     try
     {
         PreInvoke(executionContext);
         base.InvokeSync(executionContext);
     }
     catch (AmazonServiceException e)
     {
         CaptureAmazonException(executionContext.RequestContext.CSMCallAttempt, e);
         throw;
     }
     catch (Exception e)
     {
         CaptureSDKExceptionMessage(executionContext.RequestContext.CSMCallAttempt, e);
         throw;
     }
     finally
     {
         CSMCallAttemptMetricsCapture(executionContext.RequestContext, executionContext.ResponseContext);
         CSMUtilities.SerializetoJsonAndPostOverUDP(executionContext.RequestContext.CSMCallAttempt);
     }
 }
Example #10
0
        protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
        {
            var syncExecutionContext = ExecutionContext.CreateFromAsyncContext(executionContext);

            if (executionContext.ResponseContext.AsyncResult.Exception != null)
            {
                var exception = executionContext.ResponseContext.AsyncResult.Exception;
                if (exception is AmazonServiceException)
                {
                    CaptureAmazonException(syncExecutionContext.RequestContext.CSMCallAttempt, exception as AmazonServiceException);
                }
                else
                {
                    if (syncExecutionContext.ResponseContext.HttpResponse == null)
                    {
                        CaptureSDKExceptionMessage(syncExecutionContext.RequestContext.CSMCallAttempt, exception);
                    }
                }
            }

            CSMCallAttemptMetricsCapture(syncExecutionContext.RequestContext, syncExecutionContext.ResponseContext);
            CSMUtilities.BeginSerializetoJsonAndPostOverUDP(executionContext.RequestContext.CSMCallAttempt);
            base.InvokeAsyncCallback(executionContext);
        }
 public MonitoringAPICall(IRequestContext requestContext)
     : this()
 {
     Service = requestContext.ServiceMetaData.ServiceId;
     Api     = CSMUtilities.GetApiNameFromRequest(requestContext.RequestName, requestContext.ServiceMetaData.OperationNameMapping, Service);
 }