Skip to content

Commit

Permalink
[v3] Change manual instrumentation approach to not use reverse duck-t…
Browse files Browse the repository at this point in the history
…yping (#5214)

* Fix null ref in `GetManagedTracerVersion()`

* Add benchmark for manual instrumentation

* Try alternative ducktyping approach

* Fix OpenTracing helpers

* Revert the changes to benchmark stat types

Seeing as we're not reverse duck-typing any more, we don't need to do this

* Update manual Ci Visibility to not rely on reverse duck-typing

This is made rather irritating by the fact we _can't_ ducktype Test as an ITest. That, coupled with the APIs that connect module + suite + test together means we need to duplicate the interfaces in their entirety.

It seems to work though 🎉

* Revert the snapshots to match the existing public API

* Use instrumentation of DuckType.DuckCast<T> in Datadog.Trace.Manual.csproj

Means we can avoid having to include the whole DuckTyping library inside Datadog.Trace.Manual
The downside is that it's hard to test in unit tests. as everything requires auto instrumentation

* Skip the duck typing tests that won't work and add some others

* Simplify the implementation

Instead of having wrapper ManualScope implementations etc, we can just use duck typing instead directly. This reduces one level of indirection and reduces the allocations

* Redesign approach with CI Visibility

- Use the standard duck typing approach instead of reverse duck typing
- Remove the ManualTest etc
- Move methods that we _can't_ duck type to be extension methods that we instrument

* Update generated code

* Apply suggestions from code review

Co-authored-by: Kevin Gosse <kevin.gosse@datadoghq.com>

* PR feedback

- Fix previous PR feedback suggestions ;)
- Add [Instrumented] to Tracer.ctor
- Fix merge conflict in IntegrationIdExtensions
- Add missing telemetry integration
- Move TracerSettingsPopulateDictionaryIntegration into correct folder, and rename to PopulateDictionaryIntegration
- Add a unit test for SetTag

* Add unit tests for the mapping between tracersettings and public API settings

* PR Feedback - add helper class for serialization of integration settings

* PR feedback - include initial value in OverrideValue<T> helper

* PR feedback - too many braces

* Fix bug introduced

* Use defaults for null test suite

* Fix merge conflict

---------

Co-authored-by: Kevin Gosse <kevin.gosse@datadoghq.com>
  • Loading branch information
andrewlock and kevingosse committed Jul 1, 2024
1 parent 4326f67 commit b84690f
Show file tree
Hide file tree
Showing 71 changed files with 4,272 additions and 4,454 deletions.
160 changes: 0 additions & 160 deletions tracer/src/Datadog.Trace.Manual/Ci/BenchmarkDiscreteStats.cs

This file was deleted.

62 changes: 0 additions & 62 deletions tracer/src/Datadog.Trace.Manual/Ci/BenchmarkHostInfo.cs

This file was deleted.

37 changes: 0 additions & 37 deletions tracer/src/Datadog.Trace.Manual/Ci/BenchmarkJobInfo.cs

This file was deleted.

21 changes: 0 additions & 21 deletions tracer/src/Datadog.Trace.Manual/Ci/ITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,6 @@ public interface ITest
/// <param name="traits">Traits dictionary</param>
void SetTraits(Dictionary<string, List<string>> traits);

/// <summary>
/// Set Test parameters
/// </summary>
/// <param name="parameters">TestParameters instance</param>
void SetParameters(TestParameters parameters);

/// <summary>
/// Set benchmark metadata
/// </summary>
/// <param name="hostInfo">Host info</param>
/// <param name="jobInfo">Job info</param>
void SetBenchmarkMetadata(BenchmarkHostInfo hostInfo, BenchmarkJobInfo jobInfo);

/// <summary>
/// Add benchmark data
/// </summary>
/// <param name="measureType">Measure type</param>
/// <param name="info">Measure info</param>
/// <param name="statistics">Statistics values</param>
void AddBenchmarkData(BenchmarkMeasureType measureType, string info, BenchmarkDiscreteStats statistics);

/// <summary>
/// Close test
/// </summary>
Expand Down
26 changes: 10 additions & 16 deletions tracer/src/Datadog.Trace.Manual/Ci/Stubs/NullTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@

namespace Datadog.Trace.Ci.Stubs;

internal class NullTest(ITestSuite testSuite, string name, DateTimeOffset? startDate) : ITest
internal class NullTest : ITest
{
public string? Name { get; } = name;
public static readonly NullTest Instance = new();

public DateTimeOffset StartTime { get; } = startDate ?? DateTimeOffset.UtcNow;
private NullTest()
{
}

public string? Name => "Undefined";

public DateTimeOffset StartTime => default;

public ITestSuite Suite { get; } = testSuite;
public ITestSuite Suite => NullTestSuite.Instance;

public void SetTag(string key, string? value)
{
Expand All @@ -41,18 +47,6 @@ public void SetTraits(Dictionary<string, List<string>> traits)
{
}

public void SetParameters(TestParameters parameters)
{
}

public void SetBenchmarkMetadata(BenchmarkHostInfo hostInfo, BenchmarkJobInfo jobInfo)
{
}

public void AddBenchmarkData(BenchmarkMeasureType measureType, string info, BenchmarkDiscreteStats statistics)
{
}

public void Close(TestStatus status)
{
}
Expand Down
20 changes: 12 additions & 8 deletions tracer/src/Datadog.Trace.Manual/Ci/Stubs/NullTestModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@

namespace Datadog.Trace.Ci.Stubs;

internal class NullTestModule(string name, string? framework, DateTimeOffset? startDate) : ITestModule
internal class NullTestModule : ITestModule
{
public string Name { get; } = name;
public static readonly NullTestModule Instance = new();

public DateTimeOffset StartTime { get; } = startDate ?? DateTimeOffset.UtcNow;
private NullTestModule()
{
}

public string Name => "Undefined";

public DateTimeOffset StartTime => default;

public string? Framework { get; } = framework;
public string? Framework => null;

public void SetTag(string key, string? value)
{
Expand Down Expand Up @@ -41,9 +47,7 @@ public void Close(TimeSpan? duration)

public Task CloseAsync(TimeSpan? duration) => Task.CompletedTask;

public ITestSuite GetOrCreateSuite(string name)
=> new NullTestSuite(this, name, null);
public ITestSuite GetOrCreateSuite(string name) => NullTestSuite.Instance;

public ITestSuite GetOrCreateSuite(string name, DateTimeOffset? startDate)
=> new NullTestSuite(this, name, startDate);
public ITestSuite GetOrCreateSuite(string name, DateTimeOffset? startDate) => NullTestSuite.Instance;
}
Loading

0 comments on commit b84690f

Please sign in to comment.