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

Exporting tags consistently #3281

Merged
merged 36 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3d44019
WIP generalize transforming tags
alanwest May 13, 2022
5c17ba1
Merge branch 'main' into alanwest/tag-transformer
alanwest May 16, 2022
6653468
Make abstract methods protected
alanwest May 17, 2022
bd59744
Add ZipkinTagTransformer
alanwest May 17, 2022
84a1ee7
Simplify ZipkinTagTransformer
alanwest May 17, 2022
9cbb855
Refactor OTLP array attribute transform
alanwest May 18, 2022
fc5bf81
Merge branch 'main' into alanwest/tag-transformer
alanwest May 19, 2022
0c92519
Merge branch 'main' into alanwest/tag-transformer
alanwest May 20, 2022
493ed24
Unused using
alanwest May 20, 2022
0ad99fe
Change Zipkin test. Array values are now represented as JSON arrays.
alanwest May 20, 2022
e8a52a4
net462 and netcoreapp3.1 runtimes are confused about pointer types
alanwest May 20, 2022
643742e
Handle array values better
alanwest May 24, 2022
347ab44
Fix namespace
alanwest May 24, 2022
181e2fa
Handle exceptions when transforming array values
alanwest May 24, 2022
a2c2d69
Log when transform fails
alanwest May 24, 2022
9d9c5d0
Merge branch 'main' into alanwest/tag-transformer
alanwest May 24, 2022
38d17a7
TransformTag -> TryTransformTag
alanwest May 25, 2022
1f09f2c
CodeAnalysis recommendations
alanwest May 25, 2022
bdd17b2
Change OTLP exporter to use TryTransformTag
alanwest May 25, 2022
f3ee3e7
CodeAnalysis
alanwest May 25, 2022
c3dd4ec
CodeAnalysis
alanwest May 25, 2022
76a2f3c
Change Jaeger exporter to use TryTransformTag
alanwest May 25, 2022
38fb5f0
Make TagTransformers singletons
alanwest May 25, 2022
4b7727c
Merge branch 'main' into alanwest/tag-transformer
alanwest May 25, 2022
efc21a4
Unused using
alanwest May 25, 2022
a536bf0
else if
alanwest May 25, 2022
b6cab43
Make singleton Instance a property
alanwest May 25, 2022
5b23656
:seal: classes
alanwest May 25, 2022
040762c
Debug.Assert
alanwest May 25, 2022
fd9f373
Do later
alanwest May 25, 2022
0d31699
Make TransformValue protected
alanwest May 25, 2022
673ade0
Exclude TagTransformer.cs from compilation of SDK project
alanwest May 25, 2022
74df0df
Move JSON serialization to projects that need it
alanwest May 25, 2022
d882145
File-scoped namespaces
alanwest May 25, 2022
4f89b27
Merge branch 'main' into alanwest/tag-transformer
cijothomas May 26, 2022
5fa4281
Update changelogs
alanwest May 26, 2022
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
Prev Previous commit
Next Next commit
Handle exceptions when transforming array values
  • Loading branch information
alanwest committed May 24, 2022
commit 181e2fa37f07eb3382f112db5df9d46e3d5e69e9
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,15 @@ protected override OtlpCommon.AnyValue TransformArrayValue(Array array)

foreach (var item in array)
{
var value = item != null ? this.TransformValue(item) : new OtlpCommon.AnyValue();
arrayValue.Values.Add(value);
try
{
var value = item != null ? this.TransformValue(item) : new OtlpCommon.AnyValue();
arrayValue.Values.Add(value);
}
catch
{
return null;
}
}

return new OtlpCommon.AnyValue { ArrayValue = arrayValue };
Expand Down
3 changes: 2 additions & 1 deletion src/OpenTelemetry/Internal/TagAndValueTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public TValue TransformValue(object value)
case double:
return this.TransformFloatingPointValue(Convert.ToDouble(value));
default:
return default(TValue);
// This could throw an exception. The caller is expected to handle.
return this.TransformStringValue(value.ToString());
}
}

Expand Down
25 changes: 13 additions & 12 deletions src/OpenTelemetry/Internal/TagTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public T TransformTag(KeyValuePair<string, object> tag)
return default;
}

T result = default;
switch (tag.Value)
{
case char:
Expand All @@ -48,7 +47,16 @@ public T TransformTag(KeyValuePair<string, object> tag)
case double:
return this.TransformFloatingPointTag(tag.Key, Convert.ToDouble(tag.Value));
case Array array:
return this.TransformArrayTagInternal(tag.Key, array);
try
{
return this.TransformArrayTagInternal(tag.Key, array);
}
catch
{
// If ToString throws an exception then the tag is ignored.
// OpenTelemetrySdkEventSource.Log.UnsupportedAttributeType(tag.Value.GetType().ToString(), tag.Key);
return default(T);
}

// All other types are converted to strings including the following
// built-in value types:
Expand All @@ -59,22 +67,15 @@ public T TransformTag(KeyValuePair<string, object> tag)
default:
try
{
result = this.TransformStringTag(tag.Key, tag.Value.ToString());
return this.TransformStringTag(tag.Key, tag.Value.ToString());
}
catch
{
// If ToString throws an exception then the tag is ignored.
// OpenTelemetrySdkEventSource.Log.UnsupportedAttributeType(tag.Value.GetType().ToString(), tag.Key);
return default(T);
}

break;
}

// if (result == null)
// {
// // OpenTelemetryProtocolExporterEventSource.Log.UnsupportedAttributeType(kvp.Value.GetType().ToString(), kvp.Key);
// }

return result;
}

protected abstract T TransformIntegralTag(string key, long value);
Expand Down