Skip to content

Commit 067753f

Browse files
committed
feat: setup boilerplate for data-pipeline integration
1 parent c48a1f7 commit 067753f

20 files changed

+659
-15
lines changed

tracer/build/_build/Build.Steps.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ async Task DownloadWafVersion(string libddwafVersion = null, string uncompressFo
624624
.SetConfiguration(BuildConfiguration)
625625
.SetTargetPlatformAnyCPU()
626626
.EnableNoBuild()
627-
.EnableNoRestore()
627+
//.EnableNoRestore()
628628
.CombineWith(targetFrameworks, (p, framework) => p
629629
.SetFramework(framework)
630630
.SetOutput(MonitoringHomeDirectory / framework))
@@ -1365,7 +1365,7 @@ _ when path.Contains("dependency-libs") => false,
13651365
.Where(project => Solution.GetProject(project).GetTargetFrameworks().Contains(Framework))
13661366
;
13671367

1368-
DotnetBuild(projects, framework: Framework);
1368+
DotnetBuild(projects, framework: Framework, noRestore: false);
13691369
});
13701370

13711371
Target CompileSamplesWindows => _ => _
@@ -1567,8 +1567,8 @@ _ when exclude.Contains(x.project.Path) => false,
15671567
.SetFramework(Framework)
15681568
//.WithMemoryDumpAfter(timeoutInMinutes: 30)
15691569
.EnableCrashDumps()
1570-
.EnableNoRestore()
1571-
.EnableNoBuild()
1570+
// .EnableNoRestore()
1571+
// .EnableNoBuild()
15721572
.SetTestTargetPlatform(TargetPlatform)
15731573
.SetIsDebugRun(isDebugRun)
15741574
.SetProcessEnvironmentVariable("MonitoringHomeDirectory", MonitoringHomeDirectory)
@@ -1590,8 +1590,8 @@ _ when exclude.Contains(x.project.Path) => false,
15901590
.SetTargetPlatformAnyCPU()
15911591
.SetFramework(Framework)
15921592
//.WithMemoryDumpAfter(timeoutInMinutes: 30)
1593-
.EnableNoRestore()
1594-
.EnableNoBuild()
1593+
// .EnableNoRestore()
1594+
// .EnableNoBuild()
15951595
.SetFilter(string.IsNullOrWhiteSpace(Filter) ? "(RunOnWindows=True)&(LoadFromGAC!=True)&(IIS!=True)&(Category!=AzureFunctions)&(SkipInCI!=True)" : Filter)
15961596
.SetTestTargetPlatform(TargetPlatform)
15971597
.SetIsDebugRun(isDebugRun)
@@ -2104,8 +2104,8 @@ var name when multiPackageProjects.Contains(name) => false,
21042104
// Run these ones in parallel
21052105
DotNetTest(config => config
21062106
.SetConfiguration(BuildConfiguration)
2107-
.EnableNoRestore()
2108-
.EnableNoBuild()
2107+
// .EnableNoRestore()
2108+
// .EnableNoBuild()
21092109
.SetFramework(Framework)
21102110
//.WithMemoryDumpAfter(timeoutInMinutes: 30)
21112111
.EnableCrashDumps()
@@ -2127,8 +2127,8 @@ var name when multiPackageProjects.Contains(name) => false,
21272127
// Run this one separately so we can tail output
21282128
DotNetTest(config => config
21292129
.SetConfiguration(BuildConfiguration)
2130-
.EnableNoRestore()
2131-
.EnableNoBuild()
2130+
// .EnableNoRestore()
2131+
// .EnableNoBuild()
21322132
.SetFramework(Framework)
21332133
//.WithMemoryDumpAfter(timeoutInMinutes: 30)
21342134
.EnableCrashDumps()
@@ -2185,8 +2185,8 @@ var name when multiPackageProjects.Contains(name) => false,
21852185
// Run these ones in parallel
21862186
DotNetTest(config => config
21872187
.SetConfiguration(BuildConfiguration)
2188-
.EnableNoRestore()
2189-
.EnableNoBuild()
2188+
// .EnableNoRestore()
2189+
// .EnableNoBuild()
21902190
.SetFramework(Framework)
21912191
//.WithMemoryDumpAfter(timeoutInMinutes: 30)
21922192
.EnableCrashDumps()
@@ -2209,8 +2209,8 @@ var name when multiPackageProjects.Contains(name) => false,
22092209
// Run this one separately so we can tail output
22102210
DotNetTest(config => config
22112211
.SetConfiguration(BuildConfiguration)
2212-
.EnableNoRestore()
2213-
.EnableNoBuild()
2212+
// .EnableNoRestore()
2213+
// .EnableNoBuild()
22142214
.SetFramework(Framework)
22152215
//.WithMemoryDumpAfter(timeoutInMinutes: 30)
22162216
.EnableCrashDumps()

tracer/missing-nullability-files.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ src/Datadog.Trace/HttpOverStreams/IHttpContent.cs
141141
src/Datadog.Trace/Iast/Iast.cs
142142
src/Datadog.Trace/Iast/ITaintedMap.cs
143143
src/Datadog.Trace/Iast/SourceType.cs
144+
src/Datadog.Trace/LibDatadog/ByteSlice.cs
145+
src/Datadog.Trace/LibDatadog/CharSlice.cs
146+
src/Datadog.Trace/LibDatadog/ErrorCode.cs
147+
src/Datadog.Trace/LibDatadog/ErrorHandle.cs
148+
src/Datadog.Trace/LibDatadog/TraceExporter.cs
149+
src/Datadog.Trace/LibDatadog/TraceExporterConfiguration.cs
150+
src/Datadog.Trace/LibDatadog/TraceExporterError.cs
151+
src/Datadog.Trace/LibDatadog/TraceExporterException.cs
152+
src/Datadog.Trace/LibDatadog/TraceExporterInputFormat.cs
153+
src/Datadog.Trace/LibDatadog/TraceExporterNative.cs
154+
src/Datadog.Trace/LibDatadog/TraceExporterOutputFormat.cs
144155
src/Datadog.Trace/PlatformHelpers/AspNetCoreHttpRequestHandler.cs
145156
src/Datadog.Trace/PlatformHelpers/AzureContext.cs
146157
src/Datadog.Trace/PlatformHelpers/ContainerMetadata.cs

tracer/src/Datadog.Trace/Agent/AgentWriter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ internal AgentWriter(IApi api, IStatsAggregator statsAggregator, IDogStatsd stat
9797
_appsecStandaloneEnabled = appsecStandaloneEnabled;
9898
}
9999

100+
~AgentWriter()
101+
{
102+
if (_api is IDisposable disposableApi)
103+
{
104+
disposableApi.Dispose();
105+
}
106+
}
107+
100108
internal event Action Flushed;
101109

102110
internal SpanBuffer ActiveBuffer => _activeBuffer;

tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ internal static partial class ConfigurationKeys
253253
/// </summary>
254254
public const string RuntimeMetricsEnabled = "DD_RUNTIME_METRICS_ENABLED";
255255

256+
/// <summary>
257+
/// Use libdatadog data pipeline to send traces.
258+
/// Default value is <c>false</c> (disabled).
259+
/// </summary>
260+
public const string DataPipelineEnabled = "DD_DATA_PIPELINE_ENABLED";
261+
256262
/// <summary>
257263
/// Configuration key for when a standalone instance of the Trace Agent needs to be started.
258264
/// </summary>

tracer/src/Datadog.Trace/Configuration/TracerSettings.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public record TracerSettings
5252
private readonly double? _globalSamplingRate;
5353
private readonly bool _runtimeMetricsEnabled;
5454
private readonly string? _customSamplingRules;
55+
private readonly bool _dataPipelineEnabled;
5556

5657
/// <summary>
5758
/// Initializes a new instance of the <see cref="TracerSettings"/> class with default values.
@@ -331,6 +332,10 @@ _ when x.ToBoolean() is { } boolean => boolean,
331332
.AsBoolResult()
332333
.OverrideWith(in otelRuntimeMetricsEnabled, ErrorLog, defaultValue: false);
333334

335+
_dataPipelineEnabled = config
336+
.WithKeys(ConfigurationKeys.DataPipelineEnabled)
337+
.AsBool(defaultValue: true);
338+
334339
// We should also be writing telemetry for OTEL_LOGS_EXPORTER similar to OTEL_METRICS_EXPORTER, but we don't have a corresponding Datadog config
335340
// When we do, we can insert that here
336341

@@ -919,6 +924,12 @@ public bool DiagnosticSourceEnabled
919924
/// </summary>
920925
internal bool RuntimeMetricsEnabled => DynamicSettings.RuntimeMetricsEnabled ?? _runtimeMetricsEnabled;
921926

927+
/// <summary>
928+
/// Gets a value indicating whether libdatadog data pipeline
929+
/// is enabled.
930+
/// </summary>
931+
internal bool DataPipelineEnabled => _dataPipelineEnabled;
932+
922933
/// <summary>
923934
/// Gets the comma separated list of url patterns to skip tracing.
924935
/// </summary>

tracer/src/Datadog.Trace/Datadog.Trace.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<PrivateAssets>all</PrivateAssets>
5555
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5656
</PackageReference>
57+
<PackageReference Include="ganeshnj.libdatadog" Version="14.3.1-ci.771.163" />
5758
<PackageReference Include="InlineIL.Fody" Version="1.8.0" PrivateAssets="All" />
5859
</ItemGroup>
5960

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// <copyright file="ByteSlice.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
using System;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Datadog.Trace.LibDatadog;
10+
11+
/// <summary>
12+
/// Represents a slice of a byte array in memory.
13+
/// </summary>
14+
[StructLayout(LayoutKind.Sequential)]
15+
internal struct ByteSlice
16+
{
17+
/// <summary>
18+
/// Pointer to the start of the slice.
19+
/// </summary>
20+
internal IntPtr Ptr;
21+
22+
/// <summary>
23+
/// Length of the slice.
24+
/// </summary>
25+
internal UIntPtr Len;
26+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// <copyright file="CharSlice.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
using System;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Datadog.Trace.LibDatadog;
10+
11+
/// <summary>
12+
/// Represents a slice of a UTF-8 encoded string in memory.
13+
/// </summary>
14+
[StructLayout(LayoutKind.Sequential)]
15+
internal struct CharSlice
16+
{
17+
/// <summary>
18+
/// Represents an empty slice.
19+
/// </summary>
20+
internal static CharSlice Empty = new(string.Empty);
21+
22+
/// <summary>
23+
/// Pointer to the start of the slice.
24+
/// </summary>
25+
internal IntPtr Ptr;
26+
27+
/// <summary>
28+
/// Length of the slice.
29+
/// </summary>
30+
internal UIntPtr Len;
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="CharSlice"/> struct.
34+
/// This can be further optimized if we can avoid copying the string to unmanaged memory.
35+
/// </summary>
36+
/// <param name="str">The string to copy into memory.</param>
37+
internal CharSlice(string str)
38+
{
39+
// copy over str to unmanaged memory
40+
if (str == null)
41+
{
42+
Ptr = IntPtr.Zero;
43+
Len = UIntPtr.Zero;
44+
}
45+
else
46+
{
47+
var bytes = System.Text.Encoding.UTF8.GetBytes(str);
48+
Ptr = Marshal.AllocHGlobal(bytes.Length);
49+
Marshal.Copy(bytes, 0, Ptr, bytes.Length);
50+
Len = (UIntPtr)bytes.Length;
51+
}
52+
}
53+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// <copyright file="ErrorCode.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
namespace Datadog.Trace.LibDatadog;
7+
8+
/// <summary>
9+
/// Represents error codes that can occur when exporting traces.
10+
/// </summary>
11+
internal enum ErrorCode
12+
{
13+
AddressInUse = 0,
14+
ConnectionAborted = 1,
15+
ConnectionRefused = 2,
16+
ConnectionReset = 3,
17+
HttpBodyFormat = 4,
18+
HttpBodyTooLong = 5,
19+
HttpClient = 6,
20+
HttpParse = 7,
21+
HttpServer = 8,
22+
HttpUnknown = 9,
23+
HttpWrongStatus = 10,
24+
InvalidArgument = 11,
25+
InvalidData = 12,
26+
InvalidInput = 13,
27+
InvalidUrl = 14,
28+
IoError = 15,
29+
NetworkUnknown = 16,
30+
Serde = 17,
31+
TimedOut = 18,
32+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// <copyright file="ErrorHandle.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
using System;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Datadog.Trace.LibDatadog;
10+
11+
internal class ErrorHandle : SafeHandle
12+
{
13+
public ErrorHandle()
14+
: base(IntPtr.Zero, true)
15+
{
16+
}
17+
18+
public ErrorHandle(IntPtr handle)
19+
: base(handle, true)
20+
{
21+
SetHandle(handle);
22+
}
23+
24+
public override bool IsInvalid => handle == IntPtr.Zero;
25+
26+
protected override bool ReleaseHandle()
27+
{
28+
TraceExporterNative.ddog_trace_exporter_error_free(handle);
29+
return true;
30+
}
31+
32+
public TraceExporterException ToException()
33+
{
34+
return new TraceExporterException(Marshal.PtrToStructure<TraceExporterError>(handle));
35+
}
36+
37+
public void ThrowIfError()
38+
{
39+
if (!IsInvalid)
40+
{
41+
throw ToException();
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)