Skip to content

Commit 612abcd

Browse files
committed
Adds activity tracking for plugin execution
Enables activity tracking for plugin execution to monitor and diagnose plugin performance and identify bottlenecks. This change wraps the execution of various plugin types within `AppDiagnostics.StartActivity` to provide more granular tracing information.
1 parent f6a5805 commit 612abcd

File tree

7 files changed

+27
-1
lines changed

7 files changed

+27
-1
lines changed

src/Exceptionless.Core/Pipeline/Base/PipelineBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Concurrent;
1+
using System.Collections.Concurrent;
22
using Exceptionless.Core.Extensions;
33
using Exceptionless.Core.Helpers;
44
using Microsoft.Extensions.DependencyInjection;
@@ -58,6 +58,8 @@ public virtual async Task<ICollection<TContext>> RunAsync(ICollection<TContext>
5858

5959
foreach (var action in _actions)
6060
{
61+
using var _ = AppDiagnostics.StartActivity(action.Name);
62+
6163
string metricName = String.Concat(_metricPrefix, action.Name.ToLower());
6264
var contextsToProcess = contexts.Where(c => c.IsCancelled == false && !c.HasError).ToList();
6365
await AppDiagnostics.TimeAsync(() => action.ProcessBatchAsync(contextsToProcess), metricName);

src/Exceptionless.Core/Plugins/EventParser/EventParserPluginManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public List<PersistentEvent> ParseEvents(string input, int apiVersion, string? u
2525

2626
try
2727
{
28+
using var _ = AppDiagnostics.StartActivity(plugin.Name);
2829
List<PersistentEvent>? events = null;
2930
AppDiagnostics.Time(() => events = plugin.ParseEvents(input, apiVersion, userAgent), metricName);
3031
if (events is null)

src/Exceptionless.Core/Plugins/EventProcessor/EventPluginManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public async Task StartupAsync()
1515
{
1616
try
1717
{
18+
using var _ = AppDiagnostics.StartActivity(plugin.Name);
1819
string metricName = String.Concat(_metricPrefix, plugin.Name.ToLower());
1920
await AppDiagnostics.TimeAsync(() => plugin.StartupAsync(), metricName);
2021
}
@@ -39,7 +40,9 @@ public async Task EventBatchProcessingAsync(ICollection<EventContext> contexts)
3940
string metricName = String.Concat(_metricPrefix, plugin.Name.ToLower());
4041
try
4142
{
43+
using var _ = AppDiagnostics.StartActivity(plugin.Name);
4244
await AppDiagnostics.TimeAsync(() => plugin.EventBatchProcessingAsync(contextsToProcess), metricName);
45+
4346
if (contextsToProcess.All(c => c.IsCancelled || c.HasError))
4447
break;
4548
}
@@ -64,7 +67,9 @@ public async Task EventBatchProcessedAsync(ICollection<EventContext> contexts)
6467
string metricName = String.Concat(_metricPrefix, plugin.Name.ToLower());
6568
try
6669
{
70+
using var _ = AppDiagnostics.StartActivity(plugin.Name);
6771
await AppDiagnostics.TimeAsync(() => plugin.EventBatchProcessedAsync(contextsToProcess), metricName);
72+
6873
if (contextsToProcess.All(c => c.IsCancelled || c.HasError))
6974
break;
7075
}

src/Exceptionless.Core/Plugins/EventUpgrader/EventUpgraderPluginManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public void Upgrade(EventUpgraderContext context)
1717
string metricName = String.Concat(metricPrefix, plugin.Name.ToLower());
1818
try
1919
{
20+
using var _ = AppDiagnostics.StartActivity(plugin.Name);
2021
AppDiagnostics.Time(() => plugin.Upgrade(context), metricName);
2122
}
2223
catch (Exception ex)

src/Exceptionless.Core/Plugins/Formatting/FormattingPluginManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public SummaryData GetStackSummaryData(Stack stack)
1818

1919
try
2020
{
21+
using var __ = AppDiagnostics.StartActivity(plugin.Name);
2122
var result = plugin.GetStackSummaryData(stack);
2223
if (result is not null)
2324
return result;
@@ -42,6 +43,7 @@ public SummaryData GetEventSummaryData(PersistentEvent ev)
4243

4344
try
4445
{
46+
using var __ = AppDiagnostics.StartActivity(plugin.Name);
4547
var result = plugin.GetEventSummaryData(ev);
4648
if (result is not null)
4749
return result;
@@ -66,6 +68,7 @@ public string GetStackTitle(PersistentEvent ev)
6668

6769
try
6870
{
71+
using var __ = AppDiagnostics.StartActivity(plugin.Name);
6972
string? result = plugin.GetStackTitle(ev);
7073
if (!String.IsNullOrEmpty(result))
7174
return result;
@@ -90,6 +93,7 @@ public MailMessageData GetEventNotificationMailMessageData(PersistentEvent ev, b
9093

9194
try
9295
{
96+
using var __ = AppDiagnostics.StartActivity(plugin.Name);
9397
var result = plugin.GetEventNotificationMailMessageData(ev, isCritical, isNew, isRegression);
9498
if (result is not null)
9599
return result;
@@ -114,6 +118,7 @@ public SlackMessage GetSlackEventNotificationMessage(PersistentEvent ev, Project
114118

115119
try
116120
{
121+
using var __ = AppDiagnostics.StartActivity(plugin.Name);
117122
var message = plugin.GetSlackEventNotification(ev, project, isCritical, isNew, isRegression);
118123
if (message is not null)
119124
return message;

src/Exceptionless.Core/Plugins/WebHook/WebHookDataPluginManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public WebHookDataPluginManager(IServiceProvider serviceProvider, AppOptions opt
1717
string metricName = String.Concat(metricPrefix, plugin.Name.ToLower());
1818
try
1919
{
20+
using var _ = AppDiagnostics.StartActivity(plugin.Name);
2021
object? data = null;
2122
await AppDiagnostics.TimeAsync(async () => data = await plugin.CreateFromEventAsync(context), metricName);
2223
if (context.IsCancelled)
@@ -47,6 +48,7 @@ public WebHookDataPluginManager(IServiceProvider serviceProvider, AppOptions opt
4748
string metricName = String.Concat(metricPrefix, plugin.Name.ToLower());
4849
try
4950
{
51+
using var _ = AppDiagnostics.StartActivity(plugin.Name);
5052
object? data = null;
5153
await AppDiagnostics.TimeAsync(async () => data = await plugin.CreateFromStackAsync(context), metricName);
5254
if (context.IsCancelled)

src/Exceptionless.Core/Utility/AppDiagnostics.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ public static class AppDiagnostics
1717
private static readonly ConcurrentDictionary<string, GaugeInfo> _gauges = new();
1818
private static readonly ConcurrentDictionary<string, Histogram<double>> _timers = new();
1919

20+
/// <summary>
21+
/// Starts a new Activity span with the specified name.
22+
/// </summary>
23+
/// <param name="name">The friendly name for the span.</param>
24+
/// <returns>The started Activity, or null if no listeners are registered.</returns>
25+
public static Activity? StartActivity(string name)
26+
{
27+
return ActivitySource.StartActivity(name, ActivityKind.Internal, Activity.Current?.Id);
28+
}
29+
2030
public static void Counter(string name, int value = 1)
2131
{
2232
if (!_counters.TryGetValue(_metricsPrefix + name, out var counter))

0 commit comments

Comments
 (0)