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

Use ToOtlpAttribute method for traces #3274

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ option
* Fix handling of array-valued attributes for the OTLP trace exporter.
([#3238](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3238))

* Improve the conversion and formatting of attribute values to the OTLP format
for resources, metrics, and logs. The list of data types that must be
supported per the
* Improve the conversion and formatting of attribute values to the OTLP format.
The list of data types that must be supported per the
[OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/common#attribute)
is more narrow than what the .NET OpenTelemetry SDK supports. Numeric
[built-in value types](https://docs.microsoft.com/dotnet/csharp/language-reference/builtin-types/built-in-types)
Expand All @@ -30,6 +29,7 @@ option
`char`, `bool` are supported. All other types are converted to a `string`.
Array values are also supported.
([#3262](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3262))
([#3274](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3274))

## 1.3.0-beta.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,6 @@ private static OtlpTrace.Span.Types.Event ToOtlpEvent(ActivityEvent activityEven
return (Action<RepeatedField<OtlpTrace.Span>, int>)dynamicMethod.CreateDelegate(typeof(Action<RepeatedField<OtlpTrace.Span>, int>));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static OtlpCommon.KeyValue CreateOtlpKeyValue(string key, OtlpCommon.AnyValue value)
{
return new OtlpCommon.KeyValue { Key = key, Value = value };
}

private struct TagEnumerationState : IActivityEnumerator<KeyValuePair<string, object>>, PeerServiceResolver.IPeerServiceState
{
public bool Created;
Expand Down Expand Up @@ -361,75 +355,19 @@ public bool ForEach(KeyValuePair<string, object> activityTag)
this.Created = true;
}

OtlpCommon.ArrayValue arrayValue;

switch (activityTag.Value)
var attribute = activityTag.ToOtlpAttribute();
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
if (attribute != null)
{
case string s:
PeerServiceResolver.InspectTag(ref this, key, s);
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { StringValue = s }));
break;
case bool b:
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { BoolValue = b }));
break;
case int i:
PeerServiceResolver.InspectTag(ref this, key, i);
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { IntValue = i }));
break;
case long l:
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { IntValue = l }));
break;
case double d:
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { DoubleValue = d }));
break;
case int[] intArray:
arrayValue = new OtlpCommon.ArrayValue();
foreach (var item in intArray)
{
arrayValue.Values.Add(new OtlpCommon.AnyValue { IntValue = item });
}

PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { ArrayValue = arrayValue }));
break;
case double[] doubleArray:
arrayValue = new OtlpCommon.ArrayValue();
foreach (var item in doubleArray)
{
arrayValue.Values.Add(new OtlpCommon.AnyValue { DoubleValue = item });
}

PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { ArrayValue = arrayValue }));
break;
case bool[] boolArray:
arrayValue = new OtlpCommon.ArrayValue();
foreach (var item in boolArray)
{
arrayValue.Values.Add(new OtlpCommon.AnyValue { BoolValue = item });
}

PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { ArrayValue = arrayValue }));
break;
case string[] stringArray:
arrayValue = new OtlpCommon.ArrayValue();
foreach (var item in stringArray)
{
arrayValue.Values.Add(item == null ? new OtlpCommon.AnyValue() : new OtlpCommon.AnyValue { StringValue = item });
}

PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { ArrayValue = arrayValue }));
break;
case long[] longArray:
arrayValue = new OtlpCommon.ArrayValue();
foreach (var item in longArray)
{
arrayValue.Values.Add(new OtlpCommon.AnyValue { IntValue = item });
}

PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { ArrayValue = arrayValue }));
break;
default:
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { StringValue = activityTag.Value.ToString() }));
break;
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, attribute);

if (attribute.Value.ValueCase == OtlpCommon.AnyValue.ValueOneofCase.StringValue)
{
PeerServiceResolver.InspectTag(ref this, key, attribute.Value.StringValue);
}
else if (attribute.Value.ValueCase == OtlpCommon.AnyValue.ValueOneofCase.IntValue)
{
PeerServiceResolver.InspectTag(ref this, key, attribute.Value.IntValue);
}
}

return true;
Expand Down