Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit 8db5ebf

Browse files
fix serialization of attribute types (#90)
1 parent a02af50 commit 8db5ebf

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/OpenCensus.Exporter.Ocagent/Implementation/SpanDataExtentions.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,12 @@ private static Span.Types.Attributes FromIAttributes(IAttributes source)
9090

9191
attributes.AttributeMap.Add(source.AttributeMap.ToDictionary(
9292
kvp => kvp.Key,
93-
kvp => new Opencensus.Proto.Trace.V1.AttributeValue
94-
{
95-
StringValue = new TruncatableString
96-
{
97-
Value = kvp.Value.Match(s => s, b => b.ToString(), l => l.ToString(), d => d.ToString(), o => o?.ToString()),
98-
},
99-
100-
// todo: how to determine AttributeValue type?
101-
}));
93+
kvp => kvp.Value.Match(
94+
s => new Opencensus.Proto.Trace.V1.AttributeValue { StringValue = new TruncatableString() { Value = s } },
95+
b => new Opencensus.Proto.Trace.V1.AttributeValue { BoolValue = b },
96+
l => new Opencensus.Proto.Trace.V1.AttributeValue { IntValue = l },
97+
d => new Opencensus.Proto.Trace.V1.AttributeValue { DoubleValue = d },
98+
o => new Opencensus.Proto.Trace.V1.AttributeValue { StringValue = new TruncatableString() { Value = o?.ToString() } })));
10299

103100
return attributes;
104101
}
@@ -170,15 +167,12 @@ private static Span.Types.Attributes FromIAttributeMap(IDictionary<string, IAttr
170167

171168
attributes.AttributeMap.Add(source.ToDictionary(
172169
kvp => kvp.Key,
173-
kvp => new Opencensus.Proto.Trace.V1.AttributeValue
174-
{
175-
StringValue = new TruncatableString
176-
{
177-
Value = kvp.Value.Match(s => s, b => b.ToString(), l => l.ToString(), d => d.ToString(), o => o?.ToString()),
178-
},
179-
180-
// todo: how to determine AttributeValue type?
181-
}));
170+
kvp => kvp.Value.Match(
171+
s => new Opencensus.Proto.Trace.V1.AttributeValue { StringValue = new TruncatableString() { Value = s } },
172+
b => new Opencensus.Proto.Trace.V1.AttributeValue { BoolValue = b },
173+
l => new Opencensus.Proto.Trace.V1.AttributeValue { IntValue = l },
174+
d => new Opencensus.Proto.Trace.V1.AttributeValue { DoubleValue = d },
175+
o => new Opencensus.Proto.Trace.V1.AttributeValue { StringValue = new TruncatableString() { Value = o?.ToString() } })));
182176

183177
return attributes;
184178
}

0 commit comments

Comments
 (0)