public int Silence(int depth)
 {
     if (depth > 1)
     {
         AppServerUtility.MakeRequest((IReportService proxy) => proxy.Silence(depth - 1));
     }
     return(depth);
 }
 public int Noise(int depth)
 {
     if (depth > 1)
     {
         using (_tracer.BuildSpan($"Server.Noise[{depth}]").StartActive(true))
         {
             AppServerUtility.MakeRequest((IReportService proxy) => proxy.Noise(depth - 1));
         }
     }
     return(depth);
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var tracer = Common.Jaeger.Creator.GetLogger();

            GlobalTracer.Register(tracer);

            Console.WriteLine("Client started.");
            Console.WriteLine("Press any key to start requests . . .");
            Console.ReadKey();
            Console.WriteLine("Client sending requests.");

            if (true)
            {
                AppServerUtility.MakeRequest((IReportService proxy) => proxy.Touch());
                using (tracer.BuildSpan("Client.Touch").StartActive(true))
                {
                    AppServerUtility.MakeRequest((IReportService proxy) => proxy.Touch());
                }

                AppServerUtility.MakeRequest((IReportService proxy) => proxy.Silence(7));
                using (tracer.BuildSpan("Client.Noise").StartActive(true))
                {
                    AppServerUtility.MakeRequest((IReportService proxy) => proxy.Noise(11));
                }
            }

            if (true)
            {
                using (tracer.BuildSpan("ThrowsCLRException").StartActive(true))
                {
                    try
                    {
                        AppServerUtility.MakeRequest((IThrowsService proxy) =>
                                                     proxy.ThrowsCLRException());
                    }
                    catch (FaultException)
                    {
                        /* ignore */
                    }
                }

                using (tracer.BuildSpan("ThrowsCLRExceptionOneWay").StartActive(true))
                {
                    try
                    {
                        AppServerUtility.MakeRequest((IThrowsService proxy) =>
                                                     proxy.ThrowsCLRExceptionOneWay());
                    }
                    catch (FaultException)
                    {
                        /* ignore */
                    }
                }

                using (tracer.BuildSpan("ThrowsFaultException").StartActive(true))
                {
                    try
                    {
                        AppServerUtility.MakeRequest((IThrowsService proxy) =>
                                                     proxy.ThrowsFaultException());
                    }
                    catch (FaultException)
                    {
                        /* ignore */
                    }
                }

                using (tracer.BuildSpan("ThrowsFaultExceptionOneWay").StartActive(true))
                {
                    try
                    {
                        AppServerUtility.MakeRequest((IThrowsService proxy) =>
                                                     proxy.ThrowsFaultExceptionOneWay());
                    }
                    catch (FaultException)
                    {
                        /* ignore */
                    }
                }

                using (tracer.BuildSpan("ThrowsTypedCLRFaultException").StartActive(true))
                {
                    try
                    {
                        AppServerUtility.MakeRequest((IThrowsService proxy) =>
                                                     proxy.ThrowsTypedCLRFaultException());
                    }
                    catch (FaultException)
                    {
                        /* ignore */
                    }
                }

                using (tracer.BuildSpan("ThrowsTypedCustomFaultException").StartActive(true))
                {
                    try
                    {
                        AppServerUtility.MakeRequest((IThrowsService proxy) =>
                                                     proxy.ThrowsTypedCustomFaultException());
                    }
                    catch (FaultException)
                    {
                        /* ignore */
                    }
                }
            }

            if (true)
            {
                var       traceId  = Guid.NewGuid().ToString("N");
                const int reportId = 2209619;

                var scope = tracer.BuildSpan($"Client.Export(reportId={reportId})").StartActive(true);
                scope.Span.SetBaggageItem(Common.Objects.Constants.TRACE_ID, traceId);

                var token = default(string);
                using (var inner = tracer.BuildSpan("Client.AddTask").AsChildOf(scope.Span.Context).StartActive(true))
                {
                    token = AppServerUtility.MakeRequest((IExportService proxy) => proxy.AddTask(reportId));

                    if (!$"{traceId}-{reportId}".Equals(token))
                    {
                        inner.Span.Log("Not supported 'token'");
                        Tags.Error.Set(inner.Span, true);

                        throw new ApplicationException("Not supported 'token'");
                    }
                }

                using (var inner = tracer.BuildSpan("Client.WaitFile").AsChildOf(scope.Span.Context).StartActive(true))
                {
                    var file = default(object);
                    do
                    {
                        Thread.Sleep(1000);
                        file = AppServerUtility.MakeRequest((IExportService proxy) => proxy.GetFile(token));
                    } while (file == null);

                    if (!$"{file}".Equals($"{token}.docx"))
                    {
                        inner.Span.Log("Not supported 'file'");
                        Tags.Error.Set(inner.Span, true);

                        throw new ApplicationException("Not supported 'file'");
                    }
                }

                scope.Span.Finish();
            }

            Console.WriteLine("Press any key to continue . . .");
            Console.ReadKey();
        }
        public string AddTask(int reportId)
        {
            using (var scope = _tracer.BuildSpan("Server.AddTask").StartActive(true))
            {
                var traceId = scope.Span.GetBaggageItem(Common.Objects.Constants.TRACE_ID);
                if (string.IsNullOrEmpty(traceId))
                {
                    throw new ApplicationException("Not found 'traceId'");
                }

                var token = $"{traceId}-{reportId}";

                var ctx = new SpanContext(scope.Span.Context);
                if (!_rmq.TryAdd(token, ctx.SerializeObject()))
                {
                    throw new ApplicationException("Failed to add 'task'");
                }

                Task.Factory.StartNew(() =>
                {
                    if (!_rmq.TryGetValue(token, out var context))
                    {
                        throw new ApplicationException("Not found 'parentSpanCtx'");
                    }
                    var parentSpanCtx = context.DeserializeToObject <SpanContext>();

                    using (var inner = _tracer.BuildSpan("Server.TaskProcess").AsChildOf(parentSpanCtx).StartActive(true))
                    {
                        var innerTraceId = inner.Span.GetBaggageItem(Common.Objects.Constants.TRACE_ID);
                        if (string.IsNullOrEmpty(innerTraceId))
                        {
                            throw new ApplicationException("Not found 'innerTraceId'");
                        }

                        foreach (var id in Enumerable.Range(0, 5).Select(_ => Guid.NewGuid()))
                        {
                            AppServerUtility.MakeRequest((IExportService proxy) => proxy.GetInfo(id));
                        }

                        foreach (var uid in Enumerable.Range(0, 5).Select(_ => Guid.NewGuid()))
                        {
                            AppServerUtility.MakeRequest((IImageService proxy) => proxy.GetImage(uid));
                        }

                        using (_tracer.BuildSpan("Server.SomeLongActions").StartActive(true))
                        {
                            Thread.Sleep(2500);
                        }

                        if (!_db.TryAdd(token, $"{token}.docx"))
                        {
                            throw new ApplicationException("Failed to add 'file'");
                        }
                    }
                });

                using (_tracer.BuildSpan("Server.SomeActions").StartActive(true))
                {
                    Thread.Sleep(500);
                }

                return(token);
            }
        }