public IEnumerable <WeatherForecast> Get()
        {
            var rng = new Random();

            var trace = Trace.Create();

            trace.Record(Annotations.ServerRecv());
            trace.Record(Annotations.ServiceName("WeatherForecast"));
            trace.Record(Annotations.Rpc("GET"));
            trace.Record(Annotations.Event("GET/ WeatherForecast"));
            Thread.Sleep(15);
            trace.Record(Annotations.Event("Waited for 15ms"));
            Thread.Sleep(20);
            trace.Record(Annotations.Event("Waited for 20ms"));
            trace.Record(Annotations.ServerSend());
            trace.Record(Annotations.Tag("http.url", "<url>"));

            var result = Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date         = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary      = Summaries[rng.Next(Summaries.Length)]
            })
                         .ToArray();

            return(result);
        }
Beispiel #2
0
        public Task RegisterBusHandlerAsync(IRequestMatcher pattern, Func <Message, CancellationToken, Task> handler, RouteExecution execution = RouteExecution.Asynchronous, RouteMode mode = RouteMode.Observe, CancellationToken cancellationToken = default)
        {
            return(_registration.RegisterBusHandlerAsync(
                       pattern,
                       async(message, handlerToken) =>
            {
                Trace.Current = ExtractTracing(message);

                var trace = Trace.Current;
                trace.Record(Annotations.ServerRecv());
                trace.Record(Annotations.ServiceName(_serviceName));
                trace.Record(Annotations.Event("TODO"));
                try
                {
                    await handler(message, handlerToken);
                    trace.Record(Annotations.ServerSend());
                }
                catch (Exception ex)
                {
                    trace.Record(Annotations.Tag("error", ex.Message));
                    trace.Record(Annotations.LocalOperationStop());

                    throw;
                }
            },
                       execution,
                       mode,
                       cancellationToken));
        }
Beispiel #3
0
 public void FactoryReturnsCorrectTypes()
 {
     Assert.IsInstanceOf <TagAnnotation>(Annotations.Tag("", ""));
     Assert.IsInstanceOf <ClientRecv>(Annotations.ClientRecv());
     Assert.IsInstanceOf <ClientSend>(Annotations.ClientSend());
     Assert.IsInstanceOf <LocalAddr>(Annotations.LocalAddr(null));
     Assert.IsInstanceOf <Rpc>(Annotations.Rpc(""));
     Assert.IsInstanceOf <ServerRecv>(Annotations.ServerRecv());
     Assert.IsInstanceOf <ServerSend>(Annotations.ServerSend());
     Assert.IsInstanceOf <ServiceName>(Annotations.ServiceName(""));
     Assert.IsInstanceOf <Event>(Annotations.Event(""));
     Assert.IsInstanceOf <ClientAddr>(Annotations.ClientAddr(null));
     Assert.IsInstanceOf <ServerAddr>(Annotations.ServerAddr(null, null));
 }
Beispiel #4
0
        public void ToStringWriteExtraDataInAdditionToType()
        {
            Assert.AreEqual("TagAnnotation: sampleTagKey:sampleTagValue", Annotations.Tag("sampleTagKey", "sampleTagValue").ToString());
            Assert.AreEqual("Rpc: GET", Annotations.Rpc("GET").ToString());
            Assert.AreEqual("ServiceName: sampleName", Annotations.ServiceName("sampleName").ToString());
            Assert.AreEqual("Event: sampleName", Annotations.Event("sampleName").ToString());
            Assert.AreEqual("LocalOperationStart: sampleName", Annotations.LocalOperationStart("sampleName").ToString());

            var samIpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80);

            Assert.AreEqual("ClientAddr: 127.0.0.1:80", Annotations.ClientAddr(samIpEndPoint).ToString());
            Assert.AreEqual("ServerAddr: sampleName/127.0.0.1:80", Annotations.ServerAddr("sampleName", samIpEndPoint).ToString());
            Assert.AreEqual("MessageAddr: sampleName/127.0.0.1:80", Annotations.MessageAddr("sampleName", samIpEndPoint).ToString());
        }
