Exemple #1
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));
        }
Exemple #2
0
        public void TestAddAnnotation()
        {
            _recorder.BeginSegment("test", TraceId);
            _recorder.AddAnnotation("int", 98109);
            _recorder.AddAnnotation("string", "US");
            _recorder.AddAnnotation("bool", true);
            _recorder.AddAnnotation("long", 123L);
            _recorder.AddAnnotation("double", 100.2);

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

            Assert.AreEqual(98109, segment.Annotations["int"]);
            Assert.AreEqual("US", segment.Annotations["string"]);
            Assert.AreEqual(true, segment.Annotations["bool"]);
            Assert.AreEqual(123L, segment.Annotations["long"]);
            Assert.AreEqual(100.2, segment.Annotations["double"]);

            _recorder.EndSegment();
        }
Exemple #3
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");
            }
        }