示例#1
0
        internal static object Run(string projectId)
        {
            var spanExporter = new StackdriverTraceExporter(projectId);

            var metricExporter = new StackdriverMetricExporter(
                projectId,
                Stats.ViewManager);

            metricExporter.Start();

            var tracerFactory = new TracerFactory(new BatchingSpanProcessor(spanExporter));
            var tracer        = tracerFactory.GetTracer(string.Empty);

            var tagContextBuilder = Tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5"));

            var spanBuilder = tracer
                              .SpanBuilder("incoming request")
                              .SetRecordEvents(true)
                              .SetSampler(Samplers.AlwaysSample);

            Stats.ViewManager.RegisterView(VideoSizeView);

            using (tagContextBuilder.BuildScoped())
            {
                using (tracer.WithSpan(spanBuilder.StartSpan()))
                {
                    tracer.CurrentSpan.AddEvent("Processing video.");
                    Thread.Sleep(TimeSpan.FromMilliseconds(10));

                    StatsRecorder.NewMeasureMap()
                    .Put(VideoSize, 25 * MiB)
                    .Record();
                }
            }

            Thread.Sleep(TimeSpan.FromMilliseconds(5100));

            var viewData = Stats.ViewManager.GetView(VideoSizeViewName);

            Console.WriteLine(viewData);

            Console.WriteLine("Done... wait for events to arrive to backend!");
            Console.ReadLine();

            spanExporter.ShutdownAsync(CancellationToken.None).GetAwaiter().GetResult();
            metricExporter.Stop();
            return(null);
        }
        internal static object Run(string projectId)
        {
            var spanExporter = new StackdriverTraceExporter(projectId);

            var metricExporter = new StackdriverMetricExporter(
                projectId,
                Stats.ViewManager);

            metricExporter.Start();

            using (var tracerFactory = TracerFactory.Create(builder => builder.SetExporter(spanExporter)))
            {
                var tracer = tracerFactory.GetTracer("stackdriver-test");

                var tagContextBuilder = Tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5"));

                Stats.ViewManager.RegisterView(VideoSizeView);

                using (tagContextBuilder.BuildScoped())
                {
                    using (tracer.WithSpan(tracer.StartSpan("incoming request")))
                    {
                        tracer.CurrentSpan.AddEvent("Processing video.");
                        Thread.Sleep(TimeSpan.FromMilliseconds(10));

                        StatsRecorder.NewMeasureMap()
                        .Put(VideoSize, 25 * MiB)
                        .Record();
                    }
                }

                Thread.Sleep(TimeSpan.FromMilliseconds(5100));

                var viewData = Stats.ViewManager.GetView(VideoSizeViewName);

                Console.WriteLine(viewData);

                Console.WriteLine("Done... wait for events to arrive to backend!");
                Console.ReadLine();

                metricExporter.Stop();
                return(null);
            }
        }