Ejemplo n.º 1
0
        public void Event(HttpContext httpContext, string @event)
        {
            // todo - if the user isnt using tracing the code gets here and will blow up on
            // _tracer.Tracer.TryExtract..
            if (_tracer == null)
            {
                return;
            }

            var span = httpContext.GetSpan();

            if (span == null)
            {
                var spanBuilder = _tracer.BuildSpan($"server {httpContext.Request.Method} {httpContext.Request.Path}");
                if (_tracer.TryExtract(out var spanContext, httpContext.Request.Headers, (c, k) => c[k].GetValue(),
                                       c => c.Select(x => new KeyValuePair <string, string>(x.Key, x.Value.GetValue())).GetEnumerator()))
                {
                    spanBuilder.AsChildOf(spanContext);
                }

                span = _tracer.Start(spanBuilder);
                httpContext.SetSpan(span);
            }

            span?.Log(new LogData().Event(@event));
        }
Ejemplo n.º 2
0
 /*
  * handleOnMassage() handles userinput and acts accordingly
  */
 public void handleOnMassage(IWebSocketConnection socket, String message)
 {
     using (var scope = _tracer.BuildSpan("handleOnMassage").StartActive(true))
     {
         _logger.LogInformation("Function: handleOnMassage(" + message + ")");
         if (message.Equals("exit"))
         {
             socket.Close();
         }
         else if (message.Equals("earth"))
         {
             this.selection       = ImageSelection.Earth;
             this.selectNewImages = true;
         }
         else if (message.Equals("yoda"))
         {
             this.selection       = ImageSelection.Yoda;
             this.selectNewImages = true;
         }
         else if (message.Equals("babyyoda"))
         {
             this.selection       = ImageSelection.BabyYoda;
             this.selectNewImages = true;
         }
         if (this.selectNewImages)
         {
             this.allImages = getSelectedImageList(this.selection, this.imagesBaseURL);
             if (sendImage != null)
             {
                 this.sendImage.Wait();
                 this.taskCompleted = this.sendImage.IsCompleted;
             }
             this.selectNewImages = false;
             this.sendImage       = Task.Factory.StartNew(this.createSendDelayedFramesAction(), CancellationToken.None, TaskCreationOptions.DenyChildAttach,
                                                          TaskScheduler.Default);
         }
         scope.Span.Log(new Dictionary <string, object>
         {
             [OpenTracing.LogFields.Event] = "ImageSelection",
             ["value"] = selection
         });
         Console.WriteLine(message);
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
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);
        }