Skip to content

Commit

Permalink
Update project OpenTelemetry.Exporter.Jaeger to use file scoped names…
Browse files Browse the repository at this point in the history
…paces (#4684)
  • Loading branch information
jarosal authored Jul 22, 2023
1 parent 8de6e69 commit 0f9f507
Show file tree
Hide file tree
Showing 26 changed files with 2,589 additions and 2,615 deletions.
89 changes: 44 additions & 45 deletions src/OpenTelemetry.Exporter.Jaeger/Implementation/Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,66 @@
using Thrift.Protocol;
using Thrift.Protocol.Entities;

namespace OpenTelemetry.Exporter.Jaeger.Implementation
namespace OpenTelemetry.Exporter.Jaeger.Implementation;

internal sealed class Batch
{
internal sealed class Batch
public Batch(Process process, TProtocol protocol)
{
public Batch(Process process, TProtocol protocol)
{
this.BatchBeginMessage = GenerateBeginMessage(process, protocol, out int spanCountPosition);
this.SpanCountPosition = spanCountPosition;
this.BatchEndMessage = GenerateEndMessage(protocol);
}
this.BatchBeginMessage = GenerateBeginMessage(process, protocol, out int spanCountPosition);
this.SpanCountPosition = spanCountPosition;
this.BatchEndMessage = GenerateEndMessage(protocol);
}

public byte[] BatchBeginMessage { get; }
public byte[] BatchBeginMessage { get; }

public int SpanCountPosition { get; set; }
public int SpanCountPosition { get; set; }

public byte[] BatchEndMessage { get; }
public byte[] BatchEndMessage { get; }

public int MinimumMessageSize => this.BatchBeginMessage.Length
+ this.BatchEndMessage.Length;
public int MinimumMessageSize => this.BatchBeginMessage.Length
+ this.BatchEndMessage.Length;

private static byte[] GenerateBeginMessage(Process process, TProtocol oprot, out int spanCountPosition)
{
var struc = new TStruct("Batch");
private static byte[] GenerateBeginMessage(Process process, TProtocol oprot, out int spanCountPosition)
{
var struc = new TStruct("Batch");

oprot.WriteStructBegin(struc);
oprot.WriteStructBegin(struc);

var field = new TField
{
Name = "process",
Type = TType.Struct,
ID = 1,
};
var field = new TField
{
Name = "process",
Type = TType.Struct,
ID = 1,
};

oprot.WriteFieldBegin(field);
process.Write(oprot);
oprot.WriteFieldEnd();
oprot.WriteFieldBegin(field);
process.Write(oprot);
oprot.WriteFieldEnd();

field.Name = "spans";
field.Type = TType.List;
field.ID = 2;
field.Name = "spans";
field.Type = TType.List;
field.ID = 2;

oprot.WriteFieldBegin(field);
oprot.WriteFieldBegin(field);

oprot.WriteListBegin(new TList(TType.Struct, 0), out spanCountPosition);
oprot.WriteListBegin(new TList(TType.Struct, 0), out spanCountPosition);

byte[] beginMessage = oprot.WrittenData.ToArray();
oprot.Clear();
return beginMessage;
}
byte[] beginMessage = oprot.WrittenData.ToArray();
oprot.Clear();
return beginMessage;
}

private static byte[] GenerateEndMessage(TProtocol oprot)
{
oprot.WriteListEnd();
private static byte[] GenerateEndMessage(TProtocol oprot)
{
oprot.WriteListEnd();

oprot.WriteFieldEnd();
oprot.WriteFieldStop();
oprot.WriteStructEnd();
oprot.WriteFieldEnd();
oprot.WriteFieldStop();
oprot.WriteStructEnd();

byte[] endMessage = oprot.WrittenData.ToArray();
oprot.Clear();
return endMessage;
}
byte[] endMessage = oprot.WrittenData.ToArray();
oprot.Clear();
return endMessage;
}
}
77 changes: 38 additions & 39 deletions src/OpenTelemetry.Exporter.Jaeger/Implementation/EmitBatchArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,57 @@
using Thrift.Protocol;
using Thrift.Protocol.Entities;

namespace OpenTelemetry.Exporter.Jaeger.Implementation
namespace OpenTelemetry.Exporter.Jaeger.Implementation;

internal sealed class EmitBatchArgs
{
internal sealed class EmitBatchArgs
public EmitBatchArgs(TProtocol protocol)
{
public EmitBatchArgs(TProtocol protocol)
{
this.EmitBatchArgsBeginMessage = GenerateBeginMessage(protocol, out int seqIdPosition);
this.SeqIdPosition = seqIdPosition;
this.EmitBatchArgsEndMessage = GenerateEndMessage(protocol);
}
this.EmitBatchArgsBeginMessage = GenerateBeginMessage(protocol, out int seqIdPosition);
this.SeqIdPosition = seqIdPosition;
this.EmitBatchArgsEndMessage = GenerateEndMessage(protocol);
}

public byte[] EmitBatchArgsBeginMessage { get; }
public byte[] EmitBatchArgsBeginMessage { get; }

public int SeqIdPosition { get; }
public int SeqIdPosition { get; }

public byte[] EmitBatchArgsEndMessage { get; }
public byte[] EmitBatchArgsEndMessage { get; }

public int MinimumMessageSize => this.EmitBatchArgsBeginMessage.Length
+ this.EmitBatchArgsEndMessage.Length;
public int MinimumMessageSize => this.EmitBatchArgsBeginMessage.Length
+ this.EmitBatchArgsEndMessage.Length;

private static byte[] GenerateBeginMessage(TProtocol oprot, out int seqIdPosition)
{
oprot.WriteMessageBegin(new TMessage("emitBatch", TMessageType.Oneway, 0), out seqIdPosition);
private static byte[] GenerateBeginMessage(TProtocol oprot, out int seqIdPosition)
{
oprot.WriteMessageBegin(new TMessage("emitBatch", TMessageType.Oneway, 0), out seqIdPosition);

var struc = new TStruct("emitBatch_args");
oprot.WriteStructBegin(struc);
var struc = new TStruct("emitBatch_args");
oprot.WriteStructBegin(struc);

var field = new TField
{
Name = "batch",
Type = TType.Struct,
ID = 1,
};
var field = new TField
{
Name = "batch",
Type = TType.Struct,
ID = 1,
};

oprot.WriteFieldBegin(field);
oprot.WriteFieldBegin(field);

byte[] beginMessage = oprot.WrittenData.ToArray();
oprot.Clear();
return beginMessage;
}
byte[] beginMessage = oprot.WrittenData.ToArray();
oprot.Clear();
return beginMessage;
}

private static byte[] GenerateEndMessage(TProtocol oprot)
{
oprot.WriteFieldEnd();
oprot.WriteFieldStop();
oprot.WriteStructEnd();
private static byte[] GenerateEndMessage(TProtocol oprot)
{
oprot.WriteFieldEnd();
oprot.WriteFieldStop();
oprot.WriteStructEnd();

oprot.WriteMessageEnd();
oprot.WriteMessageEnd();

byte[] endMessage = oprot.WrittenData.ToArray();
oprot.Clear();
return endMessage;
}
byte[] endMessage = oprot.WrittenData.ToArray();
oprot.Clear();
return endMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
// limitations under the License.
// </copyright>

namespace OpenTelemetry.Exporter.Jaeger.Implementation
namespace OpenTelemetry.Exporter.Jaeger.Implementation;

internal interface IJaegerClient : IDisposable
{
internal interface IJaegerClient : IDisposable
{
bool Connected { get; }
bool Connected { get; }

void Connect();
void Connect();

void Close();
void Close();

int Send(byte[] buffer, int offset, int count);
}
int Send(byte[] buffer, int offset, int count);
}
63 changes: 31 additions & 32 deletions src/OpenTelemetry.Exporter.Jaeger/Implementation/Int128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,46 @@
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace OpenTelemetry.Exporter.Jaeger.Implementation
{
internal readonly struct Int128
{
public static Int128 Empty;
namespace OpenTelemetry.Exporter.Jaeger.Implementation;

private const int SpanIdBytes = 8;
private const int TraceIdBytes = 16;
internal readonly struct Int128
{
public static Int128 Empty;

public Int128(ActivitySpanId spanId)
{
Span<byte> bytes = stackalloc byte[SpanIdBytes];
spanId.CopyTo(bytes);
private const int SpanIdBytes = 8;
private const int TraceIdBytes = 16;

if (BitConverter.IsLittleEndian)
{
bytes.Reverse();
}
public Int128(ActivitySpanId spanId)
{
Span<byte> bytes = stackalloc byte[SpanIdBytes];
spanId.CopyTo(bytes);

var longs = MemoryMarshal.Cast<byte, long>(bytes);
this.High = 0;
this.Low = longs[0];
if (BitConverter.IsLittleEndian)
{
bytes.Reverse();
}

public Int128(ActivityTraceId traceId)
{
Span<byte> bytes = stackalloc byte[TraceIdBytes];
traceId.CopyTo(bytes);
var longs = MemoryMarshal.Cast<byte, long>(bytes);
this.High = 0;
this.Low = longs[0];
}

if (BitConverter.IsLittleEndian)
{
bytes.Reverse();
}
public Int128(ActivityTraceId traceId)
{
Span<byte> bytes = stackalloc byte[TraceIdBytes];
traceId.CopyTo(bytes);

var longs = MemoryMarshal.Cast<byte, long>(bytes);
this.High = BitConverter.IsLittleEndian ? longs[1] : longs[0];
this.Low = BitConverter.IsLittleEndian ? longs[0] : longs[1];
if (BitConverter.IsLittleEndian)
{
bytes.Reverse();
}

public long High { get; }

public long Low { get; }
var longs = MemoryMarshal.Cast<byte, long>(bytes);
this.High = BitConverter.IsLittleEndian ? longs[1] : longs[0];
this.Low = BitConverter.IsLittleEndian ? longs[0] : longs[1];
}

public long High { get; }

public long Low { get; }
}
Loading

0 comments on commit 0f9f507

Please sign in to comment.