-
Notifications
You must be signed in to change notification settings - Fork 2
/
logzioSpan.go
82 lines (75 loc) · 3.01 KB
/
logzioSpan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package objects
import (
"encoding/json"
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/plugin/storage/es/spanstore/dbmodel"
)
const (
spanLogType = "jaegerSpan"
//TagDotReplacementCharacter state which character should replace the dot in es
TagDotReplacementCharacter = "@"
)
// LogzioSpan is same as esSpan with a few different json field names and an addition on type field.
type LogzioSpan struct {
TraceID dbmodel.TraceID `json:"traceID"`
OperationName string `json:"operationName,omitempty"`
SpanID dbmodel.SpanID `json:"spanID"`
References []dbmodel.Reference `json:"references"`
Flags uint32 `json:"flags,omitempty"`
StartTime uint64 `json:"startTime"`
StartTimeMillis uint64 `json:"startTimeMillis"`
Timestamp uint64 `json:"@timestamp"`
Duration uint64 `json:"duration"`
Tags []dbmodel.KeyValue `json:"JaegerTags,omitempty"`
Tag map[string]interface{} `json:"JaegerTag,omitempty"`
Logs []dbmodel.Log `json:"logs"`
Process dbmodel.Process `json:"process,omitempty"`
Type string `json:"type"`
}
func getTagsValues(tags []model.KeyValue) []string {
var values []string
for i := range tags {
values = append(values, tags[i].VStr)
}
return values
}
// TransformToLogzioSpanBytes receives a Jaeger span, converts it to logzio span and returns it as a byte array.
// The main differences between Jaeger span and logzio span are arrays which are represented as maps
func TransformToLogzioSpanBytes(span *model.Span) ([]byte, error) {
spanConverter := dbmodel.NewFromDomain(true, getTagsValues(span.Tags), TagDotReplacementCharacter)
jsonSpan := spanConverter.FromDomainEmbedProcess(span)
logzioSpan := LogzioSpan{
TraceID: jsonSpan.TraceID,
OperationName: jsonSpan.OperationName,
SpanID: jsonSpan.SpanID,
References: jsonSpan.References,
Flags: jsonSpan.Flags,
StartTime: jsonSpan.StartTime,
StartTimeMillis: jsonSpan.StartTimeMillis,
Timestamp: jsonSpan.StartTimeMillis,
Duration: jsonSpan.Duration,
Tags: jsonSpan.Tags,
Tag: jsonSpan.Tag,
Process: jsonSpan.Process,
Logs: jsonSpan.Logs,
Type: spanLogType,
}
return json.Marshal(logzioSpan)
}
// TransformToDbModelSpan coverts logz.io span to ElasticSearch span
func (span *LogzioSpan) TransformToDbModelSpan() *dbmodel.Span {
return &dbmodel.Span{
OperationName: span.OperationName,
Process: span.Process,
Tags: span.Tags,
Tag: span.Tag,
References: span.References,
Logs: span.Logs,
Duration: span.Duration,
StartTimeMillis: span.StartTimeMillis,
StartTime: span.StartTime,
Flags: span.Flags,
SpanID: span.SpanID,
TraceID: span.TraceID,
}
}