@@ -28,8 +28,8 @@ import (
28
28
)
29
29
30
30
// FromSpan converts a model.Span to a log record
31
- func FromSpan (span * model.Span , topic , source string , file TagAppendRules ) (* sls.LogGroup , error ) {
32
- return converter {}.fromSpan (span , topic , source , file )
31
+ func FromSpan (span * model.Span , topic , source string , file TagAppendRules , rule KindRewriteRules ) (* sls.LogGroup , error ) {
32
+ return converter {}.fromSpan (span , topic , source , file , rule )
33
33
}
34
34
35
35
// ToSpan converts a log record to a model.Span
@@ -44,8 +44,8 @@ func ToTraces(logs []map[string]string) ([]*model.Trace, error) {
44
44
45
45
type converter struct {}
46
46
47
- func (c converter ) fromSpan (span * model.Span , topic , source string , file TagAppendRules ) (* sls.LogGroup , error ) {
48
- logs , err := c .fromSpanToLogs (span , file )
47
+ func (c converter ) fromSpan (span * model.Span , topic , source string , file TagAppendRules , rule KindRewriteRules ) (* sls.LogGroup , error ) {
48
+ logs , err := c .fromSpanToLogs (span , file , rule )
49
49
if err != nil {
50
50
return nil , err
51
51
}
@@ -56,8 +56,8 @@ func (c converter) fromSpan(span *model.Span, topic, source string, file TagAppe
56
56
}, nil
57
57
}
58
58
59
- func (c converter ) fromSpanToLogs (span * model.Span , file TagAppendRules ) ([]* sls.Log , error ) {
60
- contents , err := c .fromSpanToLogContents (span , file )
59
+ func (c converter ) fromSpanToLogs (span * model.Span , file TagAppendRules , rule KindRewriteRules ) ([]* sls.Log , error ) {
60
+ contents , err := c .fromSpanToLogContents (span , file , rule )
61
61
if err != nil {
62
62
return nil , err
63
63
}
@@ -73,7 +73,7 @@ func TraceIDToString(t *model.TraceID) string {
73
73
return fmt .Sprintf ("%016x%016x" , t .High , t .Low )
74
74
}
75
75
76
- func (c converter ) fromSpanToLogContents (span * model.Span , rules TagAppendRules ) ([]* sls.LogContent , error ) {
76
+ func (c converter ) fromSpanToLogContents (span * model.Span , tagAppendRules TagAppendRules , kindRewriteRules KindRewriteRules ) ([]* sls.LogContent , error ) {
77
77
contents := make ([]* sls.LogContent , 0 )
78
78
contents = c .appendContents (contents , traceIDField , TraceIDToString (& span .TraceID ))
79
79
contents = c .appendContents (contents , spanIDField , span .SpanID .String ())
@@ -88,18 +88,28 @@ func (c converter) fromSpanToLogContents(span *model.Span, rules TagAppendRules)
88
88
89
89
attributeMap := make (map [string ]string )
90
90
for _ , tag := range span .Tags {
91
- if k , ok := rules .SpanTagRules ()[tag .Key ]; ok {
91
+ if k , ok := tagAppendRules .SpanTagRules ()[tag .Key ]; ok {
92
92
attributeMap [k .TagKey ] = k .TagValue
93
93
}
94
94
attributeMap [tag .Key ] = tag .AsString ()
95
+
96
+ if k , ok := kindRewriteRules .SpanKindRules ()[tag .Key ]; ok {
97
+ c .appendContents (contents , spanKindField , k )
98
+ }
95
99
}
96
100
97
- for key , value := range rules .OperationPrefixRules () {
101
+ for key , value := range tagAppendRules .OperationPrefixRules () {
98
102
if strings .HasPrefix (span .OperationName , key ) {
99
103
attributeMap [value .TagKey ] = value .TagValue
100
104
}
101
105
}
102
106
107
+ for key , value := range kindRewriteRules .OperationPrefixRules () {
108
+ if strings .HasPrefix (span .OperationName , key ) {
109
+ c .appendContents (contents , spanKindField , value )
110
+ }
111
+ }
112
+
103
113
tagStr , _ := json .Marshal (attributeMap )
104
114
contents = c .appendContents (contents , "attribute" , string (tagStr ))
105
115
0 commit comments