diff --git a/trace_proto.go b/trace_proto.go index 2d259cf..f64ab1e 100644 --- a/trace_proto.go +++ b/trace_proto.go @@ -17,6 +17,7 @@ package stackdriver import ( "fmt" "math" + "strconv" "time" "unicode/utf8" @@ -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)}, diff --git a/trace_proto_test.go b/trace_proto_test.go index 45256be..8eb7b51 100644 --- a/trace_proto_test.go +++ b/trace_proto_test.go @@ -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/trace@v0.20.0 is released. + //trace.Float64Attribute("key3", 100.001), + ) span2.End() } { @@ -130,8 +134,10 @@ func createExpectedSpans() spans { DisplayName: trunc("span2", 128), Attributes: &tracepb.Span_Attributes{ AttributeMap: map[string]*tracepb.AttributeValue{ - "key2": {Value: &tracepb.AttributeValue_StringValue{StringValue: trunc("value2", 256)}}, - "key1": {Value: &tracepb.AttributeValue_IntValue{IntValue: 100}}, + "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/trace@v0.20.0 is released. + //"key3": {Value: &tracepb.AttributeValue_StringValue{StringValue: trunc("100.001", 256)}}, agentLabel: {Value: &tracepb.AttributeValue_StringValue{StringValue: ua}}, }, },