Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To incorporate Zipkin into an ASP.NET Core web API microservice with Docker to view RabbitMQ traces, you can follow the below steps:

Step 1: Create a Docker container for RabbitMQ: - Create a Dockerfile for RabbitMQ, install it in the container, and open the ports to communicate with Zipkin.

Step 2: Integrate Zipkin into asp.net core: - Add the following NuGet packages to your project: OpenTracing, OpenTracing.Contrib.NetCore, OpenTracing.Contrib.NetCore.Configuration, OpenTracing.Contrib.NetCore.CoreFx, Jaeger, Jaeger.Reporters.Zipkin, and Zipkin.Reporter.

  • In ConfigureServices(), configure Zipkin for the application and add RabbitMQ tracing using the Jaeger tracer:
services.AddOpenTracing();
services.Configure<HttpHandlerDiagnosticOptions>(options =>
{
    options.IgnorePatterns.Add(request => !request.RequestUri.LocalPath.StartsWith("/api"));
});
services.AddSingleton<ITracer>(serviceProvider =>
{
    var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();

    var reporter = new ZipkinHttpTraceReporter(“http://localhost:9411/api/v2/spans”);
    var tracer = new Tracer.Builder("My Zipkin Tracer")
        .WithReporter(reporter)
        .WithLoggerFactory(loggerFactory)
        .Build();

    return tracer;
});

Step 3: Trace RabbitMQ messages: - In the consumer or producer code, use the tracer to trace RabbitMQ messages:

using (var scope = tracer.BuildSpan("RabbitMQ Receive Message").StartActive())
{
    var message = await _rabbitMQ.Client.ReceiveAsync();

    // Handle the message
}

Step 4: Set up Zipkin and Jaeger in Docker: - Add a docker-compose.yml file to set up Zipkin and Jaeger in your Docker environment.

version: '3'
services:
  rabbitmq:
    build:
      context: .
      dockerfile: Dockerfile.rabbitmq
    ports:
      - "5672:5672"
      - "15672:15672"
  zipkin:
    image: openzipkin/zipkin
    ports:
      - "9411:9411"
  jaeger:
    image: jaegertracing/all-in-one:latest
    command: --query.port=16686
    ports:
      - "5775:5775/udp"
      - "6831:6831/udp"
      - "6832:6832/udp"
      - "5778:5778"
      - "16686:16686"
      - "14268:14268"
      - "9411:9411"
  • Run the Docker Compose: docker-compose up

Step 5: Visualize the traces in Zipkin UI: - Open Zipkin UI by pointing the browser to http://localhost:9411/ - You will be able to see the trace and the details of the RabbitMQ message in Zipkin UI.

That's it! You have successfully incorporated Zipkin into an ASP.NET Core web API microservice with Docker to view RabbitMQ traces.