Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

A simple C# library for instrumentation of SQS messages with OpenTracing

License

Notifications You must be signed in to change notification settings

juniortads/opentracing-sqs-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenTracing Badge Build status NuGet License

opentracing-sqs-csharp

A simple C# library for instrumentation of SQS messages with OpenTracing.

Dependencies

  • NET Core 3.1
  • AWSSDK.SQS 3.3.102.54
  • OpenTracing

Installation

Install the NuGet package:

> dotnet add package EventBus.Sqs

> dotnet add package EventBus.Sqs.Tracing

Getting started

Before, in your application's Startup.cs file, configure OpenTracing first.

using OpenTracing.Util;
...
services.AddSingleton(serviceProvider =>
{
    var loggerFactory = new LoggerFactory();

    var config = Jaeger.Configuration.FromEnv(loggerFactory);
    var tracer = config.GetTracer();

    if (!GlobalTracer.IsRegistered())
        GlobalTracer.Register(tracer);

    return tracer;
});

Check this link for more information about Jaeger configuration via environment.

https://github.com/jaegertracing/jaeger-client-csharp

Next, configure EventBus.Sqs with tracing:

using EventBus.Sqs.Configuration;
using EventBus.Sqs.Tracing.Configuration;
...
services.AddEventBusSQS(Configuration)
        .AddOpenTracing();

Configure health checks for SQS

services.AddHealthChecks()
        .AddSqsCheck<HereAddYourIntegrationEvent>();

Finally, We can using in your application's Controller.cs file, Check below this example:

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    private readonly IEventBus eventBus;
    public WeatherForecastController(IEventBus eventBus)
    {
        this.eventBus = eventBus;
    }

    [HttpPost]
    public async Task<ActionResult> Create()
    {
        var rng = new Random();
        //Create sample Integration Event
        var weatherInEvent = new WeatherInEvent(Guid.NewGuid().ToString(), "Freezing");

        await eventBus.Enqueue(weatherInEvent);

        return Accepted();
    }
}

Don't forget, Creating your Integration event:

public class WeatherInEvent : IntegrationEvent
{
    public string WeatherEventId { get; set; }
    public string Summary { get; set; }

    public WeatherInEvent(string id, string summary) : base(id, DateTime.UtcNow)
    {
        WeatherEventId = id;
        Summary = summary;
    }
}

More examples:

Link

Tracing

Contact

These email addresses serve as the main contact addresses for this project.

Bug reports and feature requests are more likely to be addressed if posted as issues here on GitHub.

License

This project is licensed under the terms of the MIT license, see also the full LICENSE.

MIT License

Copyright (c) 2020 Joel Junior

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A simple C# library for instrumentation of SQS messages with OpenTracing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages