Skip to content

Commit

Permalink
Change to use ActivitySource
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Apr 12, 2021
1 parent 182bbf6 commit 65cbca0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 74 deletions.
10 changes: 8 additions & 2 deletions src/Foundatio.TestHarness/Queue/QueueTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Foundatio.Queues;
using Foundatio.Tests.Extensions;
using Foundatio.Utility;
using Foundatio.Diagnostics;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -90,7 +89,14 @@ public virtual async Task CanUseQueueOptionsAsync() {
return;

try {
QueuesDiagnosticSource.ListenToProcessQueueEntry(o => _logger.LogInformation("OnStart"), o => _logger.LogInformation("OnStop"));
using var listener = new ActivityListener {
ShouldListenTo = s => s.Name == "Foundatio",
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData,
ActivityStarted = activity => _logger.LogInformation("Start: " + activity.DisplayName),
ActivityStopped = activity => _logger.LogInformation("Stop: " + activity.DisplayName)
};

ActivitySource.AddActivityListener(listener);

await queue.DeleteQueueAsync();
await AssertEmptyQueueAsync(queue);
Expand Down
10 changes: 4 additions & 6 deletions src/Foundatio/Queues/QueueBase.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Foundatio.Diagnostics;
using Foundatio.Serializer;
using Foundatio.Utility;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -123,16 +122,15 @@ protected virtual Task OnEnqueuedAsync(IQueueEntry<T> entry) {
public AsyncEvent<DequeuedEventArgs<T>> Dequeued { get; } = new AsyncEvent<DequeuedEventArgs<T>>(true);

protected virtual void StartProcessQueueEntryActivity(IQueueEntry<T> entry) {
if (!QueuesDiagnosticSource.Logger.IsEnabled("ProcessQueueEntry") || !QueuesDiagnosticSource.Logger.IsEnabled("ProcessQueueEntry", entry))
var activity = FoundatioDiagnostics.ActivitySource.StartActivity("ProcessQueueEntry", ActivityKind.Internal);
if (activity == null)
return;

var activity = new Activity("ProcessQueueEntry");
activity.AddTag("Id", entry.Id);
if (!String.IsNullOrEmpty(entry.CorrelationId))
activity.SetParentId(entry.CorrelationId);

EnrichProcessQueueEntryActivity(activity, entry);
QueuesDiagnosticSource.Logger.StartActivity(activity, entry);

entry.Properties["@Activity"] = activity;
}
Expand All @@ -144,7 +142,7 @@ protected virtual void StopProcessQueueEntryActivity(IQueueEntry<T> entry) {
return;

entry.Properties.Remove("@Activity");
QueuesDiagnosticSource.Logger.StopActivity(activity, entry);
activity.Stop();
}

protected virtual Task OnDequeuedAsync(IQueueEntry<T> entry) {
Expand Down
11 changes: 0 additions & 11 deletions src/Foundatio/Utility/DiagnosticActivityListener.cs

This file was deleted.

43 changes: 0 additions & 43 deletions src/Foundatio/Utility/DiagnosticActivitySubscriber.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/Foundatio/Utility/FoundatioDiagnosticSource.cs

This file was deleted.

10 changes: 10 additions & 0 deletions src/Foundatio/Utility/FoundatioDiagnostics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Diagnostics;
using System.Reflection;

namespace Foundatio {
internal static class FoundatioDiagnostics {
private static readonly AssemblyName AssemblyName = typeof(FoundatioDiagnostics).Assembly.GetName();
internal static readonly ActivitySource ActivitySource = new(AssemblyName.Name, AssemblyName.Version.ToString());
}
}

0 comments on commit 65cbca0

Please sign in to comment.