Skip to content

Commit

Permalink
[v3] Update OpenTracing library to use new public APIs (#5073)
Browse files Browse the repository at this point in the history
* Add OpenTracing sample app for running integration tests

* Update OpenTracing to use Datadog.Trace.Manual

* Migrate existing OpenTracing tests to integration tests

We can't run these as "basic" unit tests any more, because we require auto-instrumentation to function correctly.

* Delete old OpenTracing tests (as these are now implemented in the OpenTracing integration tests)

* Update OpenTracing public API

* Add OpenTracing project to trimming file and fix version generation

* Update opentracing source generators
  • Loading branch information
andrewlock committed May 30, 2024
1 parent 6eafd8d commit 22cf6f9
Show file tree
Hide file tree
Showing 42 changed files with 1,443 additions and 1,165 deletions.
1 change: 0 additions & 1 deletion Datadog.Trace.OSX.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"tracer\\test\\Datadog.Trace.Debugger.IntegrationTests\\Datadog.Trace.Debugger.IntegrationTests.csproj",
"tracer\\test\\Datadog.Trace.DuckTyping.Tests\\Datadog.Trace.DuckTyping.Tests.csproj",
"tracer\\test\\Datadog.Trace.IntegrationTests\\Datadog.Trace.IntegrationTests.csproj",
"tracer\\test\\Datadog.Trace.OpenTracing.IntegrationTests\\Datadog.Trace.OpenTracing.IntegrationTests.csproj",
"tracer\\test\\Datadog.Trace.OpenTracing.Tests\\Datadog.Trace.OpenTracing.Tests.csproj",
"tracer\\test\\Datadog.Trace.Security.IntegrationTests\\Datadog.Trace.Security.IntegrationTests.csproj",
"tracer\\test\\Datadog.Trace.Security.Unit.Tests\\Datadog.Trace.Security.Unit.Tests.csproj",
Expand Down
14 changes: 7 additions & 7 deletions Datadog.Trace.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Trace.OpenTracing",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Trace.OpenTracing.Tests", "tracer\test\Datadog.Trace.OpenTracing.Tests\Datadog.Trace.OpenTracing.Tests.csproj", "{3BCE5D99-147B-4305-9970-AB0F683A6E8D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Trace.OpenTracing.IntegrationTests", "tracer\test\Datadog.Trace.OpenTracing.IntegrationTests\Datadog.Trace.OpenTracing.IntegrationTests.csproj", "{EFBFC324-B459-4D39-8E19-CE4AD0DBF15F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Trace.TestHelpers", "tracer\test\Datadog.Trace.TestHelpers\Datadog.Trace.TestHelpers.csproj", "{237A1C92-DE9E-4649-961B-BBB7CF0DFE01}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FEBCE7DC-9FD1-48A6-B911-71ABB240A030}"
Expand Down Expand Up @@ -570,6 +568,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.Selenium", "tracer\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Trace.Manual", "tracer\src\Datadog.Trace.Manual\Datadog.Trace.Manual.csproj", "{D18A4340-268E-4EAA-8603-38EA998EBDF2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.OpenTracing", "tracer\test\test-applications\integrations\Samples.OpenTracing\Samples.OpenTracing.csproj", "{79A63F25-A5F9-441C-8C52-F8033A9F8ABA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.CIVisibilityIpc", "tracer\test\test-applications\integrations\Samples.CIVisibilityIpc\Samples.CIVisibilityIpc.csproj", "{BA9613FB-8458-4C78-98DE-AA45BBE62F64}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.CIVisibilityVersionMismatch", "tracer\test\test-applications\integrations\Samples.CIVisibilityVersionMismatch\Samples.CIVisibilityVersionMismatch.csproj", "{0D996EEE-7C04-4888-AF48-9C1E2F261A00}"
Expand Down Expand Up @@ -608,10 +608,6 @@ Global
{3BCE5D99-147B-4305-9970-AB0F683A6E8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BCE5D99-147B-4305-9970-AB0F683A6E8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BCE5D99-147B-4305-9970-AB0F683A6E8D}.Release|Any CPU.Build.0 = Release|Any CPU
{EFBFC324-B459-4D39-8E19-CE4AD0DBF15F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFBFC324-B459-4D39-8E19-CE4AD0DBF15F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFBFC324-B459-4D39-8E19-CE4AD0DBF15F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFBFC324-B459-4D39-8E19-CE4AD0DBF15F}.Release|Any CPU.Build.0 = Release|Any CPU
{237A1C92-DE9E-4649-961B-BBB7CF0DFE01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{237A1C92-DE9E-4649-961B-BBB7CF0DFE01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{237A1C92-DE9E-4649-961B-BBB7CF0DFE01}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -1370,6 +1366,10 @@ Global
{D18A4340-268E-4EAA-8603-38EA998EBDF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D18A4340-268E-4EAA-8603-38EA998EBDF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D18A4340-268E-4EAA-8603-38EA998EBDF2}.Release|Any CPU.Build.0 = Release|Any CPU
{79A63F25-A5F9-441C-8C52-F8033A9F8ABA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79A63F25-A5F9-441C-8C52-F8033A9F8ABA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79A63F25-A5F9-441C-8C52-F8033A9F8ABA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79A63F25-A5F9-441C-8C52-F8033A9F8ABA}.Release|Any CPU.Build.0 = Release|Any CPU
{BA9613FB-8458-4C78-98DE-AA45BBE62F64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA9613FB-8458-4C78-98DE-AA45BBE62F64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA9613FB-8458-4C78-98DE-AA45BBE62F64}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -1390,7 +1390,6 @@ Global
{0434F813-5F94-4195-8A2C-E2E755513822} = {8CEC2042-F11C-49F5-A674-2355793B600A}
{188219D1-D123-46C9-B905-A9ED30E6AAA7} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB}
{3BCE5D99-147B-4305-9970-AB0F683A6E8D} = {8CEC2042-F11C-49F5-A674-2355793B600A}
{EFBFC324-B459-4D39-8E19-CE4AD0DBF15F} = {8CEC2042-F11C-49F5-A674-2355793B600A}
{237A1C92-DE9E-4649-961B-BBB7CF0DFE01} = {8CEC2042-F11C-49F5-A674-2355793B600A}
{3C6DD42E-9214-4747-92BA-78DE29AACE59} = {AFA0AB23-64F0-4AC1-9050-6CE8FE06F580}
{5728056A-51AA-4FF5-AD0C-E86E44E36102} = {8CEC2042-F11C-49F5-A674-2355793B600A}
Expand Down Expand Up @@ -1600,6 +1599,7 @@ Global
{0F1D9FB5-4415-40F1-B7B0-6DD5A3BAB0C4} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
{32193A01-04DD-463B-A84A-9A93167958A4} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
{D18A4340-268E-4EAA-8603-38EA998EBDF2} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB}
{79A63F25-A5F9-441C-8C52-F8033A9F8ABA} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
{BA9613FB-8458-4C78-98DE-AA45BBE62F64} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
{0D996EEE-7C04-4888-AF48-9C1E2F261A00} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
EndGlobalSection
Expand Down
1 change: 0 additions & 1 deletion tracer/build/_build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ IEnumerable<MSBuildTargetPlatform> ArchitecturesForPlatformForProfiler
Project[] ParallelIntegrationTests => new[]
{
Solution.GetProject(Projects.TraceIntegrationTests),
Solution.GetProject(Projects.OpenTracingIntegrationTests),
};

Project[] ClrProfilerIntegrationTests
Expand Down
1 change: 1 addition & 0 deletions tracer/build/_build/Honeypot/IntegrationGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static IntegrationMap()

// Manual instrumentation
NugetPackages.Add("Datadog.Trace.Manual", new string[] { });
NugetPackages.Add("Datadog.Trace.OpenTracing", new string[] { });
}

private IntegrationMap()
Expand Down
1 change: 0 additions & 1 deletion tracer/build/_build/Projects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static class Projects
public const string TraceIntegrationTests = "Datadog.Trace.IntegrationTests";
public const string AppSecUnitTests = "Datadog.Trace.Security.Unit.Tests";
public const string AppSecIntegrationTests = "Datadog.Trace.Security.IntegrationTests";
public const string OpenTracingIntegrationTests = "Datadog.Trace.OpenTracing.IntegrationTests";
public const string ClrProfilerIntegrationTests = "Datadog.Trace.ClrProfiler.IntegrationTests";
public const string DdTraceIntegrationTests = "Datadog.Trace.Tools.Runner.IntegrationTests";
public const string DdTraceArtifactsTests = "Datadog.Trace.Tools.Runner.ArtifactTests";
Expand Down
2 changes: 2 additions & 0 deletions tracer/src/Datadog.Trace.Manual/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
[assembly: Datadog.Trace.Ci.Coverage.Attributes.AvoidCoverage]

[assembly: InternalsVisibleTo("Datadog.Trace.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010025b855c8bc41b1d47e777fc247392999ca6f553cdb030fac8e3bd010171ded9982540d988553935f44f7dd58cb4b17fbb92653d5c2dc5112696886665b317c6f92795bf64beab2405c501c8a30cb1b31b1541ed66e27d9823169ec2815b00ceeeecc8d5a1bf43db67d2961a3e9bea1397f043ec07491709649252f5565b756c5")]
[assembly: InternalsVisibleTo("Datadog.Trace.OpenTracing, PublicKey=002400000480000094000000060200000024000052534131000400000100010025b855c8bc41b1d47e777fc247392999ca6f553cdb030fac8e3bd010171ded9982540d988553935f44f7dd58cb4b17fbb92653d5c2dc5112696886665b317c6f92795bf64beab2405c501c8a30cb1b31b1541ed66e27d9823169ec2815b00ceeeecc8d5a1bf43db67d2961a3e9bea1397f043ec07491709649252f5565b756c5")]
[assembly: InternalsVisibleTo("Datadog.Trace.OpenTracing.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010025b855c8bc41b1d47e777fc247392999ca6f553cdb030fac8e3bd010171ded9982540d988553935f44f7dd58cb4b17fbb92653d5c2dc5112696886665b317c6f92795bf64beab2405c501c8a30cb1b31b1541ed66e27d9823169ec2815b00ceeeecc8d5a1bf43db67d2961a3e9bea1397f043ec07491709649252f5565b756c5")]

// Sanity check for _OR_GREATER compiler directives
#if !NETCOREAPP3_1_OR_GREATER && !NET461_OR_GREATER && !NETSTANDARD2_0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Compile Include="..\Datadog.Trace\ClrProfiler\AutoInstrumentation\ManualInstrumentation\TracerSettingKeyConstants.cs" Link="Configuration\%(Filename)%(Extension)" />
<Compile Include="..\Datadog.Trace\Configuration\DeprecationMessages.cs" Link="Configuration\%(Filename)%(Extension)" />
<Compile Include="..\Datadog.Trace\HttpHeaderNames.cs" />
<Compile Include="..\Datadog.Trace\IDatadogOpenTracingTracer.cs" />
<Compile Include="..\Datadog.Trace\IScope.cs" />
<Compile Include="..\Datadog.Trace\ISpan.cs" />
<Compile Include="..\Datadog.Trace\ISpanContext.cs" />
Expand Down
15 changes: 14 additions & 1 deletion tracer/src/Datadog.Trace.Manual/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Datadog.Trace
/// <summary>
/// The tracer is responsible for creating spans and flushing them to the Datadog agent
/// </summary>
public sealed class Tracer : ITracer
public sealed class Tracer : ITracer, IDatadogOpenTracingTracer
{
private static Tracer? _instance;

Expand Down Expand Up @@ -120,5 +120,18 @@ private static void Configure(Dictionary<string, object?> settings)
[Instrumented]
private IScope StartActive(string operationName, ISpanContext? parent, string? serviceName, DateTimeOffset? startTime, bool? finishOnClose)
=> NullScope.Instance;

/// <summary>
/// Creates a new <see cref="ISpan"/> with the specified parameters.
/// </summary>
/// <param name="operationName">The span's operation name</param>
/// <param name="parent">The span's parent</param>
/// <param name="serviceName">The span's service name</param>
/// <param name="startTime">An explicit start time for that span</param>
/// <param name="ignoreActiveScope">If set the span will not be a child of the currently active span</param>
/// <returns>The newly created span</returns>
[Instrumented]
ISpan IDatadogOpenTracingTracer.StartSpan(string operationName, ISpanContext? parent, string serviceName, DateTimeOffset? startTime, bool ignoreActiveScope)
=> NullSpan.Instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Datadog.Trace\Datadog.Trace.csproj" />
<ProjectReference Include="..\Datadog.Trace.Manual\Datadog.Trace.Manual.csproj" />

<PackageReference Include="OpenTracing" Version="0.12.1" />
</ItemGroup>
Expand Down
27 changes: 17 additions & 10 deletions tracer/src/Datadog.Trace.OpenTracing/HttpHeadersCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using System;
using System.Globalization;
using Datadog.Trace.Headers;
using Datadog.Trace.Propagators;
using OpenTracing.Propagation;

namespace Datadog.Trace.OpenTracing
{
internal class HttpHeadersCodec : ICodec
{
private static readonly CultureInfo InvariantCulture = CultureInfo.InvariantCulture;
private static readonly SpanContextExtractor Extractor = new();
private static readonly SpanContextInjector Injector = new();

public global::OpenTracing.ISpanContext Extract(object carrier)
{
Expand All @@ -24,9 +23,19 @@ internal class HttpHeadersCodec : ICodec
throw new ArgumentException("Carrier should have type ITextMap", nameof(carrier));
}

IHeadersCollection headers = new TextMapHeadersCollection(map);
var propagationContext = SpanContextPropagator.Instance.Extract(headers);
var propagationContext = Extractor.Extract(map, GetValues);
return new OpenTracingSpanContext(propagationContext);

static IEnumerable<string> GetValues(ITextMap textMap, string name)
{
foreach (var pair in textMap)
{
if (string.Equals(pair.Key, name, StringComparison.OrdinalIgnoreCase))
{
yield return pair.Value;
}
}
}
}

public void Inject(global::OpenTracing.ISpanContext context, object carrier)
Expand All @@ -38,18 +47,16 @@ public void Inject(global::OpenTracing.ISpanContext context, object carrier)
throw new ArgumentException("Carrier should have type ITextMap", nameof(carrier));
}

IHeadersCollection headers = new TextMapHeadersCollection(map);

if (context is OpenTracingSpanContext otSpanContext && otSpanContext.Context is SpanContext ddSpanContext)
{
// this is a Datadog context
SpanContextPropagator.Instance.Inject(ddSpanContext, headers);
Injector.Inject(map, (carrier, name, value) => carrier.Set(name, value), ddSpanContext);
}
else
{
// any other OpenTracing.ISpanContext
headers.Set(HttpHeaderNames.TraceId, context.TraceId.ToString(InvariantCulture));
headers.Set(HttpHeaderNames.ParentId, context.SpanId.ToString(InvariantCulture));
map.Set(HttpHeaderNames.TraceId, context.TraceId.ToString(InvariantCulture));
map.Set(HttpHeaderNames.ParentId, context.SpanId.ToString(InvariantCulture));
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions tracer/src/Datadog.Trace.OpenTracing/OpenTracingSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using System;
using System.Collections.Generic;
using System.Globalization;
using OpenTracing;
using OpenTracing.Tag;

namespace Datadog.Trace.OpenTracing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using System;
using System.Collections.Generic;
using System.Globalization;
using Datadog.Trace.Logging;
using Datadog.Trace.Telemetry;
using Datadog.Trace.Telemetry.Metrics;
using OpenTracing;
using OpenTracing.Tag;

namespace Datadog.Trace.OpenTracing
{
internal class OpenTracingSpanBuilder : ISpanBuilder
{
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor<OpenTracingSpanBuilder>();

private readonly OpenTracingTracer _tracer;
private readonly object _lock = new object();
private readonly string _operationName;
Expand All @@ -44,7 +37,6 @@ public ISpanBuilder AddReference(string referenceType, global::OpenTracing.ISpan
}
}

Log.Debug("ISpanBuilder.AddReference is not implemented for other references than ChildOf by Datadog.Trace");
return this;
}

Expand Down Expand Up @@ -77,7 +69,6 @@ public ISpanBuilder IgnoreActiveSpan()
lock (_lock)
{
ISpanContext parentContext = GetParentContext();
TelemetryFactory.Metrics.RecordCountSpanCreated(MetricTags.IntegrationName.OpenTracing);
ISpan ddSpan = _tracer.DatadogTracer.StartSpan(_operationName, parentContext, _serviceName, _start, _ignoreActiveSpan);
var otSpan = new OpenTracingSpan(ddSpan);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Datadog.Trace.Logging;

namespace Datadog.Trace.OpenTracing
{
internal class OpenTracingSpanContext : global::OpenTracing.ISpanContext
{
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor<OpenTracingSpanContext>();

public OpenTracingSpanContext(ISpanContext context)
{
Context = context;
Expand Down
22 changes: 0 additions & 22 deletions tracer/src/Datadog.Trace.OpenTracing/OpenTracingTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,15 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using System;
using System.Collections.Generic;
using Datadog.Trace.Logging;
using Datadog.Trace.SourceGenerators;
using Datadog.Trace.Telemetry;
using Datadog.Trace.Telemetry.Metrics;
using OpenTracing;
using OpenTracing.Propagation;

namespace Datadog.Trace.OpenTracing
{
internal class OpenTracingTracer : global::OpenTracing.ITracer
{
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor<OpenTracingTracer>();

private readonly Dictionary<string, ICodec> _codecs;

[PublicApi]
public OpenTracingTracer(IDatadogOpenTracingTracer datadogTracer)
: this(datadogTracer, CreateDefaultScopeManager(), datadogTracer.DefaultServiceName)
{
TelemetryFactory.Metrics.Record(PublicApiUsage.OpenTracingTracer_Ctor_DatadogTracer);
}

[PublicApi]
public OpenTracingTracer(IDatadogOpenTracingTracer datadogTracer, global::OpenTracing.IScopeManager scopeManager)
: this(datadogTracer, scopeManager, datadogTracer.DefaultServiceName)
{
TelemetryFactory.Metrics.Record(PublicApiUsage.OpenTracingTracer_Ctor_DatadogTracer_ScopeManager);
}

internal OpenTracingTracer(
IDatadogOpenTracingTracer datadogTracer,
global::OpenTracing.IScopeManager scopeManager,
Expand Down
Loading

0 comments on commit 22cf6f9

Please sign in to comment.