Giter Club home page Giter Club logo

libhoney-dotnet's Introduction

libhoney-dotnet

OSS Lifecycle CircleCI

This package makes it easy to instrument your .NET app to send useful events to Honeycomb, a service for debugging your software in production.

Contributions

See DEVELOPMENT.md

Features, bug fixes and other changes to libhoney are gladly accepted. Please open issues or a pull request with your change.

All contributions will be released under the Apache License 2.0.

ASP.NET Core

Services Registration

    using Honeycomb.AspNetCore.Middleware;
    ...

    public void ConfigureServices(IServiceCollection services)
    {
    ...
        services.AddHoneycomb(Configuration);
    ...
    }

Middleware

Note the relative position to app.UseMvc()

    using Honeycomb.AspNetCore.Middleware;
    ...

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        ...
        app.UseHoneycomb();

        app.UseMvc();
        ...
    }

Configuration

Configuration can either be done through adding this to your appSettings.json

{
  "HoneycombSettings": {
    "WriteKey": "<your-writekey>",
    "DefaultDataSet": "<your-dataset>",
    "BatchSize": 100,
    "SendFrequency": 10000
  }
}

Then configure Libhoney using an instance of IConfiguration during ConfigureServices:

using Honeycomb.AspNetCore.Middleware;
...

public void ConfigureServices(IServiceCollection services)
{
    services.AddHoneycomb(Configuration);
}

Or alternatively, you can configure an instance of HoneycombApiSettings programmatically:

using Honeycomb.Models;
using Honeycomb.AspNetCore.Middleware;
...

public void ConfigureServices(IServiceCollection services)
{
    services.AddHoneycomb(options => {
        options.ApiHost = "https://api.honeycomb.io";
        options.WriteKey = "<your-writekey>";
        options.DefaultDataSet = "<your-dataset>";
        options.BatchSize = 100;
        options.SendFrequency = 10000;
    });
}

Usage

    public class HomeController : Controller
    {
        private readonly IHoneycombEventManager _eventManager;

        public HomeController(IHoneycombEventManager eventManager)
        {
            _eventManager = eventManager;
        }

        ...

        public IActionResult MyAction()
        {
            var stopWatch = new Stopwatch();
            stopWatch.Start();
            ...
            result = GetDataFromAPI();
            ...
            stopWatch.Stop();
            _eventManager.AddData("api_response_ms", stopWatch.ElapsedMilliseconds);

            return result;
        }
    }

Donation

This project was kindly donated to Honeycomb by @martinjt.

libhoney-dotnet's People

Contributors

adamchester-lmg avatar bdarfler avatar chrissmith avatar dependabot[bot] avatar ericsampson avatar jamiedanielson avatar joshclark avatar martin308 avatar martinjt avatar mikegoldsmith avatar pkanal avatar robbkidd avatar vreynolds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libhoney-dotnet's Issues

Support NetCoreApp 3.0 / .Net Core 3.0

Hi, do you have any plans to release a version compatible with .Net Core 3.0? If so when might we see it?

The SDK is now available with a go-live license which has prompted us to start investigating the upgrade process, currently, we cannot upgrade any application which reports to Honeycomb until this is done.

If it's not on your radar, I'll happily work up a pull request to enable this?

Default SendFrequency is probably wrong

The SendFrequency value is clearly milliseconds, looking at the examples and code using it, however, the default value is 60:

https://github.com/martinjt/honeycomb/blob/f7075175ed69f17741f5165d836ec1e35a49b54e/src/Honeycomb/Models/HoneycombApiSettings.cs#L27

I can't help but feel that 60ms is not what was intended here. I have a terminal with trace logging spamming messages:

trce: Microsoft.Extensions.Hosting.BackgroundService[0]
      Starting Flush
trce: Honeycomb.HoneycombService[0]
      Flushing honeycomb events
trce: Microsoft.Extensions.Hosting.BackgroundService[0]
      Delaying for 60
trce: Microsoft.Extensions.Hosting.BackgroundService[0]
      Starting Flush
trce: Honeycomb.HoneycombService[0]
      Flushing honeycomb events
trce: Microsoft.Extensions.Hosting.BackgroundService[0]
      Delaying for 60

Possible to make work on .net framework ?

Hi,

Great project. We have a few legacy applications which still use .net framework (4.7.2), and some dependencies prevent us from going up to .net core.

I can see how I can make the simple use case work with .net framewor by using the service directly, but doing it out of the bounds of the web request seems a bit more tricky. Happy to have a go a contributing something ( if worthwhile). Do you have any thoughts on how to do that? Send messages to a queue (e.g azure queue) and then have a function / webjob process them? Or am I over complicating it?

Thanks,

Lee

Example app is checked in CI

We want to have a useful working example in the repo. To make sure it doesn't get out of date, and to gain more confidence when merging PRs, the example should be exercised in CI.

.Net Core Hosted Service?

Does this support use in a .net Core Hosted service? If not, what kind of work would be required to use this for a .Net Core Hosted service (e.g. non-Http, or mix of Http and non-Http traffic)

HoneycombEventManager doesn't work in Hosted Services

Hi,

HoneycombEventManager has an AddData method that does not work in all use cases, notably hosted services. Hosted services are part of ASP.NET Core so I would expect some way to work with them, even if the middleware can't do this automatically.

The problem is the dependence on HttpContext - there's no ambient request for background services.

I'd like to propose some changes, and my time permitting I'd implement it myself.

First, and most simply, I'd like AddData to have some tolerance for HttpContext being null.

Second, I'd like to decouple the creation of a HoneycombEvent from the middleware. It will still be done there, but via an API that other services could use. Notionally this would be something like a new HoneycombEventScope(httpContext) that is IDisposable. Upon being disposed it would automatically add timing information and enqueue itself to be sent.

The important thing is other consumers could create their own scopes from things other than HTTP requests, so if you had a background service you could do something like new HoneycombEventScope(traceId).

Please note those are examples, it could be an IHoneycombEventManager or something once we get into the implementation.

If there's an appetite for these changes I can put together a pull request.

X-Honeycomb-Team not set

When giving an instance of HoneycombApiSettings in a ASP.NET core application, the X-Honeycomb-Team is not set in the HTTP header (inspected using Fiddler).

services.AddHoneycomb(new HoneycombApiSettings {
						TeamId = "xyz",
						DefaultDataSet = "abc",
						BatchSize = 1,
						SendFrequency = 5000,
				});

However, putting the settings in appsettings works:

services.AddHoneycomb(Configuration);

Allow different UserAgent headers per-event

As other client libraries will use this as a base library to manage communication, multiple events will come from different libraries, so there needs to be the ability for an event to override the default ProductInfoHeader

Unable to override the target of the HTTP Post

In order to use Honeycomb Secure Tenancy, events are supposed to be sent to a local proxy that then encrypts/hashes the event data before sending it on to the main Honeycomb servers.

The library does not allow a caller to configure this scenario.

Proposed solution:
We should add a new property to HoneycombApiSettings called ApiHost. It should default to https://api.honeycomb.io. We then need to change HoneycombService.SendSingleAsync() and HoneycombService.SendBatchAsync() to use this new property rather than being hard coded.

Update for E&S

Given a libhoney configured with a v2 api key and without a dataset
When it sends HNY events
Then it should use unknown_dataset as the dataset

When given a legacy key, the behavior remains the same as today.

Notes on trimming whitespace

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.