Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more explicit logging to ApmAgent.Subscribe. #2153

Merged
merged 2 commits into from
Aug 8, 2023
Merged
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
11 changes: 10 additions & 1 deletion src/Elastic.Apm/ApmAgentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Elastic.Apm.Api;
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.Logging;

namespace Elastic.Apm
{
Expand All @@ -29,7 +31,14 @@ public static class ApmAgentExtensions
public static IDisposable Subscribe(this IApmAgent agent, params IDiagnosticsSubscriber[] subscribers)
{
var disposable = new CompositeDisposable();
if (!agent.Configuration.Enabled || subscribers is null || subscribers.Length == 0)

subscribers ??= Array.Empty<IDiagnosticsSubscriber>();
var subscribersList = string.Join(", ", subscribers.Select(s => s.GetType().Name));

agent.Logger.Trace()?.Log("Agent.Subscribe(), Agent Enabled: {AgentEnabled} Subscriber count: {NumberOfSubscribers}, ({Subscribers})",
agent.Configuration.Enabled, subscribers.Length, subscribersList);

if (!agent.Configuration.Enabled || subscribers.Length == 0)
return disposable;

foreach (var subscriber in subscribers)
Expand Down