Code Monkey home page Code Monkey logo

simpletracer's Introduction

SimpleTracer

SimpleTracer

Simplest way to listen and collect events for .Net/.Net Core applications.!

Build Test Coverage Nuget
Build Status Azure DevOps tests Azure DevOps coverage Nuget

If you have an application that you need to listen some events, you should implement the followings which is fairly painful;

  • Create a class that inherits from EventListener
  • Call EnableEvents(...) method for every source and try to eliminate the concurrency problem
  • To listen multiple different sources, be familiar with bitwise operations

Here we go! OnEventWritten(...) method will be triggered for every written events and you should concern;

  • Concurrency because events might be written from different threads
  • Buffering because events count per specific time might be more than you can handle this.
  • Separation because you wouldn't like to handle every event in same way

SimpleTracer addresses many of the common concern to provide fault tolerant, thread safe and TPL friendly solution.

Simplest way to collect Garbage Collection events, ever!

You can configure how often and which method will be triggered by calling WithInterval and WithDelegate methods. Also WithMaxTake could be handy to set event limit for each trigger.

var builder = SubscriptionContainerBuilder
    .New()
    .WithSubscription(s => s
        .WithEvents(e => e.DotNetRuntime.GC.AllInformationals())
        .WithExecution(e => e
            .WithInterval(TimeSpan.FromSeconds(30))
            .WithDelegate(OnEventsCollected)
            .WithMaxTake(300)));

var container = builder.Build();
container.Start();

You could store it wherever you want

SimpleTracer supports awaitable methods. Every execution occurs in a Task which was dedicated per Subscription for your workload!

private static Task OnEventsCollected(IEventNotification arg)
{
    foreach (IEventEntry item in arg.Events)
        Console.WriteLine($"{item.CreatedOn}\t{item.Id} : {item.Name}");

    return Task.CompletedTask;
}

Multiple EventSource in one Subscription

You don't have to create different subscriptions for every EventSource. One subscription can listen multiple EventSource with various EventLevel and EventKeywords.

 var builder = SubscriptionContainerBuilder
     .New()
     .WithSubscription(s => s
         .WithEvents(e => e.DotNetRuntime.GC.AllInformationals())
         .WithEvents(e => e.SystemNetHttp.AllWarnings())
         .WithEvents(new SourceDefinition("Custom-Event-Source", EventLevel.Error, EventKeywords.All))
         .WithExecution(e => e
             .WithInterval(TimeSpan.FromSeconds(3))
             .WithDelegate(OnEventsCollected)
             .WithMaxTake(300))
         .WithOptions());

var container = builder.Build();
container.Start();

Don't want to involve too much details?

You can create a Subscription to listen all of EventSource objects with EventLevel filter. It gives you to a massive insight about your application but also more than a thousand events to be queued.

Don't worry! By calling WithQueueCapacity, it is possible to limit to be enqueued event count.

var builder = SubscriptionContainerBuilder
    .New()
    .WithSubscription(EventLevel.Error, c => c
         .WithExecution(e => e
            .WithInterval(TimeSpan.FromSeconds(3))
            .WithDelegate(OnEventsCollected)
            .WithMaxTake(300))
        .WithOptions(o => o
            .WithQueueCapacity(3000)));

var container = builder.Build();
container.Start();

simpletracer's People

Contributors

btungut avatar

Watchers

James Cloos avatar

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.