1// Copyright (c) 2017 Uber Technologies, Inc. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package jaeger 16 17import ( 18 "fmt" 19 20 "github.com/opentracing/opentracing-go/log" 21 22 j "github.com/uber/jaeger-client-go/thrift-gen/jaeger" 23) 24 25type tags []*j.Tag 26 27// ConvertLogsToJaegerTags converts log Fields into jaeger tags. 28func ConvertLogsToJaegerTags(logFields []log.Field) []*j.Tag { 29 fields := tags(make([]*j.Tag, 0, len(logFields))) 30 for _, field := range logFields { 31 field.Marshal(&fields) 32 } 33 return fields 34} 35 36func (t *tags) EmitString(key, value string) { 37 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_STRING, VStr: &value}) 38} 39 40func (t *tags) EmitBool(key string, value bool) { 41 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_BOOL, VBool: &value}) 42} 43 44func (t *tags) EmitInt(key string, value int) { 45 vLong := int64(value) 46 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_LONG, VLong: &vLong}) 47} 48 49func (t *tags) EmitInt32(key string, value int32) { 50 vLong := int64(value) 51 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_LONG, VLong: &vLong}) 52} 53 54func (t *tags) EmitInt64(key string, value int64) { 55 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_LONG, VLong: &value}) 56} 57 58func (t *tags) EmitUint32(key string, value uint32) { 59 vLong := int64(value) 60 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_LONG, VLong: &vLong}) 61} 62 63func (t *tags) EmitUint64(key string, value uint64) { 64 vLong := int64(value) 65 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_LONG, VLong: &vLong}) 66} 67 68func (t *tags) EmitFloat32(key string, value float32) { 69 vDouble := float64(value) 70 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_DOUBLE, VDouble: &vDouble}) 71} 72 73func (t *tags) EmitFloat64(key string, value float64) { 74 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_DOUBLE, VDouble: &value}) 75} 76 77func (t *tags) EmitObject(key string, value interface{}) { 78 vStr := fmt.Sprintf("%+v", value) 79 *t = append(*t, &j.Tag{Key: key, VType: j.TagType_STRING, VStr: &vStr}) 80} 81 82func (t *tags) EmitLazyLogger(value log.LazyLogger) { 83 value(t) 84} 85