Skip to content

Commit

Permalink
Explicitly enable v2 telemetry for apps that don't enable it by default
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Oct 26, 2023
1 parent ef64807 commit ac7bb9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static MockTelemetryAgent ConfigureTelemetry(this TestHelper helper)
helper.SetEnvironmentVariable("DD_TRACE_TELEMETRY_URL", $"http://localhost:{telemetry.Port}");
// API key is required when using the custom url
helper.SetEnvironmentVariable("DD_API_KEY", "INVALID_KEY_FOR_TESTS");
// For legacy versions that don't use V2 by default
helper.SetEnvironmentVariable("DD_INTERNAL_TELEMETRY_V2_ENABLED", "1");

return telemetry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ namespace Datadog.Trace.ClrProfiler.IntegrationTests
public class TraceAnnotationsAutomaticOnlyTests : TraceAnnotationsTests
{
public TraceAnnotationsAutomaticOnlyTests(ITestOutputHelper output)
: base("TraceAnnotations", twoAssembliesLoaded: false, output)
: base("TraceAnnotations", twoAssembliesLoaded: false, enableTelemetry: true, output)
{
}
}

public class TraceAnnotationsVersionMismatchAfterFeatureTests : TraceAnnotationsTests
{
public TraceAnnotationsVersionMismatchAfterFeatureTests(ITestOutputHelper output)
: base("TraceAnnotations.VersionMismatch.AfterFeature", twoAssembliesLoaded: true, output)
: base("TraceAnnotations.VersionMismatch.AfterFeature", twoAssembliesLoaded: true, enableTelemetry: false, output)
{
}
}

public class TraceAnnotationsVersionMismatchBeforeFeatureTests : TraceAnnotationsTests
{
public TraceAnnotationsVersionMismatchBeforeFeatureTests(ITestOutputHelper output)
: base("TraceAnnotations.VersionMismatch.BeforeFeature", twoAssembliesLoaded: true, output)
: base("TraceAnnotations.VersionMismatch.BeforeFeature", twoAssembliesLoaded: true, enableTelemetry: false, output)
{
}
}
Expand All @@ -49,7 +49,7 @@ public TraceAnnotationsVersionMismatchNewerNuGetTests(ITestOutputHelper output)
#if NETFRAMEWORK
: base("TraceAnnotations.VersionMismatch.NewerNuGet", twoAssembliesLoaded: true, output)
#else
: base("TraceAnnotations.VersionMismatch.NewerNuGet", twoAssembliesLoaded: false, output)
: base("TraceAnnotations.VersionMismatch.NewerNuGet", twoAssembliesLoaded: false, enableTelemetry: false, output)
#endif
{
}
Expand All @@ -61,13 +61,15 @@ public abstract class TraceAnnotationsTests : TestHelper
private static readonly string[] TestTypes = { "Samples.TraceAnnotations.TestType", "Samples.TraceAnnotations.TestTypeGeneric`1", "Samples.TraceAnnotations.TestTypeStruct", "Samples.TraceAnnotations.TestTypeStatic" };

private readonly bool _twoAssembliesLoaded;
private readonly bool _enableTelemetry;

public TraceAnnotationsTests(string sampleAppName, bool twoAssembliesLoaded, ITestOutputHelper output)
public TraceAnnotationsTests(string sampleAppName, bool twoAssembliesLoaded, bool enableTelemetry, ITestOutputHelper output)
: base(sampleAppName, output)
{
SetServiceVersion("1.0.0");

_twoAssembliesLoaded = twoAssembliesLoaded;
_enableTelemetry = enableTelemetry;
}

[Trait("Category", "EndToEnd")]
Expand All @@ -86,8 +88,10 @@ public async Task SubmitTraces()
ddTraceMethodsString += ";Samples.TraceAnnotations.ExtensionMethods[ExtensionMethodForTestType,ExtensionMethodForTestTypeGeneric,ExtensionMethodForTestTypeTypeStruct];System.Net.Http.HttpRequestMessage[set_Method]";

SetEnvironmentVariable("DD_TRACE_METHODS", ddTraceMethodsString);
// Don't bother with telemetry when two assemblies are loaded because we could get unreliable results
MockTelemetryAgent telemetry = _twoAssembliesLoaded ? null : this.ConfigureTelemetry();
// Don't bother with telemetry in version mismatch scenarios because older versions may only support V1 telemetry
// which we no longer support in our mock telemetry agent
// FIXME: Could be fixed with an upgrade to the NuGet package (after .NET 8?)
MockTelemetryAgent telemetry = _enableTelemetry ? this.ConfigureTelemetry() : null;
using (var agent = EnvironmentHelper.GetMockAgent())
using (RunSampleAndWaitForExit(agent))
{
Expand Down Expand Up @@ -158,8 +162,10 @@ await Verifier.Verify(orderedSpans, settings)
[Trait("RunOnWindows", "True")]
public void IntegrationDisabled()
{
// Don't bother with telemetry when two assemblies are loaded because we could get unreliable results
MockTelemetryAgent telemetry = _twoAssembliesLoaded ? null : this.ConfigureTelemetry();
// Don't bother with telemetry in version mismatch scenarios because older versions may only support V1 telemetry
// which we no longer support in our mock telemetry agent
// FIXME: Could be fixed with an upgrade to the NuGet package (after .NET 8?)
MockTelemetryAgent telemetry = _enableTelemetry ? this.ConfigureTelemetry() : null;
SetEnvironmentVariable("DD_TRACE_METHODS", string.Empty);
SetEnvironmentVariable("DD_TRACE_ANNOTATIONS_ENABLED", "false");

Expand Down

0 comments on commit ac7bb9d

Please sign in to comment.