예제 #1
0
        internal void GivenOcelotIsRunningUsingOpenTracing(OpenTracing.ITracer fakeTracer)
        {
            _webHostBuilder = new WebHostBuilder();

            _webHostBuilder
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath);
                var env = hostingContext.HostingEnvironment;
                config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false);
                config.AddJsonFile("ocelot.json", optional: true, reloadOnChange: false);
                config.AddEnvironmentVariables();
            })
            .ConfigureServices(s =>
            {
                s.AddOcelot()
                .AddOpenTracing();

                s.AddSingleton <OpenTracing.ITracer>(fakeTracer);
            })
            .Configure(app =>
            {
                app.Use(async(_, next) =>
                {
                    await next.Invoke();
                });
                app.UseOcelot().Wait();
            });

            _ocelotServer = new TestServer(_webHostBuilder);

            _ocelotClient = _ocelotServer.CreateClient();
        }
예제 #2
0
 public CancelOrderHandler(IBusPublisher publisher, IXchangeCommands orderClient, ITracer tracer, ILogger <CancelOrderHandler> log)
 {
     _tracer       = tracer;
     _orderClient  = orderClient;
     _busPublisher = publisher;
     _logger       = log;
 }
예제 #3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            OpenTracing.ITracer tracer = SignalFxTracer;
            using var scope = tracer.BuildSpan("HttpTrigger").StartActive();

            string name = req.Query["name"];

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            name ??= data?.name;

            scope.Span.SetTag("span.kind", "server");
            scope.Span.SetTag("query.name", name ?? "<null>");
            scope.Span.SetTag("http.method", req.Method);

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            ObjectResult result = null;

            try
            {
                if (name == "crash")
                {
                    // The SampleServer is not running, this will fail and will create a span if the
                    // error information.
                    var samplerServerUrl = $"http://localhost:19999{SampleServer.RequestPath}/";
                    var client           = new SampleClientLibrary(samplerServerUrl);
                    responseMessage = await client.RequestAsync(responseMessage, CancellationToken.None);
                }

                result = new OkObjectResult(responseMessage);
            }
            catch (Exception e)
            {
                result = new ExceptionResult(e, includeErrorDetail: true);
                scope.Span.SetTag("error.message", e.Message);
                throw;
            }
            finally
            {
                scope.Span.SetTag("http.status_code", result?.StatusCode ?? 500);
                scope.Span.SetTag("error", true);
            }

            return(result);
        }
예제 #4
0
 public Server(String address, ImageSelection selection, String imagesBaseURL,
               int frameRate, ILogger <Server> logger, OpenTracing.ITracer tracer)
 {
     this.frameRate       = frameRate;
     this.imagesBaseURL   = imagesBaseURL;
     this.address         = address;
     this.webSocketServer = new WebSocketServer(this.address);
     this.allSockets      = new List <IWebSocketConnection>();
     this.selection       = selection;
     this.allImages       = getSelectedImageList(selection, imagesBaseURL);
     this.source          = new CancellationTokenSource();
     this.token           = source.Token;
     this._logger         = logger;
     this._tracer         = tracer;
 }
예제 #5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            OpenTracing.ITracer tracer = SignalFxTracer;
            log.LogInformation($" tracer= {tracer.ToString()}");

            var startTime = DateTimeOffset.Now;

            var headerDictionary = new Dictionary <string, string>();
            var headerKeys       = req.Headers.Keys;

            foreach (var headerKey in headerKeys)
            {
                string headerValue = req.Headers[headerKey];

                log.LogInformation($" header: {headerKey} ,  {headerValue}");
                headerDictionary.Add(headerKey, headerValue);
            }


            OpenTracing.ISpanBuilder spanBuilder = tracer.BuildSpan($"{req.Method} {req.HttpContext.Request.Path}");
            var requestContext = tracer.Extract(BuiltinFormats.HttpHeaders, new TextMapExtractAdapter(headerDictionary));

            log.LogInformation(requestContext.ToString());
            using var scope = spanBuilder
                              .AsChildOf(requestContext)
                              .WithStartTimestamp(startTime)
                              .WithTag("span.kind", "server")
                              .StartActive();

            string name = req.Query["name"];

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            name ??= data?.name;

            log.LogInformation("C# HTTP trigger function processed a request.");

            scope.Span.SetTag("query.name", name ?? "<null>");

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            ObjectResult result = null;

            try
            {
                if (name == "crash")
                {
                    throw new ArgumentException("CRASHED, 'crash' is invalid arg!");
                }

                result = new OkObjectResult(responseMessage);
            }
            catch (Exception e)
            {
                result = new ExceptionResult(e, includeErrorDetail: true);
                scope.Span.SetTag("error.message", e.Message);
                throw;
            }
            finally
            {
                scope.Span.SetTag("http.status_code", result?.StatusCode ?? 500);
                scope.Span.SetTag("error", true);
            }

            scope.Span.Finish();
            return(result);
        }
예제 #6
0
 public JaegerTracer(IServiceProvider services)
 {
     _tracer = services.GetService <IJaegerServiceTracer>();
 }
 public WebSocketConnection(IConnectionDataHandler socketMessageHandler,
                            Types.XchangeDescriptor exchangeDescriptor,
                            ISignRequestsService signService,
                            OpenTracing.ITracer tracer,
                            ILogger <WebSocketConnection> logger,
                            (string, string)[] subscriptionTags = null,