Skip to content

Commit

Permalink
Add MetricsTelemetryCollector instance to test cases in TelemetryHelp…
Browse files Browse the repository at this point in the history
…erTests so that we can accurately test the metrics that are generated when TelemetryController.IntegrationGeneratedSpan(IntegrationId) is invoked in product code, which generates both a spans_created telemetry metric and an updated integration telemetry
  • Loading branch information
zacharycmontoya committed Jan 9, 2025
1 parent 68d194e commit 716ae47
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Datadog.Trace.Configuration.ConfigurationSources.Telemetry;
using Datadog.Trace.Configuration.Telemetry;
using Datadog.Trace.Telemetry;
using Datadog.Trace.Telemetry.Metrics;
using Datadog.Trace.TestHelpers;
using FluentAssertions;
using FluentAssertions.Execution;
Expand Down Expand Up @@ -48,25 +49,35 @@ public TelemetryHelperTests(ITestOutputHelper output)
public void AssertIntegration_HandlesMultipleTelemetryPushes()
{
var collector = new IntegrationTelemetryCollector();
var metricsCollector = new MetricsTelemetryCollector();
var telemetryData = new List<TelemetryData>();

collector.IntegrationRunning(IntegrationId.Aerospike);

telemetryData.Add(BuildTelemetryData(collector.GetData()));
metricsCollector.AggregateMetrics();
telemetryData.Add(BuildTelemetryData(collector.GetData(), metrics: metricsCollector.GetMetrics()));

// The updates to both the IntegrationTelemetryCollector and the MetricsTelemetryCollector
// are typically handled by TelemetryController.IntegrationGeneratedSpan(IntegrationId),
// so we simulate that here with the separate calls
collector.IntegrationGeneratedSpan(IntegrationId.Aerospike);
metricsCollector.RecordCountSpanCreated(IntegrationId.Aerospike.GetMetricTag());

collector.IntegrationRunning(IntegrationId.Couchbase);
telemetryData.Add(BuildTelemetryData(collector.GetData(), sendAppStarted: false));

metricsCollector.AggregateMetrics();
telemetryData.Add(BuildTelemetryData(collector.GetData(), metrics: metricsCollector.GetMetrics(), sendAppStarted: false));

collector.IntegrationRunning(IntegrationId.Kafka);
collector.IntegrationGeneratedSpan(IntegrationId.Msmq);
collector.IntegrationRunning(IntegrationId.Msmq);
var tracerSettings = TracerSettings.Create(new()
{
{ ConfigurationKeys.DisabledIntegrations, $"{nameof(IntegrationId.Kafka)};{nameof(IntegrationId.Msmq)}" }
});

collector.RecordTracerSettings(tracerSettings);
telemetryData.Add(BuildTelemetryData(collector.GetData(), sendAppClosing: true));
metricsCollector.AggregateMetrics();
telemetryData.Add(BuildTelemetryData(collector.GetData(), metrics: metricsCollector.GetMetrics(), sendAppClosing: true));

using var s = new AssertionScope();
TelemetryHelper.AssertIntegration(telemetryData, IntegrationId.Aerospike, enabled: true, autoEnabled: true);
Expand Down Expand Up @@ -150,12 +161,13 @@ public void AssertConfiguration_HandlesMultipleTelemetryPushes()
private TelemetryData BuildTelemetryData(
ICollection<IntegrationTelemetryData> integrations,
ICollection<ConfigurationKeyValue> configuration = null,
MetricResults? metrics = null,
bool sendAppStarted = true,
bool sendAppClosing = false)
=> _dataBuilder.BuildTelemetryData(
_app,
_host,
new TelemetryInput(configuration, null, integrations, null, null, sendAppStarted),
new TelemetryInput(configuration, null, integrations, metrics, null, sendAppStarted),
namingSchemeVersion: "1",
sendAppClosing);
}

0 comments on commit 716ae47

Please sign in to comment.