-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup boilerplate for data-pipeline integration
- Loading branch information
Showing
20 changed files
with
645 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// <copyright file="ByteSlice.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Datadog.Trace.LibDatadog; | ||
|
||
/// <summary> | ||
/// Represents a slice of a byte array in memory. | ||
/// </summary> | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct ByteSlice | ||
{ | ||
/// <summary> | ||
/// Pointer to the start of the slice. | ||
/// </summary> | ||
internal IntPtr Ptr; | ||
|
||
/// <summary> | ||
/// Length of the slice. | ||
/// </summary> | ||
internal UIntPtr Len; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// <copyright file="CharSlice.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Datadog.Trace.LibDatadog; | ||
|
||
/// <summary> | ||
/// Represents a slice of a UTF-8 encoded string in memory. | ||
/// </summary> | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct CharSlice | ||
{ | ||
/// <summary> | ||
/// Represents an empty slice. | ||
/// </summary> | ||
internal static CharSlice Empty = new(string.Empty); | ||
|
||
/// <summary> | ||
/// Pointer to the start of the slice. | ||
/// </summary> | ||
internal IntPtr Ptr; | ||
|
||
/// <summary> | ||
/// Length of the slice. | ||
/// </summary> | ||
internal UIntPtr Len; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CharSlice"/> struct. | ||
/// This can be further optimized if we can avoid copying the string to unmanaged memory. | ||
/// </summary> | ||
/// <param name="str">The string to copy into memory.</param> | ||
internal CharSlice(string str) | ||
{ | ||
// copy over str to unmanaged memory | ||
if (str == null) | ||
{ | ||
Ptr = IntPtr.Zero; | ||
Len = UIntPtr.Zero; | ||
} | ||
else | ||
{ | ||
var bytes = System.Text.Encoding.UTF8.GetBytes(str); | ||
Ptr = Marshal.AllocHGlobal(bytes.Length); | ||
Marshal.Copy(bytes, 0, Ptr, bytes.Length); | ||
Len = (UIntPtr)bytes.Length; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// <copyright file="ErrorCode.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
namespace Datadog.Trace.LibDatadog; | ||
|
||
/// <summary> | ||
/// Represents error codes that can occur when exporting traces. | ||
/// </summary> | ||
internal enum ErrorCode | ||
{ | ||
AddressInUse = 0, | ||
ConnectionAborted = 1, | ||
ConnectionRefused = 2, | ||
ConnectionReset = 3, | ||
HttpBodyFormat = 4, | ||
HttpBodyTooLong = 5, | ||
HttpClient = 6, | ||
HttpParse = 7, | ||
HttpServer = 8, | ||
HttpUnknown = 9, | ||
HttpWrongStatus = 10, | ||
InvalidArgument = 11, | ||
InvalidData = 12, | ||
InvalidInput = 13, | ||
InvalidUrl = 14, | ||
IoError = 15, | ||
NetworkUnknown = 16, | ||
Serde = 17, | ||
TimedOut = 18, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// <copyright file="ErrorHandle.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Datadog.Trace.LibDatadog; | ||
|
||
internal class ErrorHandle : SafeHandle | ||
{ | ||
public ErrorHandle() | ||
: base(IntPtr.Zero, true) | ||
{ | ||
} | ||
|
||
public ErrorHandle(IntPtr handle) | ||
: base(handle, true) | ||
{ | ||
SetHandle(handle); | ||
} | ||
|
||
public override bool IsInvalid => handle == IntPtr.Zero; | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
TraceExporterNative.ddog_trace_exporter_error_free(handle); | ||
return true; | ||
} | ||
|
||
public TraceExporterException ToException() | ||
{ | ||
return new TraceExporterException(Marshal.PtrToStructure<TraceExporterError>(handle)); | ||
} | ||
|
||
public void ThrowIfError() | ||
{ | ||
if (!IsInvalid) | ||
{ | ||
throw ToException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// <copyright file="TraceExporter.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading.Tasks; | ||
using Datadog.Trace.Agent; | ||
|
||
namespace Datadog.Trace.LibDatadog; | ||
|
||
internal class TraceExporter : SafeHandle, IApi | ||
{ | ||
private readonly TraceExporterConfiguration _configuration; | ||
|
||
public TraceExporter(TraceExporterConfiguration configuration) | ||
: base(IntPtr.Zero, true) | ||
{ | ||
_configuration = configuration; | ||
var errPtr = TraceExporterNative.ddog_trace_exporter_new(out var ptr, configuration); | ||
errPtr.ThrowIfError(); | ||
SetHandle(ptr); | ||
} | ||
|
||
public override bool IsInvalid => handle == IntPtr.Zero; | ||
|
||
public Task<bool> SendTracesAsync(ArraySegment<byte> traces, int numberOfTraces, bool statsComputationEnabled, long numberOfDroppedP0Traces, long numberOfDroppedP0Spans, bool appsecStandaloneEnabled) | ||
{ | ||
// Pin the array to get a pointer to the data | ||
// This is recommended if using UnsafeAddrOfPinnedArrayElement to avoid the GC moving the array | ||
var tracesHandle = GCHandle.Alloc(traces.Array, GCHandleType.Pinned); | ||
var tracesSlice = new ByteSlice | ||
{ | ||
Ptr = Marshal.UnsafeAddrOfPinnedArrayElement(traces.Array, traces.Offset), | ||
Len = (UIntPtr)traces.Count | ||
}; | ||
|
||
var responsePtr = IntPtr.Zero; | ||
using var error = TraceExporterNative.ddog_trace_exporter_send(this, tracesSlice, (UIntPtr)numberOfTraces, ref responsePtr); | ||
tracesHandle.Free(); | ||
error.ThrowIfError(); | ||
|
||
return Task.FromResult(true); | ||
} | ||
|
||
public Task<bool> SendStatsAsync(StatsBuffer stats, long bucketDuration) | ||
{ | ||
return Task.FromResult(true); | ||
} | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
TraceExporterNative.ddog_trace_exporter_free(handle); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.