diff --git a/tracer/test/benchmarks/Benchmarks.OpenTelemetry.Api/Benchmarks.OpenTelemetry.Api.csproj b/tracer/test/benchmarks/Benchmarks.OpenTelemetry.Api/Benchmarks.OpenTelemetry.Api.csproj
index 7b198ba2ef95..46d7f2659034 100644
--- a/tracer/test/benchmarks/Benchmarks.OpenTelemetry.Api/Benchmarks.OpenTelemetry.Api.csproj
+++ b/tracer/test/benchmarks/Benchmarks.OpenTelemetry.Api/Benchmarks.OpenTelemetry.Api.csproj
@@ -22,7 +22,7 @@
-
+
diff --git a/tracer/test/benchmarks/Benchmarks.OpenTelemetry.InstrumentedApi/Benchmarks.OpenTelemetry.InstrumentedApi.csproj b/tracer/test/benchmarks/Benchmarks.OpenTelemetry.InstrumentedApi/Benchmarks.OpenTelemetry.InstrumentedApi.csproj
index b99ab1662a28..cd2d9a68ddca 100644
--- a/tracer/test/benchmarks/Benchmarks.OpenTelemetry.InstrumentedApi/Benchmarks.OpenTelemetry.InstrumentedApi.csproj
+++ b/tracer/test/benchmarks/Benchmarks.OpenTelemetry.InstrumentedApi/Benchmarks.OpenTelemetry.InstrumentedApi.csproj
@@ -28,7 +28,7 @@
-
+
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/ActivityBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/ActivityBenchmark.cs
index 932ccbd2dc6e..a6a5809d6213 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/ActivityBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/ActivityBenchmark.cs
@@ -30,19 +30,27 @@ public class ActivityBenchmark
private Datadog.Trace.Activity.DuckTypes.ActivitySource _duckSource;
private ActivitySource _source;
+ private ActivityListener _activityListener;
[GlobalSetup]
public void GlobalSetup()
{
_source = new ActivitySource(SourceName);
- var activityListener = new ActivityListener { ShouldListenTo = _ => true, Sample = (ref ActivityCreationOptions options) => ActivitySamplingResult.AllData };
+ _activityListener = new ActivityListener { ShouldListenTo = _ => true, Sample = (ref ActivityCreationOptions options) => ActivitySamplingResult.AllData };
- ActivitySource.AddActivityListener(activityListener);
+ ActivitySource.AddActivityListener(_activityListener);
_duckSource = new Datadog.Trace.Activity.DuckTypes.ActivitySource { Name = _source.Name, Version = _source.Version ?? string.Empty };
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ _source.Dispose();
+ _activityListener.Dispose();
+ }
+
[Benchmark]
public void StartStopWithChild()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/AgentWriterBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/AgentWriterBenchmark.cs
index a4ff3f2ba228..68c8440720af 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/AgentWriterBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/AgentWriterBenchmark.cs
@@ -39,13 +39,9 @@ public void GlobalSetup()
_enrichedSpans = new ArraySegment(enrichedSpans);
- var overrides = new NameValueConfigurationSource(new()
- {
- { ConfigurationKeys.StartupDiagnosticLogEnabled, false.ToString() },
- { ConfigurationKeys.TraceEnabled, false.ToString() },
- });
- var sources = new CompositeConfigurationSource(new[] { overrides, GlobalConfigurationSource.Instance });
- var settings = new TracerSettings(sources);
+ var config = TracerHelper.DefaultConfig;
+ config.Add(ConfigurationKeys.TraceEnabled, false);
+ var settings = TracerSettings.Create(config);
var api = new Api(new FakeApiRequestFactory(settings.Exporter.AgentUri), statsd: null, updateSampleRates: null, partialFlushEnabled: false);
@@ -55,6 +51,12 @@ public void GlobalSetup()
WriteAndFlushEnrichedTraces().GetAwaiter().GetResult();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ _agentWriter.FlushAndCloseAsync();
+ }
+
///
/// Same as WriteAndFlushTraces but with more realistic traces (with tags and metrics)
///
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecBenchmarkUtils.cs b/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecBenchmarkUtils.cs
index b3dc8ddaf3da..6376b5a3cc3a 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecBenchmarkUtils.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecBenchmarkUtils.cs
@@ -15,14 +15,27 @@ internal class AppSecBenchmarkUtils
{
internal static void SetupDummyAgent()
{
- var settings = TracerSettings.Create(new()
+ TracerHelper.SetGlobalTracer(new()
{
{ ConfigurationKeys.StartupDiagnosticLogEnabled, false },
#pragma warning disable CS0618 // Type or member is obsolete
{ ConfigurationKeys.MaxTracesSubmittedPerSecond, 0 },
#pragma warning restore CS0618 // Type or member is obsolete
+ { ConfigurationKeys.Rcm.RemoteConfigurationEnabled, false }, // disable remote config
+ { ConfigurationKeys.AgentFeaturePollingEnabled, false }, // disable discovery service
+ { ConfigurationKeys.Telemetry.Enabled, false }, // disable telemetry
});
- Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
+ }
+
+ internal static void CleanupDummyAgent()
+ {
+ TracerHelper.CleanupGlobalTracer();
+ }
+
+ internal static void CleanupWafLibraryInvoker()
+ {
+ Environment.SetEnvironmentVariable("DD_TRACE_LOGGING_RATE", null);
+ Environment.SetEnvironmentVariable("DD_INTERNAL_TRACE_NATIVE_ENGINE_PATH", null);
}
internal static WafLibraryInvoker CreateWafLibraryInvoker()
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecBodyBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecBodyBenchmark.cs
index 079c631a46c6..005342473514 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecBodyBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecBodyBenchmark.cs
@@ -42,7 +42,6 @@ public class AppSecBodyBenchmark
public void GlobalSetup()
{
AppSecBenchmarkUtils.SetupDummyAgent();
- var dir = Directory.GetCurrentDirectory();
Environment.SetEnvironmentVariable("DD_APPSEC_ENABLED", "true");
_security = Security.Instance;
@@ -73,6 +72,13 @@ public void GlobalSetup()
_props10x6 = ConstructionUtils.ConstructProps10Rec(6);
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ Environment.SetEnvironmentVariable("DD_APPSEC_ENABLED", null);
+ AppSecBenchmarkUtils.CleanupDummyAgent();
+ }
+
[Benchmark]
public void AllCycleSimpleBody() => ExecuteCycle(new { });
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecEncodeBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecEncodeBenchmark.cs
index 139fead5f82b..e078bc46d812 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecEncodeBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecEncodeBenchmark.cs
@@ -36,6 +36,17 @@ public void GlobalSetup()
_args = MakeNestedMap(20);
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ AppSecBenchmarkUtils.CleanupDummyAgent();
+ AppSecBenchmarkUtils.CleanupWafLibraryInvoker();
+ if (Encoder.Pool is { IsDisposed: false } pool)
+ {
+ pool.Dispose();
+ }
+ }
+
///
/// Generates dummy arguments for the waf
///
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecWafBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecWafBenchmark.cs
index 6eb10d08deb9..2fab8fc92e33 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecWafBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/Asm/AppSecWafBenchmark.cs
@@ -60,6 +60,14 @@ public void GlobalSetup()
_stage3 = MakeRealisticNestedMapStage3();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ AppSecBenchmarkUtils.CleanupDummyAgent();
+ AppSecBenchmarkUtils.CleanupWafLibraryInvoker();
+ _waf?.Dispose();
+ }
+
[IterationSetup]
public void IterationSetup()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/AspNetCoreBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/AspNetCoreBenchmark.cs
index 587418116632..e84512e4be99 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/AspNetCoreBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/AspNetCoreBenchmark.cs
@@ -1,13 +1,23 @@
#if !NETFRAMEWORK
using System;
+using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Datadog.Trace;
+using Datadog.Trace.Agent.DiscoveryService;
+using Datadog.Trace.AppSec;
using Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.HttpClientHandler;
using Datadog.Trace.Configuration;
+using Datadog.Trace.Configuration.Telemetry;
+using Datadog.Trace.Debugger;
+using Datadog.Trace.Debugger.SpanCodeOrigin;
+using Datadog.Trace.DiagnosticListeners;
+using Datadog.Trace.Iast.Settings;
+using Datadog.Trace.RemoteConfigurationManagement;
+using Datadog.Trace.Security.Unit.Tests.Iast;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
@@ -22,26 +32,48 @@ namespace Benchmarks.Trace
public class AspNetCoreBenchmark
{
private HttpClient _client;
+ private Tracer _tracer;
+ private Security _security;
+ private Datadog.Trace.Iast.Iast _iast;
+ private SpanCodeOrigin _spanCodeOrigin;
+ private DiagnosticManager _diagnosticManager;
+ private TestServer _testServer;
[GlobalSetup]
public void GlobalSetup()
{
- var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });
+ var config = new CustomSettingsForTests(TracerHelper.DefaultConfig);
+ var settings = new TracerSettings(config, NullConfigurationTelemetry.Instance, new());
- Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
+ _tracer = TracerHelper.CreateTracer(settings);
+ _security = new Security(new SecuritySettings(config, NullConfigurationTelemetry.Instance), null, new RcmSubscriptionManager());
+ _iast = new Datadog.Trace.Iast.Iast(new IastSettings(config, NullConfigurationTelemetry.Instance), NullDiscoveryService.Instance);
var builder = new WebHostBuilder()
.UseStartup();
- var testServer = new TestServer(builder);
- _client = testServer.CreateClient();
+ _testServer = new TestServer(builder);
+ _client = _testServer.CreateClient();
- Datadog.Trace.ClrProfiler.Instrumentation.Initialize();
+ var observers = new List();
+ _spanCodeOrigin = new SpanCodeOrigin(new DebuggerSettings(config, NullConfigurationTelemetry.Instance));
+ observers.Add(new AspNetCoreDiagnosticObserver(_tracer, _security, _iast, _spanCodeOrigin));
+ _diagnosticManager = new DiagnosticManager(observers);
+ _diagnosticManager.Start();
// Warmup to initialize middleware pipeline
SendRequest();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ _diagnosticManager.Dispose();
+ _testServer.Dispose();
+ _security.Dispose();
+ _tracer.TracerManager.ShutdownAsync().GetAwaiter().GetResult();
+ }
+
[Benchmark]
public string SendRequest()
{
@@ -102,6 +134,11 @@ public void GlobalSetup()
{
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ }
+
[Benchmark]
public string SendRequest()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/Benchmarks.Trace.csproj b/tracer/test/benchmarks/Benchmarks.Trace/Benchmarks.Trace.csproj
index bbd352963c01..62fa11b0510a 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/Benchmarks.Trace.csproj
+++ b/tracer/test/benchmarks/Benchmarks.Trace/Benchmarks.Trace.csproj
@@ -37,14 +37,14 @@
PreserveNewest
+
-
-
+
+
-
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/CIVisibilityProtocolWriterBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/CIVisibilityProtocolWriterBenchmark.cs
index 719d01019ee4..559c3d4f6048 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/CIVisibilityProtocolWriterBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/CIVisibilityProtocolWriterBenchmark.cs
@@ -36,13 +36,9 @@ public void GlobalSetup()
_enrichedSpans = new ArraySegment(enrichedSpans);
- var overrides = new NameValueConfigurationSource(new()
- {
- { ConfigurationKeys.StartupDiagnosticLogEnabled, false.ToString() },
- { ConfigurationKeys.TraceEnabled, false.ToString() },
- });
- var sources = new CompositeConfigurationSource(new[] { overrides, GlobalConfigurationSource.Instance });
- var settings = new TestOptimizationSettings(sources, NullConfigurationTelemetry.Instance);
+ var config = TracerHelper.DefaultConfig;
+ config[ConfigurationKeys.TraceEnabled] = false;
+ var settings = new TestOptimizationSettings(new DictionaryObjectConfigurationSource(config), NullConfigurationTelemetry.Instance);
_eventWriter = new CIVisibilityProtocolWriter(settings, new FakeCIVisibilityProtocolWriter());
@@ -50,6 +46,13 @@ public void GlobalSetup()
WriteAndFlushEnrichedTraces().GetAwaiter().GetResult();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ _eventWriter.FlushAndCloseAsync();
+ }
+
+
///
/// Same as WriteAndFlushTraces but with more realistic traces (with tags and metrics)
///
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/DbCommandBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/DbCommandBenchmark.cs
index 77663409f5d1..f76037a518fe 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/DbCommandBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/DbCommandBenchmark.cs
@@ -18,13 +18,16 @@ public class DbCommandBenchmark
[GlobalSetup]
public void GlobalSetup()
{
- var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });
-
- Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
-
+ TracerHelper.SetGlobalTracer();
_customCommand = new CustomDbCommand();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ TracerHelper.CleanupGlobalTracer();
+ }
+
[Benchmark]
public unsafe int ExecuteNonQuery()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/ElasticsearchBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/ElasticsearchBenchmark.cs
index e546c7b17bf1..8d951e78b66f 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/ElasticsearchBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/ElasticsearchBenchmark.cs
@@ -20,9 +20,7 @@ public class ElasticsearchBenchmark
[GlobalSetup]
public void GlobalSetup()
{
- var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });
-
- Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
+ TracerHelper.SetGlobalTracer();
_pipeline = new RequestPipeline();
_data = new RequestData
@@ -33,6 +31,12 @@ public void GlobalSetup()
};
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ TracerHelper.CleanupGlobalTracer();
+ }
+
[Benchmark]
public unsafe object CallElasticsearch()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/GraphQLBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/GraphQLBenchmark.cs
index 32719b5cd561..94ee0945d530 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/GraphQLBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/GraphQLBenchmark.cs
@@ -20,14 +20,18 @@ public class GraphQLBenchmark
[GlobalSetup]
public void GlobalSetup()
{
- var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });
-
- Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
+ TracerHelper.SetGlobalTracer();
_context = new ExecutionContext();
_client = new GraphQLClient(_result);
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ TracerHelper.CleanupGlobalTracer();
+ }
+
[Benchmark]
public unsafe int ExecuteAsync()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/HttpClientBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/HttpClientBenchmark.cs
index 7cc6a7a6e446..bf3c85e6660c 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/HttpClientBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/HttpClientBenchmark.cs
@@ -20,13 +20,17 @@ public class HttpClientBenchmark
[GlobalSetup]
public void GlobalSetup()
{
- var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });
-
- Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
-
+ TracerHelper.SetGlobalTracer();
_httpRequest = new HttpRequestMessage { RequestUri = new Uri("http://datadoghq.com") };
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ TracerHelper.CleanupGlobalTracer();
+ _httpRequest.Dispose();
+ }
+
[Benchmark]
public unsafe string SendAsync()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/ILoggerBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/ILoggerBenchmark.cs
index 79f051b8b342..30080beffc60 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/ILoggerBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/ILoggerBenchmark.cs
@@ -16,42 +16,49 @@ namespace Benchmarks.Trace
[BenchmarkCategory(Constants.TracerCategory)]
public class ILoggerBenchmark
{
- private Tracer _logInjectionTracer;
private ILogger _logger;
+ private ServiceProvider _serviceProvider;
[GlobalSetup]
public void GlobalSetup()
{
- var logInjectionSettings = TracerSettings.Create(new()
- {
- { ConfigurationKeys.StartupDiagnosticLogEnabled, false },
- { ConfigurationKeys.LogsInjectionEnabled, true },
- { ConfigurationKeys.Environment, "env" },
- { ConfigurationKeys.ServiceVersion, "version" },
- });
-
- _logInjectionTracer = new Tracer(logInjectionSettings, new DummyAgentWriter(), null, null, null);
- Tracer.UnsafeSetTracerInstance(_logInjectionTracer);
+ var config = TracerHelper.DefaultConfig;
+ config[ConfigurationKeys.LogsInjectionEnabled] = true;
+ config[ConfigurationKeys.Environment] = "env";
+ config[ConfigurationKeys.ServiceVersion] = "version";
+ TracerHelper.SetGlobalTracer(config);
var services = new ServiceCollection();
services.AddLogging();
services.AddSingleton();
- var serviceProvider = services.BuildServiceProvider();
+ _serviceProvider = services.BuildServiceProvider();
- _logger = serviceProvider.GetRequiredService>();
+ _logger = _serviceProvider.GetRequiredService>();
// Warmup
EnrichedLog();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ if (_logger is IDisposable disposable)
+ {
+ disposable.Dispose();
+ }
+
+ _serviceProvider.Dispose();
+ TracerHelper.CleanupGlobalTracer();
+ }
+
[Benchmark]
public void EnrichedLog()
{
- using (_logInjectionTracer.StartActive("Test"))
+ using (Tracer.Instance.StartActive("Test"))
{
- using (_logInjectionTracer.StartActive("Child"))
+ using (Tracer.Instance.StartActive("Child"))
{
_logger.LogInformation("Hello");
}
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/Log4netBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/Log4netBenchmark.cs
index 2430a4ad7e9b..c50b1e7c2052 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/Log4netBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/Log4netBenchmark.cs
@@ -17,22 +17,16 @@ namespace Benchmarks.Trace
[BenchmarkCategory(Constants.TracerCategory)]
public class Log4netBenchmark
{
- private Tracer _logInjectionTracer;
private log4net.ILog _logger;
[GlobalSetup]
public void GlobalSetup()
{
- var logInjectionSettings = TracerSettings.Create(new()
- {
- { ConfigurationKeys.StartupDiagnosticLogEnabled, false },
- { ConfigurationKeys.LogsInjectionEnabled, true },
- { ConfigurationKeys.Environment, "env" },
- { ConfigurationKeys.ServiceVersion, "version" },
- });
-
- _logInjectionTracer = new Tracer(logInjectionSettings, new DummyAgentWriter(), null, null, null);
- Tracer.UnsafeSetTracerInstance(_logInjectionTracer);
+ var config = TracerHelper.DefaultConfig;
+ config[ConfigurationKeys.LogsInjectionEnabled] = true;
+ config[ConfigurationKeys.Environment] = "env";
+ config[ConfigurationKeys.ServiceVersion] = "version";
+ TracerHelper.SetGlobalTracer(config);
var repository = (Hierarchy)log4net.LogManager.GetRepository();
var patternLayout = new PatternLayout { ConversionPattern = "%date [%thread] %-5level %logger {dd.env=%property{dd.env}, dd.service=%property{dd.service}, dd.version=%property{dd.version}, dd.trace_id=%property{dd.trace_id}, dd.span_id=%property{dd.span_id}} - %message%newline" };
@@ -55,12 +49,18 @@ public void GlobalSetup()
_logger = log4net.LogManager.GetLogger(typeof(Log4netBenchmark));
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ TracerHelper.CleanupGlobalTracer();
+ }
+
[Benchmark]
public void EnrichedLog()
{
- using (_logInjectionTracer.StartActive("Test"))
+ using (Tracer.Instance.StartActive("Test"))
{
- using (_logInjectionTracer.StartActive("Child"))
+ using (Tracer.Instance.StartActive("Child"))
{
_logger.Info("Hello");
}
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/NLogBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/NLogBenchmark.cs
index 5e57efbea948..1e4dd57c6d5e 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/NLogBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/NLogBenchmark.cs
@@ -14,22 +14,16 @@ namespace Benchmarks.Trace
[BenchmarkCategory(Constants.TracerCategory)]
public class NLogBenchmark
{
- private Tracer _logInjectionTracer;
private NLog.Logger _logger;
[GlobalSetup]
public void GlobalSetup()
{
- var logInjectionSettings = TracerSettings.Create(new()
- {
- { ConfigurationKeys.StartupDiagnosticLogEnabled, false },
- { ConfigurationKeys.LogsInjectionEnabled, true },
- { ConfigurationKeys.Environment, "env" },
- { ConfigurationKeys.ServiceVersion, "version" },
- });
-
- _logInjectionTracer = new Tracer(logInjectionSettings, new DummyAgentWriter(), null, null, null);
- Tracer.UnsafeSetTracerInstance(_logInjectionTracer);
+ var settings = TracerHelper.DefaultConfig;
+ settings[ConfigurationKeys.LogsInjectionEnabled] = true;
+ settings[ConfigurationKeys.Environment] = "env";
+ settings[ConfigurationKeys.ServiceVersion] = "version";
+ TracerHelper.SetGlobalTracer(settings);
var config = new LoggingConfiguration();
@@ -53,12 +47,19 @@ public void GlobalSetup()
_ = DiagnosticContextHelper.Cache.Mdlc;
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ LogManager.Shutdown();
+ TracerHelper.CleanupGlobalTracer();
+ }
+
[Benchmark]
public void EnrichedLog()
{
- using (_logInjectionTracer.StartActive("Test"))
+ using (Tracer.Instance.StartActive("Test"))
{
- using (_logInjectionTracer.StartActive("Child"))
+ using (Tracer.Instance.StartActive("Child"))
{
// None of the arguments are used directly
// First arg is a marker type, so needs to be an NLog type
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/RedisBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/RedisBenchmark.cs
index 898549787f08..0f7cd3461434 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/RedisBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/RedisBenchmark.cs
@@ -22,10 +22,7 @@ public class RedisBenchmark
[GlobalSetup]
public void GlobalSetup()
{
- var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });
-
- Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
-
+ TracerHelper.SetGlobalTracer();
_client = new RedisNativeClient();
_fn = () => 42;
_completePipelineFn = _ => { };
@@ -34,6 +31,12 @@ public void GlobalSetup()
.ToArray();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ TracerHelper.CleanupGlobalTracer();
+ }
+
[Benchmark]
public unsafe int SendReceive()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/SerilogBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/SerilogBenchmark.cs
index a3f980e9d8de..f7c8612eb0d6 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/SerilogBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/SerilogBenchmark.cs
@@ -21,22 +21,16 @@ namespace Benchmarks.Trace
public class SerilogBenchmark
{
private Logger _logger;
- private Tracer _logInjectionTracer;
private LogEvent _logEvent;
[GlobalSetup]
public void GlobalSetup()
{
- var logInjectionSettings = TracerSettings.Create(new()
- {
- { ConfigurationKeys.StartupDiagnosticLogEnabled, false },
- { ConfigurationKeys.LogsInjectionEnabled, true },
- { ConfigurationKeys.Environment, "env" },
- { ConfigurationKeys.ServiceVersion, "version" },
- });
-
- _logInjectionTracer = new Tracer(logInjectionSettings, new DummyAgentWriter(), null, null, null);
- Tracer.UnsafeSetTracerInstance(_logInjectionTracer);
+ var settings = TracerHelper.DefaultConfig;
+ settings[ConfigurationKeys.LogsInjectionEnabled] = true;
+ settings[ConfigurationKeys.Environment] = "env";
+ settings[ConfigurationKeys.ServiceVersion] = "version";
+ TracerHelper.SetGlobalTracer(settings);
var formatter = new MessageTemplateTextFormatter("{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}{Properties}{NewLine}", null);
@@ -57,12 +51,19 @@ public void GlobalSetup()
EnrichedLog();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ _logger.Dispose();
+ TracerHelper.CleanupGlobalTracer();
+ }
+
[Benchmark]
public void EnrichedLog()
{
- using (_logInjectionTracer.StartActive("Test"))
+ using (Tracer.Instance.StartActive("Test"))
{
- using (_logInjectionTracer.StartActive("Child"))
+ using (Tracer.Instance.StartActive("Child"))
{
// equivalent of auto-instrumentation
LoggerDispatchInstrumentation.OnMethodBegin(_logger, _logEvent);
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/SpanBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/SpanBenchmark.cs
index aa55bd5a709c..a8cbe85e400b 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/SpanBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/SpanBenchmark.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using Datadog.Trace;
+using Datadog.Trace.Agent.DiscoveryService;
using Datadog.Trace.BenchmarkDotNet;
using Datadog.Trace.ClrProfiler.AutoInstrumentation.ManualInstrumentation.Extensions;
using Datadog.Trace.ClrProfiler.AutoInstrumentation.ManualInstrumentation.Proxies;
@@ -10,6 +11,7 @@
using Datadog.Trace.Configuration;
using Datadog.Trace.DuckTyping;
using Datadog.Trace.ExtensionMethods;
+using Datadog.Trace.Telemetry;
using BindingFlags = System.Reflection.BindingFlags;
using Tracer = Datadog.Trace.Tracer;
using ManualTracer = DatadogTraceManual::Datadog.Trace.Tracer;
@@ -36,9 +38,11 @@ public void GlobalSetup()
{
{ ConfigurationKeys.StartupDiagnosticLogEnabled, false },
{ ConfigurationKeys.TraceEnabled, false },
+ { ConfigurationKeys.AgentFeaturePollingEnabled, false },
+ { ConfigurationKeys.Telemetry.Enabled, false },
});
- _tracer = new Tracer(settings, new DummyAgentWriter(), null, null, null);
+ _tracer = new Tracer(settings, new DummyAgentWriter(), null, null, null, telemetry: NullTelemetryController.Instance, NullDiscoveryService.Instance);
// Create the manual integration
Dictionary manualSettings = new();
@@ -53,6 +57,12 @@ public void GlobalSetup()
StartFinishSpan();
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ _tracer.TracerManager.ShutdownAsync().GetAwaiter().GetResult();
+ }
+
// ///
// /// Starts and finishes scope benchmark using the manual instrumentation
// ///
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/TraceAnnotationsBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/TraceAnnotationsBenchmark.cs
index 2e5d2a63ee0c..88fe11b2bedd 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/TraceAnnotationsBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/TraceAnnotationsBenchmark.cs
@@ -25,9 +25,13 @@ static TraceAnnotationsBenchmark()
[GlobalSetup]
public void GlobalSetup()
{
- var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });
+ TracerHelper.SetGlobalTracer();
+ }
- Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ TracerHelper.CleanupGlobalTracer();
}
[Benchmark]
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/TraceProcessorBenchmark.cs b/tracer/test/benchmarks/Benchmarks.Trace/TraceProcessorBenchmark.cs
index c71254c385f2..b0f4a2852b38 100644
--- a/tracer/test/benchmarks/Benchmarks.Trace/TraceProcessorBenchmark.cs
+++ b/tracer/test/benchmarks/Benchmarks.Trace/TraceProcessorBenchmark.cs
@@ -10,18 +10,21 @@ namespace Benchmarks.Trace
[MemoryDiagnoser]
public class TraceProcessorBenchmark
{
- private readonly ITraceProcessor _normalizerTraceProcessor;
- private readonly ITraceProcessor _trucantorTraceProcessor;
- private readonly ITraceProcessor _obfuscatorTraceProcessor;
+ private ITraceProcessor _normalizerTraceProcessor;
+ private ITraceProcessor _trucantorTraceProcessor;
+ private ITraceProcessor _obfuscatorTraceProcessor;
private ArraySegment _spans;
+ private Tracer _tracer;
- public TraceProcessorBenchmark()
+ [GlobalSetup]
+ public void GlobalSetup()
{
_normalizerTraceProcessor = new NormalizerTraceProcessor();
_trucantorTraceProcessor = new TruncatorTraceProcessor();
_obfuscatorTraceProcessor = new ObfuscatorTraceProcessor(true);
-
- var traceContext = new TraceContext(Tracer.Instance, null);
+
+ _tracer = TracerHelper.CreateTracer();
+ var traceContext = new TraceContext(_tracer, null);
var spanContext = new SpanContext(parent: null, traceContext, serviceName: "My Service Name", traceId: (TraceId)100, spanId: 200);
var span = new Span(spanContext, DateTimeOffset.Now);
span.ResourceName = "My Resource Name";
@@ -29,6 +32,12 @@ public TraceProcessorBenchmark()
_spans = new ArraySegment(Enumerable.Repeat(span, 100).ToArray());
}
+ [GlobalCleanup]
+ public void GlobalCleanup()
+ {
+ _tracer.TracerManager.ShutdownAsync().GetAwaiter().GetResult();
+ }
+
[Benchmark]
public void NormalizerProcessor()
{
diff --git a/tracer/test/benchmarks/Benchmarks.Trace/TracerHelper.cs b/tracer/test/benchmarks/Benchmarks.Trace/TracerHelper.cs
new file mode 100644
index 000000000000..16a799cbfd48
--- /dev/null
+++ b/tracer/test/benchmarks/Benchmarks.Trace/TracerHelper.cs
@@ -0,0 +1,43 @@
+using System.Collections.Generic;
+using Datadog.Trace;
+using Datadog.Trace.Agent.DiscoveryService;
+using Datadog.Trace.Configuration;
+using Datadog.Trace.Configuration.ConfigurationSources.Telemetry;
+using Datadog.Trace.Configuration.Telemetry;
+using Datadog.Trace.Telemetry;
+
+namespace Benchmarks.Trace;
+
+public static class TracerHelper
+{
+ // Return a new instance each time to handle modification
+ public static Dictionary DefaultConfig => new()
+ {
+ { ConfigurationKeys.StartupDiagnosticLogEnabled, false },
+ { ConfigurationKeys.Rcm.RemoteConfigurationEnabled, false },
+ { ConfigurationKeys.AgentFeaturePollingEnabled, false },
+ { ConfigurationKeys.Telemetry.Enabled, false },
+ };
+
+ public static Tracer CreateTracer(Dictionary config = null)
+ => CreateTracer(
+ new TracerSettings(
+ new DictionaryObjectConfigurationSource(config ?? DefaultConfig),
+ NullConfigurationTelemetry.Instance,
+ new OverrideErrorLog()));
+
+ public static Tracer CreateTracer(TracerSettings settings)
+ => new(settings, new DummyAgentWriter(), null, null, null, NullTelemetryController.Instance, NullDiscoveryService.Instance);
+
+ public static void SetGlobalTracer(Dictionary config = null)
+ {
+ Tracer.UnsafeSetTracerInstance(CreateTracer(config));
+ }
+
+ public static void CleanupGlobalTracer()
+ {
+ Tracer.Instance.TracerManager.ShutdownAsync().GetAwaiter().GetResult();
+ Tracer.UnsafeSetTracerInstance(null);
+ }
+
+}