Exemple #1
0
    static void Main()
    {
        string writeKey = "abcabc123123defdef456456";
        string dataSet  = "factorial";

        var honey = new LibHoney(writeKey, dataSet);

        Task.Run(() => ReadResponses(honey.Responses));

        // Attach fields to the top-level instance.
        honey.AddField("version", "3.4.5");
        honey.AddDynamicField("num_threads", () => Process.GetCurrentProcess().Threads.Count);

        // Sends an event with "version", "num_threads", and "status" fields.
        honey.SendNow("status", "starting run");

        RunFact(1, 2, new Builder(honey, new Dictionary <string, object> ()
        {
            ["range"] = "low"
        }));
        RunFact(31, 32, new Builder(honey, new Dictionary <string, object> ()
        {
            ["range"] = "high"
        }));

        honey.SendNow("status", "sending now");
        honey.Close();
    }
Exemple #2
0
        public void SendNowClosed()
        {
            var libHoney = new LibHoney("key1", "HelloHoney", 1);

            libHoney.Close();

            bool excThrown = false;

            try { libHoney.SendNow(new Dictionary <string, object> ()); } catch (SendException) { excThrown = true; }
            Assert.True(excThrown);

            excThrown = false;
            try { libHoney.SendNow("name", "value"); } catch (SendException) { excThrown = true; }
            Assert.True(excThrown);
        }
Exemple #3
0
    static void Main()
    {
        string writeKey = "abcabc123123defdef456456";
        string dataSet  = "event_values";

        var honey = new LibHoney(writeKey, dataSet);
        var rand  = new Random();

        // Send 3 events with a random number.
        for (int i = 0; i < 10; i++)
        {
            honey.SendNow(new Dictionary <string, object> ()
            {
                ["counter"] = rand.Next(100),
            });
        }

        // Send an event with the same writeKey but different
        // dataSet.
        var ev = new Event(honey);

        ev.DataSet = "master_values";
        ev.AddField("latest_event", DateTime.Now.ToString("O"));
        ev.Send();

        // Close the client.
        honey.Close();
    }
Exemple #4
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            RelayNamespace = Configuration["RelayNamespace"];
            ConnectionName = Configuration["RelayConnectionName"];
            KeyName        = Configuration["RelayKeyName"];
            Key            = Configuration["RelayKey"];

            // Begin
            HttpClient client  = HttpClientFactory.Create();
            var        baseUri = new Uri(string.Format("https://{0}/{1}/", RelayNamespace, ConnectionName));
            var        request = new HttpRequestMessage()
            {
                RequestUri = new Uri(baseUri, "status"),
                Method     = HttpMethod.Get
            };

            await AddAuthToken(request);

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var response = await client.SendAsync(request);

            stopWatch.Stop();

            _libHoney.SendNow(new Dictionary <string, object> ()
            {
                ["name"]         = "status",
                ["service_name"] = "GetStatus",
                ["duration_ms"]  = stopWatch.ElapsedMilliseconds,
                ["method"]       = "get",
                ["status_code"]  = response.StatusCode,
                ["azFunction"]   = "GetStatus",
                ["endpoint"]     = baseUri + "status",
            });

            if (response.IsSuccessStatusCode)
            {
                string payload = await response.Content.ReadAsStringAsync();

                return(new OkObjectResult(payload));
            }
            else
            {
                return(new BadRequestObjectResult(response.ReasonPhrase));
            }
        }
Exemple #5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "temps/{traceid?}/{parentspanid?}")] HttpRequest req,
            ILogger log, string?traceid, string?parentspanid)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            var spanId = Guid.NewGuid().ToString();

            RelayNamespace = Configuration["RelayNamespace"];
            ConnectionName = Configuration["RelayConnectionName"];
            KeyName        = Configuration["RelayKeyName"];
            Key            = Configuration["RelayKey"];
            var baseUri = new Uri(string.Format("https://{0}/{1}/", RelayNamespace, ConnectionName));

            HttpResponseMessage response;
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            response = await SendRelayRequest(baseUri, "temps", HttpMethod.Get, "");

            stopWatch.Stop();

            _libHoney.SendNow(new Dictionary <string, object> ()
            {
                ["name"]            = "temps",
                ["service_name"]    = "GetTemps",
                ["trace_id"]        = traceid,
                ["trace.span_id"]   = spanId,
                ["trace.parent_id"] = parentspanid,
                ["duration_ms"]     = stopWatch.ElapsedMilliseconds,
                ["method"]          = "get",
                ["status_code"]     = response.StatusCode,
                ["azFunction"]      = "GetTemps",
                ["endpoint"]        = baseUri + "temps",
            });

            if (response.IsSuccessStatusCode)
            {
                log.LogInformation("response.IsSuccessStatusCode PASSED");
                string payload = await response.Content.ReadAsStringAsync();

                return(new OkObjectResult(payload));
            }
            else
            {
                log.LogInformation("response.IsSuccessStatusCode FAILED");
                return(new BadRequestObjectResult(response.ReasonPhrase));
            }
        }
Exemple #6
0
        void LogRequest(DateTime startTimeUtc, RelayedHttpListenerContext context)
        {
            DateTime stopTimeUtc = DateTime.UtcNow;

            _libHoney.SendNow(new Dictionary <string, object> ()
            {
                ["name"]         = "HybridConnectionReverseProxy",
                ["service_name"] = "HybridConnectionReverseProxy",
                ["duration_ms"]  = (int)stopTimeUtc.Subtract(startTimeUtc).TotalMilliseconds,
                ["method"]       = context.Request.HttpMethod,
                ["status_code"]  = $"{(int)context.Response.StatusCode}",
                ["azFunction"]   = "GetTemps",
                ["endpoint"]     = $"\"{context.Request.Url.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped)}\"",
            });
            StringBuilder buffer = new StringBuilder();

            buffer.Append($"{startTimeUtc.ToString("s", CultureInfo.InvariantCulture)}, ");
            buffer.Append($"\"{context.Request.HttpMethod} {context.Request.Url.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped)}\", ");
            buffer.Append($"{(int)context.Response.StatusCode}, ");
            buffer.Append($"{(int)stopTimeUtc.Subtract(startTimeUtc).TotalMilliseconds}");
            Console.WriteLine(buffer);
        }
Exemple #7
0
    static void Main()
    {
        string writeKey = "abcabc123123defdef456456";
        string dataSet  = "simple";

        var honey = new LibHoney(writeKey, dataSet);
        var rand  = new Random();

        // Send 10 events with a random number.
        for (int i = 0; i < 10; i++)
        {
            honey.SendNow(new Dictionary <string, object> ()
            {
                ["message"] = "Diagnostic #" + i,
                ["counter"] = rand.Next(100),
            });

            Thread.Sleep(TimeSpan.FromMilliseconds(100));
        }

        // Close the client.
        honey.Close();
    }