Skip to content

Commit

Permalink
Merge branch 'main' into repo-add-labels-to-pr-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Jun 13, 2024
2 parents 1e39b08 + 0819114 commit 0302d05
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.IncludeTraceStateForSpan.get -> bool
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.IncludeTraceStateForSpan.set -> void
static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.LoggerProviderBuilder builder) -> OpenTelemetry.Logs.LoggerProviderBuilder
static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.LoggerProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.Geneva.GenevaExporterOptions> configureExporter) -> OpenTelemetry.Logs.LoggerProviderBuilder
static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.LoggerProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Geneva.GenevaExporterOptions> configureExporter) -> OpenTelemetry.Logs.LoggerProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

* Update GenevaTraceExporter to export `activity.TraceStateString` as the value
for Part B `traceState` field for Spans when the `IncludeTraceStateForSpan`
option is set to `true`. This is an opt-in feature and the default value is `false`.
Note that this is for Spans only and not for LogRecord.
([#1850](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1850))

## 1.9.0-rc.1

Released 2024-Jun-12
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class GenevaExporterOptions

public EventNameExportMode EventNameExportMode { get; set; }

public bool IncludeTraceStateForSpan { get; set; }

public IReadOnlyDictionary<string, string> TableNameMappings
{
get => this._tableNameMappings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public MsgPackTraceExporter(GenevaExporterOptions options)
#endif
}

this.m_shouldIncludeTraceState = options.IncludeTraceStateForSpan;

var buffer = new byte[BUFFER_SIZE];

var cursor = 0;
Expand Down Expand Up @@ -243,6 +245,17 @@ internal int SerializeActivity(Activity activity)
cntFields += 1;
}

if (this.m_shouldIncludeTraceState)
{
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 Expand Up @@ -453,5 +466,7 @@ public void Dispose()
private readonly HashSet<string> m_dedicatedFields;
#endif

private readonly bool m_shouldIncludeTraceState;

private bool isDisposed;
}
7 changes: 7 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ A list of fields which should be stored as individual table columns.
This is a collection of fields that will be applied to all the Logs and Traces
sent through this exporter.

#### `IncludeTraceStateForSpan` (optional)

Export `activity.TraceStateString` as the value for Part B `traceState` field for
Spans when the `IncludeTraceStateForSpan` option is set to `true`.
This is an opt-in feature and the default value is `false`.
Note that this is for Spans only and not for LogRecord.

#### `TableNameMappings` (optional)

This defines the mapping for the table name used to store Logs and Traces.
Expand Down
13 changes: 13 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldTraceExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal sealed class TldTraceExporter : TldExporter, IDisposable
private readonly byte partAFieldsCount = 3; // At least three fields: time, ext_dt_traceId, ext_dt_spanId
private readonly HashSet<string> m_customFields;
private readonly Tuple<byte[], byte[]> repeatedPartAFields;
private readonly bool m_shouldIncludeTraceState;

private readonly EventProvider eventProvider;

Expand Down Expand Up @@ -114,6 +115,8 @@ public TldTraceExporter(GenevaExporterOptions options)
this.repeatedPartAFields = eb.GetRawFields();
}
}

this.m_shouldIncludeTraceState = options.IncludeTraceStateForSpan;
}

public ExportResult Export(in Batch<Activity> batch)
Expand Down Expand Up @@ -205,6 +208,16 @@ internal void SerializeActivity(Activity activity)
partBFieldsCount++;
}

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

var linkEnumerator = activity.EnumerateLinks();
if (linkEnumerator.MoveNext())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,15 @@ public void GenevaTraceExporter_Success_Windows()
}

[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public void GenevaTraceExporter_Serialization_Success(bool hasTableNameMapping, bool hasCustomFields)
[InlineData(false, false, false)]
[InlineData(false, true, false)]
[InlineData(true, false, false)]
[InlineData(true, true, false)]
[InlineData(false, false, true)]
[InlineData(false, true, true)]
[InlineData(true, false, true)]
[InlineData(true, true, true)]
public void GenevaTraceExporter_Serialization_Success(bool hasTableNameMapping, bool hasCustomFields, bool includeTraceState)
{
string path = string.Empty;
Socket server = null;
Expand Down Expand Up @@ -241,6 +245,11 @@ public void GenevaTraceExporter_Serialization_Success(bool hasTableNameMapping,
exporterOptions.CustomFields = new string[] { "clientRequestId" };
}

if (includeTraceState)
{
exporterOptions.IncludeTraceStateForSpan = true;
}

using var exporter = new MsgPackTraceExporter(exporterOptions);
#if NET8_0_OR_GREATER
var dedicatedFields = typeof(MsgPackTraceExporter).GetField("m_dedicatedFields", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(exporter) as FrozenSet<string>;
Expand Down Expand Up @@ -278,6 +287,11 @@ public void GenevaTraceExporter_Serialization_Success(bool hasTableNameMapping,
var linkedtraceId2 = ActivityTraceId.CreateFromString("e8ea7e9ac72de94e91fabc613f9686a2".AsSpan());
var linkedSpanId2 = ActivitySpanId.CreateFromString("888915b6286b9c02".AsSpan());

if (includeTraceState)
{
parentActivity.TraceStateString = "some=state";
}

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

if (!exporterOptions.IncludeTraceStateForSpan || string.IsNullOrEmpty(activity.TraceStateString))
{
Assert.False(mapping.ContainsKey("traceState"));
}
else
{
Assert.Equal(activity.TraceStateString, mapping["traceState"]);
}

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

0 comments on commit 0302d05

Please sign in to comment.