Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exporter.Geneva] Add TraceState support #1850

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Add TraceState support.
([#1850](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1850))

## 1.9.0-alpha.1

Released 2024-May-22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ internal int SerializeActivity(Activity activity)
cntFields += 1;
}

var traceStateString = activity.TraceStateString;
if (!string.IsNullOrEmpty(traceStateString))
{
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, "traceState");
cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, traceStateString);
cntFields += 1;
}

var linkEnumerator = activity.EnumerateLinks();
if (linkEnumerator.MoveNext())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ internal void SerializeActivity(Activity activity)
{
eb.AddCountedString("parentId", strParentId);
partBFieldsCount++;
}

var traceStateString = activity.TraceStateString;
if (!string.IsNullOrEmpty(traceStateString))
{
eb.AddCountedAnsiString("traceState", traceStateString, Encoding.UTF8);
partBFieldsCount++;
}

var linkEnumerator = activity.EnumerateLinks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
using OpenTelemetry.Trace;

/*
BenchmarkDotNet v0.13.10, Windows 11 (10.0.23424.1000)
Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores
.NET SDK 8.0.100
[Host] : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2


| Method | Mean | Error | StdDev | Allocated |
|-------------------------- |---------:|---------:|---------:|----------:|
| MsgPack_SerializeActivity | 266.4 ns | 3.84 ns | 3.59 ns | - |
| TLD_SerializeActivity | 298.9 ns | 1.99 ns | 1.66 ns | - |
| MsgPack_ExportActivity | 787.3 ns | 15.70 ns | 31.71 ns | - |
| TLD_ExportActivity | 878.6 ns | 9.84 ns | 9.20 ns | - |
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
Intel Core i9-10900K CPU 3.70GHz, 1 CPU, 20 logical and 10 physical cores
.NET SDK 8.0.300
[Host] : .NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX2


| Method | Mean | Error | StdDev | Allocated |
|------------------------------------------------- |-----------:|----------:|----------:|----------:|
| MsgPack_SerializeActivity | 239.467 ns | 1.1202 ns | 0.9930 ns | - |
| TLD_SerializeActivity | 279.810 ns | 1.2504 ns | 0.9763 ns | - |
| TLD_SerializeActivityWithoutTraceState | 294.145 ns | 1.2952 ns | 1.1481 ns | - |
| TLD_SerializeActivityWithTraceState | 319.608 ns | 5.9573 ns | 5.5724 ns | - |
| TLD_SerializeActivityWithTraceStateInGrandparent | 314.195 ns | 1.1738 ns | 0.9164 ns | - |
| MsgPack_ExportActivity | 265.354 ns | 1.0098 ns | 0.9445 ns | - |
| TLD_ExportActivity | 1.102 ns | 0.0469 ns | 0.0482 ns | - |
*/

namespace OpenTelemetry.Exporter.Geneva.Benchmarks;
Expand All @@ -29,6 +32,9 @@ namespace OpenTelemetry.Exporter.Geneva.Benchmarks;
public class TLDTraceExporterBenchmarks
{
private readonly Activity activity;
private readonly Activity activityWithoutTraceState;
private readonly Activity activityWithTraceState;
private readonly Activity activityWithTraceStateInGrandparent;
private readonly Batch<Activity> batch;
private readonly MsgPackTraceExporter msgPackExporter;
private readonly TldTraceExporter tldExporter;
Expand Down Expand Up @@ -58,6 +64,51 @@ public TLDTraceExporterBenchmarks()
this.activity?.SetStatus(Status.Error);
}

using (var grandparentActivity = this.activitySource.StartActivity("GrandparentActivity"))
{
using (var parentActivity = this.activitySource.StartActivity("ParentActivity", ActivityKind.Internal, grandparentActivity.Context))
{
using (var testActivity = this.activitySource.StartActivity("SayHello", ActivityKind.Internal, parentActivity.Context))
{
// testActivity.TraceStateString = "some=state";
this.activityWithoutTraceState = testActivity;
this.activityWithoutTraceState.SetTag("tagString", "value");
this.activityWithoutTraceState.SetTag("tagInt", 100);
this.activityWithoutTraceState.SetStatus(Status.Error);
}
}
}

