Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Proto.Actor/ActorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public ActorSystem() : this(new ActorSystemConfig())
public ActorSystem(ActorSystemConfig config)
{
Stopper = new Stopper();
Diagnostics = new ();
Config = config ?? throw new ArgumentNullException(nameof(config));
Diagnostics = new DiagnosticsStore(this);
ProcessRegistry = new ProcessRegistry(this);
Root = config.ConfigureRootContext(new RootContext(this));
DeadLetter = new DeadLetterProcess(this);
Expand Down
13 changes: 13 additions & 0 deletions src/Proto.Actor/Configuration/ActorSystemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public record ActorSystemConfig
/// </summary>
public bool DeadLetterResponseLogging { get; init; }

/// <summary>
/// The LogLevel used for diagnostics logging
/// </summary>
public LogLevel DiagnosticsLogLevel { get; set; } = LogLevel.Information;

/// <summary>
/// Creates a new default ActorSystemConfig
/// </summary>
Expand Down Expand Up @@ -224,6 +229,14 @@ public ActorSystemConfig WithDeveloperThreadPoolStatsLogging(bool enabled) =>
/// </summary>
public ActorSystemConfig WithDeadLetterResponseLogging(bool enabled) =>
this with { DeadLetterResponseLogging = enabled };

/// <summary>
/// The LogLevel used for Diagnostics logging
/// </summary>
/// <param name="diagnosticsLogLevel"></param>
/// <returns></returns>
public ActorSystemConfig WithDiagnosticsLogLevel(LogLevel diagnosticsLogLevel) =>
this with { DiagnosticsLogLevel = diagnosticsLogLevel };
}

//Not part of the contract, but still shipped out of the box
Expand Down
27 changes: 21 additions & 6 deletions src/Proto.Actor/Diagnostics/DiagnosticsStore.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
using System.Collections.Concurrent;

using System.Text.Json.Serialization;
using Microsoft.Extensions.Logging;
using Proto.Utils;


namespace Proto.Diagnostics;

public class DiagnosticsStore
{
private readonly ConcurrentBag<DiagnosticsEntry> _entries = new();
private readonly ILogger _logger = Log.CreateLogger<DiagnosticsStore>();
private readonly ConcurrentSet<DiagnosticsEntry> _entries = new();
private readonly LogLevel _logLevel;

public DiagnosticsStore(ActorSystem system)
{
_logLevel = system.Config.DiagnosticsLogLevel;
}

public void RegisterEvent(string module, string message)
{
var entry = new DiagnosticsEntry(module, message, null);
_entries.Add(entry);
if (_entries.TryAdd(entry))
{
_logger.Log(_logLevel, "[Diagnostics] Event {Module}: {Message}", module, message);
}
}

public void RegisterObject(string module, string key, object data)
{
var entry = new DiagnosticsEntry(module, key, data);
_entries.Add(entry);

if (_entries.TryAdd(entry))
{
var json = System.Text.Json.JsonSerializer.Serialize(data);
_logger.Log(_logLevel,"[Diagnostics] Event {Module}: {Key}: {Data}", module, key, json);
}
}

public DiagnosticsEntry[] Get()
Expand Down