Skip to content

Commit

Permalink
Add test to ensure that we are collecting spans_created metrics and a…
Browse files Browse the repository at this point in the history
…sserting they have the tag "integration_name:IntegrationId.ToString()"
  • Loading branch information
zacharycmontoya committed Dec 18, 2024
1 parent 4288ae4 commit c00ad5f
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="TelemetryHelper.cs" company="Datadog">
// <copyright file="TelemetryHelper.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
Expand Down Expand Up @@ -165,6 +165,35 @@ _ when data.TryGetPayload<AppIntegrationsChangedPayload>(TelemetryRequestTypes.A
}
}

var spansCreatedByIntegration = new ConcurrentDictionary<string, MetricData>();
var metricsPayloads =
allData
.Select(
data => data switch
{
_ when data.TryGetPayload<GenerateMetricsPayload>(TelemetryRequestTypes.GenerateMetrics) is { } p => p.Series.Where(s => s.Metric == "spans_created"),
_ => null,
})
.Where(x => x is not null);

// Flatten the spans_created metrics
foreach (var metricPayload in metricsPayloads)
{
foreach (var metricEntry in metricPayload)
{
spansCreatedByIntegration.TryAdd(metricEntry.Tags.First(s => s.StartsWith("integration_name:")), metricEntry);
}
}

if (enabled)
{
spansCreatedByIntegration.Should().NotBeEmpty();

var spansCreated = spansCreatedByIntegration.Should().ContainKey($"integration_name:{integrationId.ToString().ToLower()}").WhoseValue;
spansCreated.Points.Should().NotBeEmpty();
spansCreated.Points.Sum(p => p.Value).Should().BeGreaterThanOrEqualTo(1);
}

latestIntegrations.Should().NotBeEmpty();

var integration = latestIntegrations.Should().ContainKey(integrationId.ToString()).WhoseValue;
Expand Down

0 comments on commit c00ad5f

Please sign in to comment.