using (var grandparentActivity = this.activitySource.StartActivity("GrandparentActivity"))
{
using (var parentActivity = this.activitySource.StartActivity("ParentActivity", ActivityKind.Internal, grandparentActivity.Context))
{
using (var testActivity = this.activitySource.StartActivity("SayHello", ActivityKind.Internal, parentActivity.Context))
{
testActivity.TraceStateString = "some=state";
this.activityWithTraceState = testActivity;
this.activityWithTraceState.SetTag("tagString", "value");
this.activityWithTraceState.SetTag("tagInt", 100);
this.activityWithTraceState.SetStatus(Status.Error);
}
}
}

using (var grandparentActivity = this.activitySource.StartActivity("GrandparentActivity"))
{
grandparentActivity.TraceStateString = "some=state";
using (var parentActivity = this.activitySource.StartActivity("ParentActivity", ActivityKind.Internal, grandparentActivity.Context))
{
using (var testActivity = this.activitySource.StartActivity("SayHello", ActivityKind.Internal, parentActivity.Context))
{
this.activityWithTraceStateInGrandparent = testActivity;
this.activityWithTraceStateInGrandparent.SetTag("tagString", "value");
this.activityWithTraceStateInGrandparent.SetTag("tagInt", 100);
this.activityWithTraceStateInGrandparent.SetStatus(Status.Error);
}
}
}

this.msgPackExporter = new MsgPackTraceExporter(new GenevaExporterOptions
{
ConnectionString = "EtwSession=OpenTelemetry",
Expand Down Expand Up @@ -93,6 +144,24 @@ public void TLD_SerializeActivity()
this.tldExporter.SerializeActivity(this.activity);
}

[Benchmark]
public void TLD_SerializeActivityWithoutTraceState()
{
this.tldExporter.SerializeActivity(this.activityWithoutTraceState);
}

[Benchmark]
public void TLD_SerializeActivityWithTraceState()
{
this.tldExporter.SerializeActivity(this.activityWithTraceState);
}

[Benchmark]
public void TLD_SerializeActivityWithTraceStateInGrandparent()
{
this.tldExporter.SerializeActivity(this.activityWithTraceStateInGrandparent);
}

[Benchmark]
public void MsgPack_ExportActivity()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
using OpenTelemetry.Trace;

/*
BenchmarkDotNet v0.13.10, Windows 11 (10.0.23424.1000)
Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores
.NET SDK 8.0.100
[Host] : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2


| Method | Mean | Error | StdDev | Gen0 | Allocated |
|--------------------------------- |-----------:|---------:|---------:|-------:|----------:|
| ExportActivity | 847.1 ns | 16.34 ns | 22.36 ns | - | - |
| SerializeActivity | 261.5 ns | 2.91 ns | 2.58 ns | - | - |
| CreateActivityWithGenevaExporter | 1,066.0 ns | 20.98 ns | 56.35 ns | 0.0648 | 416 B |
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
Intel Core i9-10900K CPU 3.70GHz, 1 CPU, 20 logical and 10 physical cores
.NET SDK 8.0.300
[Host] : .NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX2


| Method | Mean | Error | StdDev | Gen0 | Allocated |
|--------------------------------------------- |---------:|--------:|--------:|-------:|----------:|
| ExportActivity | 266.2 ns | 0.34 ns | 0.28 ns | - | - |
| SerializeActivity | 243.1 ns | 1.42 ns | 1.26 ns | - | - |
| SerializeActivityWithoutTraceState | 248.7 ns | 0.78 ns | 0.65 ns | - | - |
| SerializeActivityWithTraceState | 273.8 ns | 3.75 ns | 3.32 ns | - | - |
| SerializeActivityWithTraceStateInGrandparent | 280.2 ns | 5.54 ns | 5.69 ns | - | - |
| CreateActivityWithGenevaExporter | 452.1 ns | 4.50 ns | 3.99 ns | 0.0396 | 416 B |
*/

namespace OpenTelemetry.Exporter.Geneva.Benchmarks;
Expand All @@ -27,6 +30,9 @@ namespace OpenTelemetry.Exporter.Geneva.Benchmarks;
public class TraceExporterBenchmarks
{
private readonly Activity activity;
private readonly Activity activityWithoutTraceState;
private readonly Activity activityWithTraceState;
private readonly Activity activityWithTraceStateInGrandparent;
private readonly Batch<Activity> batch;
private readonly MsgPackTraceExporter exporter;
private readonly TracerProvider tracerProvider;
Expand Down Expand Up @@ -57,6 +63,51 @@ public TraceExporterBenchmarks()
this.activity.SetStatus(Status.Error);
}

using (var grandparentActivity = this.activitySource.StartActivity("GrandparentActivity"))
{
using (var parentActivity = this.activitySource.StartActivity("ParentActivity", ActivityKind.Internal, grandparentActivity.Context))
{
using (var testActivity = this.activitySource.StartActivity("SayHello", ActivityKind.Internal, parentActivity.Context))
{
// testActivity.TraceStateString = "some=state";
this.activityWithoutTraceState = testActivity;
this.activityWithoutTraceState.SetTag("tagString", "value");
this.activityWithoutTraceState.SetTag("tagInt", 100);
this.activityWithoutTraceState.SetStatus(Status.Error);
}
}
}

using (var grandparentActivity = this.activitySource.StartActivity("GrandparentActivity"))
{
using (var parentActivity = this.activitySource.StartActivity("ParentActivity", ActivityKind.Internal, grandparentActivity.Context))
{
using (var testActivity = this.activitySource.StartActivity("SayHello", ActivityKind.Internal, parentActivity.Context))
{
testActivity.TraceStateString = "some=state";
this.activityWithTraceState = testActivity;
this.activityWithTraceState.SetTag("tagString", "value");
this.activityWithTraceState.SetTag("tagInt", 100);
this.activityWithTraceState.SetStatus(Status.Error);
}
}
}

using (var grandparentActivity = this.activitySource.StartActivity("GrandparentActivity"))
{
grandparentActivity.TraceStateString = "some=state";
using (var parentActivity = this.activitySource.StartActivity("ParentActivity", ActivityKind.Internal, grandparentActivity.Context))
{
using (var testActivity = this.activitySource.StartActivity("SayHello", ActivityKind.Internal, parentActivity.Context))
{
this.activityWithTraceStateInGrandparent = testActivity;
this.activityWithTraceStateInGrandparent.SetTag("tagString", "value");
this.activityWithTraceStateInGrandparent.SetTag("tagInt", 100);
this.activityWithTraceStateInGrandparent.SetStatus(Status.Error);
}
}
}

activityListener.Dispose();
#endregion

Expand Down Expand Up @@ -99,6 +150,24 @@ public void SerializeActivity()
this.exporter.SerializeActivity(this.activity);
}

