Skip to content

Commit

Permalink
Message Bus: Distributed Tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
phongnguyend committed Jan 21, 2025
1 parent d0b860a commit a5871df
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
/*
* https://github.com/serilog/serilog-aspnetcore/issues/207
*
*/
using System.Diagnostics;

using Serilog.Core;
using Serilog.Events;
using System.Diagnostics;
namespace ClassifiedAds.CrossCuttingConcerns.Logging;

namespace ClassifiedAds.Infrastructure.Logging;

public class ActivityEnricher : ILogEventEnricher
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var activity = Activity.Current;

if (activity == null)
{
return;
}

logEvent.AddPropertyIfAbsent(new LogEventProperty("SpanId", new ScalarValue(activity.GetSpanId())));
logEvent.AddPropertyIfAbsent(new LogEventProperty("TraceId", new ScalarValue(activity.GetTraceId())));
logEvent.AddPropertyIfAbsent(new LogEventProperty("ParentId", new ScalarValue(activity.GetParentId())));
}
}

internal static class ActivityExtensions
public static class ActivityExtensions
{
public static string GetSpanId(this Activity activity)
{
Expand Down Expand Up @@ -57,4 +33,17 @@ public static string GetParentId(this Activity activity)
_ => null,
} ?? string.Empty;

Check warning on line 34 in src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/Logging/ActivityExtensions.cs

View workflow job for this annotation

GitHub Actions / build

}

public static Activity StartNew(string name, string parentId = null)
{
var activity = new Activity(name);

if (!string.IsNullOrEmpty(parentId))
{
activity.SetParentId(parentId);
}

activity.Start();
return activity;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public async Task ReceiveAsync(Func<T, MetaData, Task> action, CancellationToken

await _channel.QueueDeclareAsync(_options.QueueName, true, false, false, arguments, cancellationToken: cancellationToken);
await _channel.QueueBindAsync(_options.QueueName, _options.ExchangeName, _options.RoutingKey, null, cancellationToken: cancellationToken);
await _channel.QueueBindAsync(_options.QueueName, "amq.direct", $"direct_route_to_queue_{_options.QueueName}", null, cancellationToken: cancellationToken);
}

await _channel.BasicQosAsync(prefetchSize: 0, prefetchCount: 1, global: false, cancellationToken: cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ClassifiedAds.CrossCuttingConcerns.Exceptions;
using ClassifiedAds.Infrastructure.Logging;
using ClassifiedAds.CrossCuttingConcerns.Logging;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ClassifiedAds.CrossCuttingConcerns.Exceptions;
using ClassifiedAds.Infrastructure.Logging;
using ClassifiedAds.CrossCuttingConcerns.Logging;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
/*
* https://github.com/serilog/serilog-aspnetcore/issues/207
*
*/
using System.Diagnostics;

using Serilog.Core;
using Serilog.Events;
using System.Diagnostics;
namespace ClassifiedAds.CrossCuttingConcerns.Logging;

namespace ClassifiedAds.Infrastructure.Logging;

public class ActivityEnricher : ILogEventEnricher
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var activity = Activity.Current;

if (activity == null)
{
return;
}

logEvent.AddPropertyIfAbsent(new LogEventProperty("SpanId", new ScalarValue(activity.GetSpanId())));
logEvent.AddPropertyIfAbsent(new LogEventProperty("TraceId", new ScalarValue(activity.GetTraceId())));
logEvent.AddPropertyIfAbsent(new LogEventProperty("ParentId", new ScalarValue(activity.GetParentId())));
}
}

internal static class ActivityExtensions
public static class ActivityExtensions
{
public static string GetSpanId(this Activity activity)
{
Expand Down Expand Up @@ -57,4 +33,17 @@ public static string GetParentId(this Activity activity)
_ => null,
} ?? string.Empty;

Check warning on line 34 in src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/Logging/ActivityExtensions.cs

View workflow job for this annotation

GitHub Actions / build

}

public static Activity StartNew(string name, string parentId = null)
{
var activity = new Activity(name);

if (!string.IsNullOrEmpty(parentId))
{
activity.SetParentId(parentId);
}

activity.Start();
return activity;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public async Task ReceiveAsync(Func<T, MetaData, Task> action, CancellationToken

await _channel.QueueDeclareAsync(_options.QueueName, true, false, false, arguments, cancellationToken: cancellationToken);
await _channel.QueueBindAsync(_options.QueueName, _options.ExchangeName, _options.RoutingKey, null, cancellationToken: cancellationToken);
await _channel.QueueBindAsync(_options.QueueName, "amq.direct", $"direct_route_to_queue_{_options.QueueName}", null, cancellationToken: cancellationToken);
}

await _channel.BasicQosAsync(prefetchSize: 0, prefetchCount: 1, global: false, cancellationToken: cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ClassifiedAds.CrossCuttingConcerns.Exceptions;
using ClassifiedAds.Infrastructure.Logging;
using ClassifiedAds.CrossCuttingConcerns.Logging;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ClassifiedAds.CrossCuttingConcerns.Exceptions;
using ClassifiedAds.Infrastructure.Logging;
using ClassifiedAds.CrossCuttingConcerns.Logging;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
Expand Down

0 comments on commit a5871df

Please sign in to comment.