Beispiel #1
0
        /// <summary>
        /// Processes HTTP response.
        /// </summary>
        private static void ProcessHTTPResponse(Object sender, EventArgs e)
        {
            var context  = ((HttpApplication)sender).Context;
            var response = context.Response;

            if (!AWSXRayRecorder.Instance.IsTracingDisabled() && response != null)
            {
                Dictionary <string, object> responseAttributes = new Dictionary <string, object>();
                ProcessResponseAttributes(response, responseAttributes);
                _recorder.AddHttpInformation("response", responseAttributes);
            }

            Exception exc = context.Error; // Record exception, if any

            if (exc != null)
            {
                _recorder.AddException(exc);
            }

            TraceHeader traceHeader = GetTraceHeader(context);
            bool        isSampleDecisionRequested = traceHeader.Sampled == SampleDecision.Requested;

            if (traceHeader.Sampled == SampleDecision.Unknown || traceHeader.Sampled == SampleDecision.Requested)
            {
                SetSamplingDecision(traceHeader); // extracts sampling decision from the available segment
            }

            _recorder.EndSegment();
            // if the sample decision is requested, add the trace header to response
            if (isSampleDecisionRequested)
            {
                response.Headers.Add(TraceHeader.HeaderKey, traceHeader.ToString());
            }
        }
Beispiel #2
0
        public IHttpActionResult GetProduct(int id)
        {
            AWSXRayRecorder recorder = new AWSXRayRecorder();
            Product         product  = null;

            if (id <= 10)
            {
                product = products.FirstOrDefault((p) => p.Id == id);
            }
            else
            {
                try
                {
                    product = GetItem(id);
                }catch (Exception ex)
                {
                    recorder.AddException(ex);
                    throw;
                }
            }
            if (product == null)
            {
                recorder.AddAnnotation("MissingItem", id);
                return(NotFound());
            }

            return(Ok(product));
        }
Beispiel #3
0
        /// <inheritdoc />
        public async Task <TResult> InterceptAsync <TResult>(Func <Task <TResult> > method, DbCommand command)
        {
            _recorder.BeginSubsegment(BuildSubsegmentName(command));
            try
            {
                _recorder.SetNamespace("remote");
                var ret = await method();

                CollectSqlInformation(command);

                return(ret);
            }
            catch (Exception e)
            {
                _recorder.AddException(e);
                throw;
            }
            finally
            {
                _recorder.EndSubsegment();
            }
        }
Beispiel #4
0
        public void TestAddException()
        {
            _recorder.BeginSegment("test", TraceId);
            var e = new ArgumentNullException("value");

            _recorder.AddException(e);

            var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity();

            Assert.IsNotNull(segment);

            Assert.IsTrue(segment.HasFault);
            Assert.ReferenceEquals(e, segment.Cause.ExceptionDescriptors[0].Exception);

            _recorder.EndSegment();
        }
Beispiel #5
0
        public void TestLogErrorModeForContextMissingStrategy()
        {
            using (var recorder = new AWSXRayRecorder())
            {
                recorder.ContextMissingStrategy = ContextMissingStrategy.LOG_ERROR;

                recorder.EndSegment();
                recorder.BeginSubsegment("no segment");
                recorder.EndSubsegment();
                recorder.SetNamespace("dummy namespace");
                recorder.AddAnnotation("key", "value");
                recorder.AddHttpInformation("key", "value");
                recorder.MarkError();
                recorder.MarkFault();
                recorder.MarkThrottle();
                recorder.AddException(new ArgumentNullException());
                recorder.AddPrecursorId(Entity.GenerateId());
                recorder.AddSqlInformation("sqlKey", "value");
                recorder.AddMetadata("key", "value");
            }
        }
        /// <summary>
        /// Processes HTTP request and response. A segment is created at the beginning of the request and closed at the
        /// end of the request. If the web app is running on AWS Lambda, a subsegment is started and ended for the respective
        /// events.
        /// </summary>
        public async Task Invoke(HttpContext context)
        {
            ProcessHTTPRequest(context);

            try
            {
                if (_next != null)
                {
                    await _next.Invoke(context); // call next handler
                }
            }
            catch (Exception exc)
            {
                _recorder.AddException(exc);
                throw;
            }

            finally
            {
                ProcessHTTPResponse(context);
            }
        }
        private TResult Intercept <TResult>(Func <TResult> method)
        {
            AWSXRayRecorder recorder = AWSXRayRecorder.Instance;

            recorder.BeginSubsegment(Connection.Database + "@" + SqlUtil.RemovePortNumberFromDataSource(Connection.DataSource));
            try
            {
                recorder.SetNamespace("remote");
                var ret = method();
                CollectSqlInformation();

                return(ret);
            }
            catch (Exception e)
            {
                recorder.AddException(e);
                throw;
            }
            finally
            {
                recorder.EndSubsegment();
            }
        }
 /// <summary>
 /// Process exception.
 /// </summary>
 /// <param name="exception">Instance of <see cref="Exception"/>.</param>
 internal static void ProcessCommandError(Exception exception)
 {
     _recorder.AddException(exception);
     _recorder.EndSubsegment();
 }
 internal static void ProcessException(Exception exception)
 {
     _recorder.AddException(exception);
 }