Code Monkey home page Code Monkey logo

honeycombserilogsink's Introduction

Honeycomb Serilog sink

Build Status Nuget Azure DevOps coverage

[BuildHistory]

This project aims to provide a Serilog sink to push structured log events to the Honeycomb platform for observability and monitoring purposes.

By hooking up to serilog the goal is to allow all existing applications which already produce structured events for logging to easily include Honeycomb as part of their pipeline.

This library will add an enricher that adds information about the ongoing Activity/Span.The moment the log message's created. This adds a trace.trace_id property that matches the activities TraceId and a trace.parent_id property which matches the SpanId of the activity to each log event. Every event will be tagged with meta.annotation_type=span_event in Honeycomb and you'll be able to see them when reviewing a trace.

Setup

To start using this sink simply download the package from Nuget and add it to your Serilog configuration as another sink in the pipeline.

Parameters

Mandatory

  • dataset: The name of the dataset to send the log messages to.
  • api key: An API key with Send Events permissions on the dataset.

Optional

  • httpClientFactory: a factory which will provide an instance of HttpClient. When passed it's the responsability of the caller to manage the lifecycle of the client.
  • honeycombUrl: the url to the honeycomb Events API, change it if you want to test or if using Refinery. It defaults to https://api.honeycomb.io
  • Batching Option:
    • batchSizeLimit: The maximum number of log events to send in a batch. Defaults to 1000.
    • period: The maximum amount of time before flushing the events. Defaults to 2 seconds. If you see issues with memory utilization troubleshoot the batching options, too big a batch size limmit might result in a lot of memory being used, too low numbers may result in too frequent calls to the API.

Download the package

 dotnet add package Honeycomb.Serilog.Sink

Example

using Honeycomb.Serilog.Sink;

namespace Example
{
    public static class Program
    {
        public static int Main(string[] args)
        {
          Activity.DefaultIdFormat = ActivityIdFormat.W3C;
          Activity.ForceDefaultIdFormat = true;

          Log.Logger = new LoggerConfiguration()
                          .WriteTo.HoneycombSink(
                              teamId: dataset,
                              apiKey: apiKey)
                          .BuildLogger();

          // Do stuff
        }
    }
}

Using service provider

namespace Example
{
  public static class Program
  {
    public static int Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            .Enrich.FromLogContext()
            .WriteTo.Console()
            .CreateBootstrapLogger();

        try
        {
            Log.Information("Starting web host");
            CreateHostBuilder(args).Build().Run();
            return 0;
        }
        catch (Exception ex)
        {
            Log.Fatal(ex, "Host terminated unexpectedly");
            return 1;
        }
        finally
        {
            Log.CloseAndFlush();
        }
    }

    public static IHostBuilder CreateWebHostBuilder(string[] args)
    {
        return Host.CreateDefaultBuilder(args)
            .UseSerilog((_, services, configuration) =>
            {
                configuration.WriteTo.HoneycombSink(
                    teamId: <Dataset>,
                    apiKey: <Api Key>,
                    httpClientFactory: () =>
                        services.GetRequiredService<IHttpClientFactory>()
                                .CreateClient("honeycomb"));
            });
    }
  }
}

honeycombserilogsink's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar evilpilaf avatar frozenskys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ot-brett-bim

honeycombserilogsink's Issues

issues with empty string values for fields

Empty strings in Honeycomb can have unintended consequences. An empty string will not return true for "field" does not exist in a filter. This presents a problem with tracing data and .NET core 3.0 which automatically adds some tracing context to each entry.

.NET core adds a ParentID property, and will set the value to a blank string. This fields needs to be undefined and for tracing to work properly in Honecyomb. Can we add a check to only add properties that have a non-empty value before sending to Honeycomb?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.