Beispiel #5
0
 public void FactoryReturnsCorrectTypes()
 {
     Assert.IsInstanceOf <TagAnnotation>(Annotations.Tag("", ""));
     Assert.IsInstanceOf <ClientRecv>(Annotations.ClientRecv());
     Assert.IsInstanceOf <ClientSend>(Annotations.ClientSend());
     Assert.IsInstanceOf <LocalAddr>(Annotations.LocalAddr(null));
     Assert.IsInstanceOf <Rpc>(Annotations.Rpc(""));
     Assert.IsInstanceOf <ServerRecv>(Annotations.ServerRecv());
     Assert.IsInstanceOf <ServerSend>(Annotations.ServerSend());
     Assert.IsInstanceOf <ServiceName>(Annotations.ServiceName(""));
     Assert.IsInstanceOf <Event>(Annotations.Event(""));
     Assert.IsInstanceOf <ClientAddr>(Annotations.ClientAddr(null));
     Assert.IsInstanceOf <ServerAddr>(Annotations.ServerAddr(null, null));
     Assert.IsInstanceOf <MessageAddr>(Annotations.MessageAddr(null, null));
     Assert.IsInstanceOf <ConsumerStart>(Annotations.ConsumerStart());
     Assert.IsInstanceOf <ConsumerStop>(Annotations.ConsumerStop());
     Assert.IsInstanceOf <ProducerStart>(Annotations.ProducerStart());
     Assert.IsInstanceOf <ProducerStop>(Annotations.ProducerStop());
     Assert.IsInstanceOf <LocalOperationStart>(Annotations.LocalOperationStart(""));
     Assert.IsInstanceOf <LocalOperationStop>(Annotations.LocalOperationStop());
 }
Beispiel #6
0
        public async Task SendAsync(Message message, CancellationToken cancellationToken = default)
        {
            var trace = Trace.Current.Child();

            var newMessage = InjectTracing(message, trace);

            trace.Record(Annotations.ClientSend());
            trace.Record(Annotations.ServiceName(_serviceName));
            trace.Record(Annotations.Event("TODO"));
            try
            {
                await _sender.SendAsync(newMessage, cancellationToken);

                trace.Record(Annotations.ClientRecv());
            }
            catch (Exception ex)
            {
                trace.Record(Annotations.Tag("error", ex.Message));
                trace.Record(Annotations.LocalOperationStop());

                throw;
            }
        }
        public async Task <IActionResult> GetById(int id)
        {
            var trace = Trace.Current;

            //trace.Record(Annotations.ServerRecv());
//            trace.Record(Annotations.ServiceName(nameof(CustomersController)));
            //trace.Record(Annotations.Rpc("GET"));
            //trace.Record(Annotations.ServerSend());
            trace.Record(Annotations.Tag("Actions", "Customers.GetById"));
            trace.Record(Annotations.Event("GetById.BeforeDB"), DateTime.Now);

            var customerEntity = await _customerRepository
                                 .GetCustomerById(id)
                                 .ConfigureAwait(false);

            trace.Record(Annotations.Event("GetById.AfterDB"), DateTime.Now);

            if (customerEntity == null)
            {
                return(NotFound(new OperationStatus($"Customer {id} not found")));
            }

            trace.Record(Annotations.Event("GetById.BeforeMapping"), DateTime.Now);

            var customer = new Customer
            {
                Id        = customerEntity.Id,
                FirstName = customerEntity.FirstName,
                LastName  = customerEntity.LastName,
                Email     = customerEntity.Email
            };

            trace.Record(Annotations.Event("GetById.AfterMapping"), DateTime.Now);

            return(Ok(customer));
        }
Beispiel #8
0
 public ISpan Log(DateTimeOffset timestamp, string @event)
 {
     Trace.Record(Annotations.Event(@event), timestamp.UtcDateTime);
     return(this);
 }
Beispiel #9
0
 public ISpan Log(string @event)
 {
     Trace.Record(Annotations.Event(@event));
     return(this);
 }
Beispiel #10
0
 public ISpan Log(DateTimeOffset timestamp, IDictionary <string, object> fields)
 {
     Trace.Record(Annotations.Event(JoinKeyValuePairs(fields)), timestamp.UtcDateTime);
     return(this);
 }
Beispiel #11
0
 public ISpan Log(IDictionary <string, object> fields)
 {
     Trace.Record(Annotations.Event(JoinKeyValuePairs(fields)));
     return(this);
 }