18
18
// ServiceEntrySpanOperation is a dyngo.Operation that holds a the first span of a service. Usually a http or grpc span.
19
19
ServiceEntrySpanOperation struct {
20
20
dyngo.Operation
21
- tags map [string ]any
22
- jsonTags map [ string ] any
23
- mu sync.Mutex
21
+ jsonTags map [string ]any
22
+ tagSetter TagSetter
23
+ mu sync.Mutex
24
24
}
25
25
26
26
// ServiceEntrySpanArgs is the arguments for a ServiceEntrySpanOperation
@@ -52,7 +52,7 @@ func (ServiceEntrySpanArgs) IsArgOf(*ServiceEntrySpanOperation) {}
52
52
func (op * ServiceEntrySpanOperation ) SetTag (key string , value any ) {
53
53
op .mu .Lock ()
54
54
defer op .mu .Unlock ()
55
- op .tags [ key ] = value
55
+ op .tagSetter . SetTag ( key , value )
56
56
}
57
57
58
58
// SetSerializableTag adds the key/value pair to the tags to add to the service entry span.
@@ -76,7 +76,7 @@ func (op *ServiceEntrySpanOperation) SetSerializableTags(tags map[string]any) {
76
76
func (op * ServiceEntrySpanOperation ) setSerializableTag (key string , value any ) {
77
77
switch value .(type ) {
78
78
case string , int8 , int16 , int32 , int64 , uint8 , uint16 , uint32 , uint64 , float32 , float64 , bool :
79
- op .tags [ key ] = value
79
+ op .tagSetter . SetTag ( key , value )
80
80
default :
81
81
op .jsonTags [key ] = value
82
82
}
@@ -87,7 +87,7 @@ func (op *ServiceEntrySpanOperation) SetTags(tags map[string]any) {
87
87
op .mu .Lock ()
88
88
defer op .mu .Unlock ()
89
89
for k , v := range tags {
90
- op .tags [ k ] = v
90
+ op .tagSetter . SetTag ( k , v )
91
91
}
92
92
}
93
93
@@ -96,7 +96,7 @@ func (op *ServiceEntrySpanOperation) SetStringTags(tags map[string]string) {
96
96
op .mu .Lock ()
97
97
defer op .mu .Unlock ()
98
98
for k , v := range tags {
99
- op .tags [ k ] = v
99
+ op .tagSetter . SetTag ( k , v )
100
100
}
101
101
}
102
102
@@ -126,32 +126,30 @@ func (op *ServiceEntrySpanOperation) OnSpanTagEvent(tag SpanTag) {
126
126
op .SetTag (tag .Key , tag .Value )
127
127
}
128
128
129
- func StartServiceEntrySpanOperation (ctx context.Context ) (* ServiceEntrySpanOperation , context.Context ) {
129
+ func StartServiceEntrySpanOperation (ctx context.Context , span TagSetter ) (* ServiceEntrySpanOperation , context.Context ) {
130
130
parent , _ := dyngo .FromContext (ctx )
131
131
op := & ServiceEntrySpanOperation {
132
132
Operation : dyngo .NewOperation (parent ),
133
- tags : make (map [string ]any ),
134
- jsonTags : make ( map [ string ] any ) ,
133
+ jsonTags : make (map [string ]any , 2 ),
134
+ tagSetter : span ,
135
135
}
136
136
return op , dyngo .StartAndRegisterOperation (ctx , op , ServiceEntrySpanArgs {})
137
137
}
138
138
139
- func (op * ServiceEntrySpanOperation ) Finish (span TagSetter ) {
139
+ func (op * ServiceEntrySpanOperation ) Finish () {
140
+ span := op .tagSetter
140
141
if _ , ok := span .(* NoopTagSetter ); ok { // If the span is a NoopTagSetter or is nil, we don't need to set any tags
141
142
return
142
143
}
143
144
144
145
op .mu .Lock ()
145
146
defer op .mu .Unlock ()
146
147
147
- for k , v := range op .tags {
148
- span .SetTag (k , v )
149
- }
150
-
151
148
for k , v := range op .jsonTags {
152
149
strValue , err := json .Marshal (v )
153
150
if err != nil {
154
151
log .Debug ("appsec: failed to marshal tag %s: %v" , k , err )
152
+ continue
155
153
}
156
154
span .SetTag (k , string (strValue ))
157
155
}
0 commit comments