[Benchmark]
public void SerializeActivityWithoutTraceState()
xiang17 marked this conversation as resolved.
Show resolved Hide resolved
{
this.exporter.SerializeActivity(this.activityWithoutTraceState);
}

[Benchmark]
public void SerializeActivityWithTraceState()
{
this.exporter.SerializeActivity(this.activityWithTraceState);
}

[Benchmark]
public void SerializeActivityWithTraceStateInGrandparent()
{
this.exporter.SerializeActivity(this.activityWithTraceStateInGrandparent);
}

[Benchmark]
public void CreateActivityWithGenevaExporter()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ public void GenevaTraceExporter_Serialization_Success(bool hasTableNameMapping,
var linkedtraceId2 = ActivityTraceId.CreateFromString("e8ea7e9ac72de94e91fabc613f9686a2".AsSpan());
var linkedSpanId2 = ActivitySpanId.CreateFromString("888915b6286b9c02".AsSpan());

parentActivity.TraceStateString = "some=state";

var links = new[]
{
new ActivityLink(new ActivityContext(
Expand Down Expand Up @@ -659,6 +661,11 @@ private void AssertFluentdForwardModeForActivity(GenevaExporterOptions exporterO
Assert.Equal(activity.ParentSpanId.ToHexString(), mapping["parentId"]);
}

if (!string.IsNullOrEmpty(activity.TraceStateString))
{
Assert.Equal(activity.TraceStateString, mapping["traceState"]);
}

#region Assert Activity Links
if (activity.Links.Any())
{
Expand Down
Loading