Skip to content

Commit

Permalink
Add integration test to check that we record "code" telemetry config …
Browse files Browse the repository at this point in the history
…correctly
  • Loading branch information
andrewlock committed Nov 29, 2024
1 parent 88e2e04 commit b2e414e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
9 changes: 9 additions & 0 deletions Datadog.Trace.Minimal.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
"solution": {
"path": "Datadog.Trace.sln",
"projects": [
"tracer\\test\\test-applications\\integrations\\Samples.MongoDB\\Samples.MongoDB.csproj",
"tracer\\test\\test-applications\\integrations\\dependency-libs\\ActivitySampleHelper\\ActivitySampleHelper.csproj",
"tracer\\build\\_build\\_build.csproj",
"tracer\\test\\Datadog.Trace.ClrProfiler.IntegrationTests\\Datadog.Trace.ClrProfiler.IntegrationTests.csproj",
"tracer\\test\\Datadog.Trace.Tests\\Datadog.Trace.Tests.csproj",
"tracer\\test\\Datadog.Trace.TestHelpers\\Datadog.Trace.TestHelpers.csproj",
"tracer\\test\\Datadog.Trace.TestHelpers.AutoInstrumentation\\Datadog.Trace.TestHelpers.AutoInstrumentation.csproj",
"tracer\\src\\Datadog.Trace.Annotations\\Datadog.Trace.Annotations.csproj",
"tracer\\src\\Datadog.Trace.Manual\\Datadog.Trace.Manual.csproj",
"tracer\\src\\Datadog.Trace.ClrProfiler.Managed.Loader\\Datadog.Trace.ClrProfiler.Managed.Loader.csproj",
"tracer\\src\\Datadog.Tracer.Native\\Datadog.Tracer.Native.DLL.vcxproj",
"tracer\\src\\Datadog.Tracer.Native\\Datadog.Tracer.Native.vcxproj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,7 @@ internal static IEnumerable<DistributionMetricData> GetDistributions(this MockTe

internal static void AssertConfiguration(ICollection<TelemetryData> allData, string key, object value = null)
{
var payloads =
allData
.OrderByDescending(x => x.SeqId)
.Select(
data => data switch
{
_ when data.TryGetPayload<AppStartedPayload>(TelemetryRequestTypes.AppStarted) is { } p => p.Configuration,
_ when data.TryGetPayload<AppClientConfigurationChangedPayload>(TelemetryRequestTypes.AppClientConfigurationChanged) is { } p => p.Configuration,
_ => null,
})
.Where(x => x is not null)
.ToList();
var payloads = GetAllConfigurationPayloads(allData);

payloads.Should().NotBeEmpty();
var config = payloads
Expand All @@ -133,6 +122,23 @@ _ when data.TryGetPayload<AppClientConfigurationChangedPayload>(TelemetryRequest
}
}

internal static List<ICollection<ConfigurationKeyValue>> GetAllConfigurationPayloads(IEnumerable<TelemetryData> allData)
{
var payloads =
allData
.OrderByDescending(x => x.SeqId)
.Select(
data => data switch
{
_ when data.TryGetPayload<AppStartedPayload>(TelemetryRequestTypes.AppStarted) is { } p => p.Configuration,
_ when data.TryGetPayload<AppClientConfigurationChangedPayload>(TelemetryRequestTypes.AppClientConfigurationChanged) is { } p => p.Configuration,
_ => null,
})
.Where(x => x is not null)
.ToList();
return payloads;
}

internal static void AssertIntegration(ICollection<TelemetryData> allData, IntegrationId integrationId, bool enabled, bool? autoEnabled)
{
allData.Should().ContainSingle(x => x.IsRequestType(TelemetryRequestTypes.AppClosing));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Datadog.Trace.Configuration;
Expand Down Expand Up @@ -109,5 +110,20 @@ private async Task RunTest(bool usePublishWithRID = false)
settings.DisableRequireUniquePrefix();

await VerifyHelper.VerifySpans(spans, settings);

// telemetry should contain "code" config when it's set manually in code
// this just verifies we have values for all the settings we call,
// without being too rigid about the exact values to avoid fragility
var allConfig = TelemetryHelper.GetAllConfigurationPayloads(telemetry.Telemetry)
.SelectMany(x => x)
.Where(x => x.Origin == "code")
.Select(x => x.Name);

allConfig.Should().Contain([
ConfigurationKeys.DebugEnabled,
ConfigurationKeys.ServiceName,
ConfigurationKeys.Environment,
ConfigurationKeys.GlobalTags,
]);
}
}

0 comments on commit b2e414e

Please sign in to comment.