Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Add support for Float64 attribute. #86

Merged
merged 2 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions trace_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package stackdriver
import (
"fmt"
"math"
"strconv"
"time"
"unicode/utf8"

Expand Down Expand Up @@ -234,6 +235,13 @@ func attributeValue(v interface{}) *tracepb.AttributeValue {
return &tracepb.AttributeValue{
Value: &tracepb.AttributeValue_IntValue{IntValue: value},
}
case float64:
// TODO: set double value if Stackdriver Trace support it in the future.
return &tracepb.AttributeValue{
Value: &tracepb.AttributeValue_StringValue{
StringValue: trunc(strconv.FormatFloat(value, 'f', -1, 64),
maxAttributeStringValue)},
}
case string:
return &tracepb.AttributeValue{
Value: &tracepb.AttributeValue_StringValue{StringValue: trunc(value, maxAttributeStringValue)},
Expand Down
8 changes: 7 additions & 1 deletion trace_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ func generateSpan() {
span2.AddAttributes(
trace.StringAttribute("key1", "value1"),
trace.StringAttribute("key2", "value2"))
span2.AddAttributes(trace.Int64Attribute("key1", 100))
span2.AddAttributes(
trace.Int64Attribute("key1", 100),
// TODO [rghetia]: uncomment the test case after go.opencensus.io/[email protected] is released.
//trace.Float64Attribute("key3", 100.001),
)
span2.End()
}
{
Expand Down Expand Up @@ -132,6 +136,8 @@ func createExpectedSpans() spans {
AttributeMap: map[string]*tracepb.AttributeValue{
"key2": {Value: &tracepb.AttributeValue_StringValue{StringValue: trunc("value2", 256)}},
"key1": {Value: &tracepb.AttributeValue_IntValue{IntValue: 100}},
// TODO [rghetia]: uncomment the test case after go.opencensus.io/[email protected] is released.
"key3": {Value: &tracepb.AttributeValue_StringValue{StringValue: trunc("100.001", 256)}},
agentLabel: {Value: &tracepb.AttributeValue_StringValue{StringValue: ua}},
},
},
Expand Down