/
registered_span.go
1802 lines (1587 loc) · 50.9 KB
/
registered_span.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// (c) Copyright IBM Corp. 2021
// (c) Copyright Instana Inc. 2021
package instana
import (
"strings"
"github.com/opentracing/opentracing-go/ext"
)
// Registered types supported by Instana. The span type is determined based on
// the operation name passed to the `StartSpan()` call of a tracer.
//
// It is NOT RECOMMENDED to use operation names that match any of these constants in your
// custom instrumentation code unless you explicitly wish to send data as a registered span.
// The list of supported tags can be found in the godoc of the respective span tags type below.
const (
// SDK span, a generic span containing arbitrary data. Spans with operation name
// not listed in the subsequent list will be sent as an SDK spans forwarding all
// attached tags to the agent
SDKSpanType = RegisteredSpanType("sdk")
// HTTP server and client spans
HTTPServerSpanType = RegisteredSpanType("g.http")
HTTPClientSpanType = RegisteredSpanType("http")
// RPC server and client spans
RPCServerSpanType = RegisteredSpanType("rpc-server")
RPCClientSpanType = RegisteredSpanType("rpc-client")
// Kafka consumer/producer span
KafkaSpanType = RegisteredSpanType("kafka")
// Google Cloud Storage client span
GCPStorageSpanType = RegisteredSpanType("gcs")
// Google Cloud PubSub client span
GCPPubSubSpanType = RegisteredSpanType("gcps")
// AWS Lambda entry span
AWSLambdaEntrySpanType = RegisteredSpanType("aws.lambda.entry")
// AWS S3 client span
AWSS3SpanType = RegisteredSpanType("s3")
// AWS SQS client span
AWSSQSSpanType = RegisteredSpanType("sqs")
// AWS SNS client span
AWSSNSSpanType = RegisteredSpanType("sns")
// AWS DynamoDB client span
AWSDynamoDBSpanType = RegisteredSpanType("dynamodb")
// AWS Lambda invoke span
AWSLambdaInvokeSpanType = RegisteredSpanType("aws.lambda.invoke")
// Logging span
LogSpanType = RegisteredSpanType("log.go")
// MongoDB client span
MongoDBSpanType = RegisteredSpanType("mongo")
// PostgreSQL client span
PostgreSQLSpanType = RegisteredSpanType("postgres")
// MySQL client span
MySQLSpanType = RegisteredSpanType("mysql")
// Redis client span
RedisSpanType = RegisteredSpanType("redis")
// Couchbase client span
CouchbaseSpanType = RegisteredSpanType("couchbase")
// Cosmos client span
CosmosSpanType = RegisteredSpanType("cosmos")
// RabbitMQ client span
RabbitMQSpanType = RegisteredSpanType("rabbitmq")
// Azure function span
AzureFunctionType = RegisteredSpanType("azf")
// GraphQL server span
GraphQLServerType = RegisteredSpanType("graphql.server")
// GraphQL client span
GraphQLClientType = RegisteredSpanType("graphql.client")
)
// RegisteredSpanType represents the span type supported by Instana
type RegisteredSpanType string
// extractData is a factory method to create the `data` section for a typed span
func (st RegisteredSpanType) extractData(span *spanS) typedSpanData {
switch st {
case HTTPServerSpanType, HTTPClientSpanType:
return newHTTPSpanData(span)
case RPCServerSpanType, RPCClientSpanType:
return newRPCSpanData(span)
case KafkaSpanType:
return newKafkaSpanData(span)
case GCPStorageSpanType:
return newGCPStorageSpanData(span)
case GCPPubSubSpanType:
return newGCPPubSubSpanData(span)
case AWSLambdaEntrySpanType:
return newAWSLambdaSpanData(span)
case AWSS3SpanType:
return newAWSS3SpanData(span)
case AWSSQSSpanType:
return newAWSSQSSpanData(span)
case AWSSNSSpanType:
return newAWSSNSSpanData(span)
case AWSDynamoDBSpanType:
return newAWSDynamoDBSpanData(span)
case AWSLambdaInvokeSpanType:
return newAWSLambdaInvokeSpanData(span)
case LogSpanType:
return newLogSpanData(span)
case MongoDBSpanType:
return newMongoDBSpanData(span)
case PostgreSQLSpanType:
return newPostgreSQLSpanData(span)
case CouchbaseSpanType:
return newCouchbaseSpanData(span)
case CosmosSpanType:
return newCosmosSpanData(span)
case MySQLSpanType:
return newMySQLSpanData(span)
case RedisSpanType:
return newRedisSpanData(span)
case RabbitMQSpanType:
return newRabbitMQSpanData(span)
case AzureFunctionType:
return newAZFSpanData(span)
case GraphQLServerType, GraphQLClientType:
return newGraphQLSpanData(span)
default:
return newSDKSpanData(span)
}
}
// TagsNames returns a set of tag names known to the registered span type
func (st RegisteredSpanType) TagsNames() map[string]struct{} {
var yes struct{}
switch st {
case HTTPServerSpanType, HTTPClientSpanType:
return map[string]struct{}{
"http.url": yes, string(ext.HTTPUrl): yes,
"http.status": yes, "http.status_code": yes,
"http.method": yes, string(ext.HTTPMethod): yes,
"http.path": yes,
"http.params": yes,
"http.header": yes,
"http.path_tpl": yes,
"http.route_id": yes,
"http.host": yes,
"http.protocol": yes,
"http.error": yes,
}
case RPCServerSpanType, RPCClientSpanType:
return map[string]struct{}{
"rpc.host": yes,
"rpc.port": yes,
"rpc.call": yes,
"rpc.call_type": yes,
"rpc.flavor": yes,
"rpc.error": yes,
}
case KafkaSpanType:
return map[string]struct{}{
"kafka.service": yes,
"kafka.access": yes,
}
case GCPStorageSpanType:
return map[string]struct{}{
"gcs.op": yes,
"gcs.bucket": yes,
"gcs.object": yes,
"gcs.entity": yes,
"gcs.range": yes,
"gcs.sourceBucket": yes,
"gcs.sourceObject": yes,
"gcs.destinationBucket": yes,
"gcs.destinationObject": yes,
"gcs.numberOfOperations": yes,
"gcs.projectId": yes,
"gcs.accessId": yes,
}
case GCPPubSubSpanType:
return map[string]struct{}{
"gcps.projid": yes,
"gcps.op": yes,
"gcps.top": yes,
"gcps.sub": yes,
"gcps.msgid": yes,
}
case AWSLambdaEntrySpanType:
return map[string]struct{}{
"lambda.arn": yes,
"lambda.name": yes,
"lambda.version": yes,
"lambda.trigger": yes,
"lambda.coldStart": yes,
"lambda.msleft": yes,
"lambda.error": yes,
"cloudwatch.events.id": yes,
"cloudwatch.events.resources": yes,
"cloudwatch.logs.group": yes,
"cloudwatch.logs.stream": yes,
"cloudwatch.logs.decodingError": yes,
"cloudwatch.logs.events": yes,
"s3.events": yes,
"sqs.messages": yes,
}
case AWSS3SpanType:
return map[string]struct{}{
"s3.region": yes,
"s3.op": yes,
"s3.bucket": yes,
"s3.key": yes,
"s3.error": yes,
}
case AWSSQSSpanType:
return map[string]struct{}{
"sqs.sort": yes,
"sqs.queue": yes,
"sqs.type": yes,
"sqs.group": yes,
"sqs.size": yes,
"sqs.error": yes,
}
case AWSSNSSpanType:
return map[string]struct{}{
"sns.topic": yes,
"sns.target": yes,
"sns.phone": yes,
"sns.subject": yes,
"sns.error": yes,
}
case AWSDynamoDBSpanType:
return map[string]struct{}{
"dynamodb.table": yes,
"dynamodb.op": yes,
"dynamodb.error": yes,
}
case AWSLambdaInvokeSpanType:
return map[string]struct{}{
"function": yes,
"type": yes,
"error": yes,
}
case LogSpanType:
return map[string]struct{}{
"log.message": yes,
"log.level": yes,
"log.parameters": yes,
"log.logger": yes,
}
case MongoDBSpanType:
return map[string]struct{}{
"mongo.service": yes,
"mongo.namespace": yes,
"mongo.command": yes,
"mongo.query": yes,
"mongo.json": yes,
"mongo.filter": yes,
"mongo.error": yes,
}
case PostgreSQLSpanType:
return map[string]struct{}{
"pg.db": yes,
"pg.user": yes,
"pg.stmt": yes,
"pg.host": yes,
"pg.port": yes,
"pg.error": yes,
}
case CouchbaseSpanType:
return map[string]struct{}{
"couchbase.bucket": yes,
"couchbase.hostname": yes,
"couchbase.type": yes,
"couchbase.sql": yes,
"couchbase.error": yes,
}
case MySQLSpanType:
return map[string]struct{}{
"mysql.db": yes,
"mysql.user": yes,
"mysql.stmt": yes,
"mysql.host": yes,
"mysql.port": yes,
"mysql.error": yes,
}
case RedisSpanType:
return map[string]struct{}{
"redis.connection": yes,
"redis.command": yes,
"redis.subCommands": yes,
"redis.error": yes,
}
case RabbitMQSpanType:
return map[string]struct{}{
"rabbitmq.exchange": yes,
"rabbitmq.key": yes,
"rabbitmq.sort": yes,
"rabbitmq.address": yes,
"rabbitmq.error": yes,
}
case AzureFunctionType:
return map[string]struct{}{
"azf.name": yes,
"azf.functionname": yes,
"azf.methodname": yes,
"azf.triggername": yes,
"azf.runtime": yes,
"azf.error": yes,
}
case GraphQLServerType, GraphQLClientType:
return map[string]struct{}{
"graphql.operationName": yes,
"graphql.operationType": yes,
"graphql.fields": yes,
"graphql.args": yes,
"graphql.error": yes,
}
default:
return nil
}
}
// HTTPSpanData represents the `data` section of an HTTP span sent within an OT span document
type HTTPSpanData struct {
SpanData
Tags HTTPSpanTags `json:"http"`
clientSpan bool
}
// newHTTPSpanData initializes a new HTTP span data from tracer span
func newHTTPSpanData(span *spanS) HTTPSpanData {
data := HTTPSpanData{
SpanData: NewSpanData(span, RegisteredSpanType(span.Operation)),
Tags: newHTTPSpanTags(span),
}
kindTag := span.Tags[string(ext.SpanKind)]
data.clientSpan = kindTag == ext.SpanKindRPCClientEnum || kindTag == string(ext.SpanKindRPCClientEnum)
return data
}
// Kind returns instana.EntrySpanKind for server spans and instana.ExitSpanKind otherwise
func (d HTTPSpanData) Kind() SpanKind {
if d.clientSpan {
return ExitSpanKind
}
return EntrySpanKind
}
// HTTPSpanTags contains fields within the `data.http` section of an OT span document
type HTTPSpanTags struct {
// Full request/response URL
URL string `json:"url,omitempty"`
// The HTTP status code returned with client/server response
Status int `json:"status,omitempty"`
// The HTTP method of the request
Method string `json:"method,omitempty"`
// Path is the path part of the request URL
Path string `json:"path,omitempty"`
// Params are the request query string parameters
Params string `json:"params,omitempty"`
// Headers are the captured request/response headers
Headers map[string]string `json:"header,omitempty"`
// PathTemplate is the raw template string used to route the request
PathTemplate string `json:"path_tpl,omitempty"`
// RouteID is an optional name/identifier for the matched route
RouteID string `json:"route_id,omitempty"`
// The name:port of the host to which the request had been sent
Host string `json:"host,omitempty"`
// The name of the protocol used for request ("http" or "https")
Protocol string `json:"protocol,omitempty"`
// The message describing an error occurred during the request handling
Error string `json:"error,omitempty"`
}
// newHTTPSpanTags extracts HTTP-specific span tags from a tracer span
func newHTTPSpanTags(span *spanS) HTTPSpanTags {
var tags HTTPSpanTags
for k, v := range span.Tags {
switch k {
case "http.url", string(ext.HTTPUrl):
readStringTag(&tags.URL, v)
case "http.status", "http.status_code":
readIntTag(&tags.Status, v)
case "http.method", string(ext.HTTPMethod):
readStringTag(&tags.Method, v)
case "http.path":
readStringTag(&tags.Path, v)
case "http.params":
readStringTag(&tags.Params, v)
case "http.header":
if m, ok := v.(map[string]string); ok {
tags.Headers = m
}
case "http.path_tpl":
readStringTag(&tags.PathTemplate, v)
case "http.route_id":
readStringTag(&tags.RouteID, v)
case "http.host":
readStringTag(&tags.Host, v)
case "http.protocol":
readStringTag(&tags.Protocol, v)
case "http.error":
readStringTag(&tags.Error, v)
}
}
return tags
}
// RPCSpanData represents the `data` section of an RPC span sent within an OT span document
type RPCSpanData struct {
SpanData
Tags RPCSpanTags `json:"rpc"`
clientSpan bool
}
// newRPCSpanData initializes a new RPC span data from tracer span
func newRPCSpanData(span *spanS) RPCSpanData {
data := RPCSpanData{
SpanData: NewSpanData(span, RegisteredSpanType(span.Operation)),
Tags: newRPCSpanTags(span),
}
kindTag := span.Tags[string(ext.SpanKind)]
data.clientSpan = kindTag == ext.SpanKindRPCClientEnum || kindTag == (ext.SpanKindRPCClientEnum)
return data
}
// Kind returns instana.EntrySpanKind for server spans and instana.ExitSpanKind otherwise
func (d RPCSpanData) Kind() SpanKind {
if d.clientSpan {
return ExitSpanKind
}
return EntrySpanKind
}
// RPCSpanTags contains fields within the `data.rpc` section of an OT span document
type RPCSpanTags struct {
// The name of the remote host for an RPC call
Host string `json:"host,omitempty"`
// The port of the remote host for an RPC call
Port string `json:"port,omitempty"`
// The name of the remote method to invoke
Call string `json:"call,omitempty"`
// The type of an RPC call, e.g. either "unary" or "stream" for GRPC requests
CallType string `json:"call_type,omitempty"`
// The RPC flavor used for this call, e.g. "grpc" for GRPC requests
Flavor string `json:"flavor,omitempty"`
// The message describing an error occurred during the request handling
Error string `json:"error,omitempty"`
}
// newRPCSpanTags extracts RPC-specific span tags from a tracer span
func newRPCSpanTags(span *spanS) RPCSpanTags {
var tags RPCSpanTags
for k, v := range span.Tags {
switch k {
case "rpc.host":
readStringTag(&tags.Host, v)
case "rpc.port":
readStringTag(&tags.Port, v)
case "rpc.call":
readStringTag(&tags.Call, v)
case "rpc.call_type":
readStringTag(&tags.CallType, v)
case "rpc.flavor":
readStringTag(&tags.Flavor, v)
case "rpc.error":
readStringTag(&tags.Error, v)
}
}
return tags
}
// KafkaSpanData represents the `data` section of an Kafka span sent within an OT span document
type KafkaSpanData struct {
SpanData
Tags KafkaSpanTags `json:"kafka"`
producerSpan bool
}
// newKafkaSpanData initializes a new Kafka span data from tracer span
func newKafkaSpanData(span *spanS) KafkaSpanData {
data := KafkaSpanData{
SpanData: NewSpanData(span, RegisteredSpanType(span.Operation)),
Tags: newKafkaSpanTags(span),
}
kindTag := span.Tags[string(ext.SpanKind)]
data.producerSpan = kindTag == ext.SpanKindProducerEnum || kindTag == string(ext.SpanKindProducerEnum)
return data
}
// Kind returns instana.ExitSpanKind for producer spans and instana.EntrySpanKind otherwise
func (d KafkaSpanData) Kind() SpanKind {
if d.producerSpan {
return ExitSpanKind
}
return EntrySpanKind
}
// KafkaSpanTags contains fields within the `data.kafka` section of an OT span document
type KafkaSpanTags struct {
// Kafka topic
Service string `json:"service"`
// The access mode:, either "send" for publisher or "consume" for consumer
Access string `json:"access"`
}
// newKafkaSpanTags extracts Kafka-specific span tags from a tracer span
func newKafkaSpanTags(span *spanS) KafkaSpanTags {
var tags KafkaSpanTags
for k, v := range span.Tags {
switch k {
case "kafka.service":
readStringTag(&tags.Service, v)
case "kafka.access":
readStringTag(&tags.Access, v)
}
}
return tags
}
// RabbitMQSpanData represents the `data` section of an RabbitMQ span
type RabbitMQSpanData struct {
SpanData
Tags RabbitMQSpanTags `json:"rabbitmq"`
producerSpan bool
}
// newRabbitMQSpanData initializes a new RabbitMQ span data from tracer span
func newRabbitMQSpanData(span *spanS) RabbitMQSpanData {
data := RabbitMQSpanData{
SpanData: NewSpanData(span, RegisteredSpanType(span.Operation)),
Tags: newRabbitMQSpanTags(span),
}
kindTag := span.Tags[string(ext.SpanKind)]
data.producerSpan = kindTag == ext.SpanKindProducerEnum || kindTag == string(ext.SpanKindProducerEnum)
return data
}
// Kind returns instana.ExitSpanKind for producer spans and instana.EntrySpanKind otherwise
func (d RabbitMQSpanData) Kind() SpanKind {
if d.producerSpan {
return ExitSpanKind
}
return EntrySpanKind
}
// RabbitMQSpanTags contains fields within the `data.rabbitmq` section
type RabbitMQSpanTags struct {
// The RabbitMQ exchange name
Exchange string `json:"exchange"`
// The routing key
Key string `json:"key"`
// Indicates wether the message is being produced or consumed
Sort string `json:"sort"`
// The AMQP URI used to establish a connection to RabbitMQ
Address string `json:"address"`
// Error is the optional error that can be thrown by RabbitMQ when executing a command
Error string `json:"error,omitempty"`
}
// newRabbitMQSpanTags extracts RabbitMQ-specific span tags from a tracer span
func newRabbitMQSpanTags(span *spanS) RabbitMQSpanTags {
var tags RabbitMQSpanTags
for k, v := range span.Tags {
switch k {
case "rabbitmq.exchange":
readStringTag(&tags.Exchange, v)
case "rabbitmq.key":
readStringTag(&tags.Key, v)
case "rabbitmq.sort":
readStringTag(&tags.Sort, v)
case "rabbitmq.address":
readStringTag(&tags.Address, v)
case "rabbitmq.error":
readStringTag(&tags.Error, v)
}
}
return tags
}
// GCPStorageSpanData represents the `data` section of a Google Cloud Storage span sent within an OT span document
type GCPStorageSpanData struct {
SpanData
Tags GCPStorageSpanTags `json:"gcs"`
}
// newGCPStorageSpanData initializes a new Google Cloud Storage span data from tracer span
func newGCPStorageSpanData(span *spanS) GCPStorageSpanData {
data := GCPStorageSpanData{
SpanData: NewSpanData(span, GCPStorageSpanType),
Tags: newGCPStorageSpanTags(span),
}
return data
}
// Kind returns the span kind for a Google Cloud Storage span
func (d GCPStorageSpanData) Kind() SpanKind {
return ExitSpanKind
}
// GCPStorageSpanTags contains fields within the `data.gcs` section of an OT span document
type GCPStorageSpanTags struct {
Operation string `json:"op,omitempty"`
Bucket string `json:"bucket,omitempty"`
Object string `json:"object,omitempty"`
Entity string `json:"entity,omitempty"`
Range string `json:"range,omitempty"`
SourceBucket string `json:"sourceBucket,omitempty"`
SourceObject string `json:"sourceObject,omitempty"`
DestinationBucket string `json:"destinationBucket,omitempty"`
DestinationObject string `json:"destinationObject,omitempty"`
NumberOfOperations string `json:"numberOfOperations,omitempty"`
ProjectID string `json:"projectId,omitempty"`
AccessID string `json:"accessId,omitempty"`
}
// newGCPStorageSpanTags extracts Google Cloud Storage span tags from a tracer span
func newGCPStorageSpanTags(span *spanS) GCPStorageSpanTags {
var tags GCPStorageSpanTags
for k, v := range span.Tags {
switch k {
case "gcs.op":
readStringTag(&tags.Operation, v)
case "gcs.bucket":
readStringTag(&tags.Bucket, v)
case "gcs.object":
readStringTag(&tags.Object, v)
case "gcs.entity":
readStringTag(&tags.Entity, v)
case "gcs.range":
readStringTag(&tags.Range, v)
case "gcs.sourceBucket":
readStringTag(&tags.SourceBucket, v)
case "gcs.sourceObject":
readStringTag(&tags.SourceObject, v)
case "gcs.destinationBucket":
readStringTag(&tags.DestinationBucket, v)
case "gcs.destinationObject":
readStringTag(&tags.DestinationObject, v)
case "gcs.numberOfOperations":
readStringTag(&tags.NumberOfOperations, v)
case "gcs.projectId":
readStringTag(&tags.ProjectID, v)
case "gcs.accessId":
readStringTag(&tags.AccessID, v)
}
}
return tags
}
// GCPPubSubSpanData represents the `data` section of a Google Cloud Pub/Sub span sent within an OT span document
type GCPPubSubSpanData struct {
SpanData
Tags GCPPubSubSpanTags `json:"gcps"`
}
// newGCPPubSubSpanData initializes a new Google Cloud Pub/Span span data from tracer span
func newGCPPubSubSpanData(span *spanS) GCPPubSubSpanData {
data := GCPPubSubSpanData{
SpanData: NewSpanData(span, GCPPubSubSpanType),
Tags: newGCPPubSubSpanTags(span),
}
return data
}
// Kind returns the span kind for a Google Cloud Pub/Sub span
func (d GCPPubSubSpanData) Kind() SpanKind {
switch strings.ToLower(d.Tags.Operation) {
case "consume":
return EntrySpanKind
default:
return ExitSpanKind
}
}
// GCPPubSubSpanTags contains fields within the `data.gcps` section of an OT span document
type GCPPubSubSpanTags struct {
ProjectID string `json:"projid"`
Operation string `json:"op"`
Topic string `json:"top,omitempty"`
Subscription string `json:"sub,omitempty"`
MessageID string `json:"msgid,omitempty"`
}
// newGCPPubSubSpanTags extracts Google Cloud Pub/Sub span tags from a tracer span
func newGCPPubSubSpanTags(span *spanS) GCPPubSubSpanTags {
var tags GCPPubSubSpanTags
for k, v := range span.Tags {
switch k {
case "gcps.projid":
readStringTag(&tags.ProjectID, v)
case "gcps.op":
readStringTag(&tags.Operation, v)
case "gcps.top":
readStringTag(&tags.Topic, v)
case "gcps.sub":
readStringTag(&tags.Subscription, v)
case "gcps.msgid":
readStringTag(&tags.MessageID, v)
}
}
return tags
}
// AWSLambdaCloudWatchSpanTags contains fields within the `data.lambda.cw` section of an OT span document
type AWSLambdaCloudWatchSpanTags struct {
Events *AWSLambdaCloudWatchEventTags `json:"events,omitempty"`
Logs *AWSLambdaCloudWatchLogsTags `json:"logs,omitempty"`
}
// newAWSLambdaCloudWatchSpanTags extracts CloudWatch tags for an AWS Lambda entry span
func newAWSLambdaCloudWatchSpanTags(span *spanS) AWSLambdaCloudWatchSpanTags {
var tags AWSLambdaCloudWatchSpanTags
if events := newAWSLambdaCloudWatchEventTags(span); !events.IsZero() {
tags.Events = &events
}
if logs := newAWSLambdaCloudWatchLogsTags(span); !logs.IsZero() {
tags.Logs = &logs
}
return tags
}
// IsZero returns true if an AWSLambdaCloudWatchSpanTags struct was populated with event data
func (tags AWSLambdaCloudWatchSpanTags) IsZero() bool {
return (tags.Events == nil || tags.Events.IsZero()) && (tags.Logs == nil || tags.Logs.IsZero())
}
// AWSLambdaCloudWatchEventTags contains fields within the `data.lambda.cw.events` section of an OT span document
type AWSLambdaCloudWatchEventTags struct {
// ID is the ID of the event
ID string `json:"id"`
// Resources contains the event resources
Resources []string `json:"resources"`
// More is set to true if the event resources list was truncated
More bool `json:"more,omitempty"`
}
// newAWSLambdaCloudWatchEventTags extracts CloudWatch event tags for an AWS Lambda entry span. It truncates
// the resources list to the first 3 items, populating the `data.lambda.cw.events.more` tag and limits each
// resource string to the first 200 characters to reduce the payload.
func newAWSLambdaCloudWatchEventTags(span *spanS) AWSLambdaCloudWatchEventTags {
var tags AWSLambdaCloudWatchEventTags
if v, ok := span.Tags["cloudwatch.events.id"]; ok {
readStringTag(&tags.ID, v)
}
if v, ok := span.Tags["cloudwatch.events.resources"]; ok {
switch v := v.(type) {
case []string:
if len(v) > 3 {
v = v[:3]
tags.More = true
}
tags.Resources = v
case string:
tags.Resources = []string{v}
case []byte:
tags.Resources = []string{string(v)}
}
}
// truncate resources
if len(tags.Resources) > 3 {
tags.Resources, tags.More = tags.Resources[:3], true
}
for i := range tags.Resources {
if len(tags.Resources[i]) > 200 {
tags.Resources[i] = tags.Resources[i][:200]
}
}
return tags
}
// IsZero returns true if an AWSCloudWatchEventTags struct was populated with event data
func (tags AWSLambdaCloudWatchEventTags) IsZero() bool {
return tags.ID == ""
}
// AWSLambdaCloudWatchLogsTags contains fields within the `data.lambda.cw.logs` section of an OT span document
type AWSLambdaCloudWatchLogsTags struct {
Group string `json:"group"`
Stream string `json:"stream"`
Events []string `json:"events"`
More bool `json:"more,omitempty"`
DecodingError string `json:"decodingError,omitempty"`
}
// newAWSLambdaCloudWatchLogsTags extracts CloudWatch Logs tags for an AWS Lambda entry span. It truncates
// the log events list to the first 3 items, populating the `data.lambda.cw.logs.more` tag and limits each
// log string to the first 200 characters to reduce the payload.
func newAWSLambdaCloudWatchLogsTags(span *spanS) AWSLambdaCloudWatchLogsTags {
var tags AWSLambdaCloudWatchLogsTags
if v, ok := span.Tags["cloudwatch.logs.group"]; ok {
readStringTag(&tags.Group, v)
}
if v, ok := span.Tags["cloudwatch.logs.stream"]; ok {
readStringTag(&tags.Stream, v)
}
if v, ok := span.Tags["cloudwatch.logs.decodingError"]; ok {
switch v := v.(type) {
case error:
tags.DecodingError = v.Error()
case string:
tags.DecodingError = v
}
}
if v, ok := span.Tags["cloudwatch.logs.events"]; ok {
switch v := v.(type) {
case []string:
if len(v) > 3 {
v = v[:3]
tags.More = true
}
tags.Events = v
case string:
tags.Events = []string{v}
case []byte:
tags.Events = []string{string(v)}
}
}
// truncate events
if len(tags.Events) > 3 {
tags.Events, tags.More = tags.Events[:3], true
}
for i := range tags.Events {
if len(tags.Events[i]) > 200 {
tags.Events[i] = tags.Events[i][:200]
}
}
return tags
}
// IsZero returns true if an AWSLambdaCloudWatchLogsTags struct was populated with logs data
func (tags AWSLambdaCloudWatchLogsTags) IsZero() bool {
return tags.Group == "" && tags.Stream == "" && tags.DecodingError == ""
}
// AWSS3EventTags represens metadata for an S3 event
type AWSS3EventTags struct {
Name string `json:"event"`
Bucket string `json:"bucket"`
Object string `json:"object,omitempty"`
}
// AWSLambdaS3SpanTags contains fields within the `data.lambda.s3` section of an OT span document
type AWSLambdaS3SpanTags struct {
Events []AWSS3EventTags `json:"events,omitempty"`
}
// newAWSLambdaS3SpanTags extracts S3 Event tags for an AWS Lambda entry span. It truncates
// the events list to the first 3 items and limits each object names to the first 200 characters to reduce the payload.
func newAWSLambdaS3SpanTags(span *spanS) AWSLambdaS3SpanTags {
var tags AWSLambdaS3SpanTags
if events, ok := span.Tags["s3.events"]; ok {
events, ok := events.([]AWSS3EventTags)
if ok {
tags.Events = events
}
}
if len(tags.Events) > 3 {
tags.Events = tags.Events[:3]
}
for i := range tags.Events {
if len(tags.Events[i].Object) > 200 {
tags.Events[i].Object = tags.Events[i].Object[:200]
}
}
return tags
}
// IsZero returns true if an AWSLambdaS3SpanTags struct was populated with events data
func (tags AWSLambdaS3SpanTags) IsZero() bool {
return len(tags.Events) == 0
}
// AWSSQSMessageTags represents span tags for an SQS message delivery
type AWSSQSMessageTags struct {
Queue string `json:"queue"`
}
// AWSLambdaSQSSpanTags contains fields within the `data.lambda.sqs` section of an OT span document
type AWSLambdaSQSSpanTags struct {
// Messages are message tags for an SQS event
Messages []AWSSQSMessageTags `json:"messages"`
}
// newAWSLambdaSQSSpanTags extracts SQS event tags for an AWS Lambda entry span. It truncates
// the events list to the first 3 items to reduce the payload.
func newAWSLambdaSQSSpanTags(span *spanS) AWSLambdaSQSSpanTags {
var tags AWSLambdaSQSSpanTags
if msgs, ok := span.Tags["sqs.messages"]; ok {
msgs, ok := msgs.([]AWSSQSMessageTags)
if ok {
tags.Messages = msgs
}
}
if len(tags.Messages) > 3 {
tags.Messages = tags.Messages[:3]
}
return tags
}
// IsZero returns true if an AWSLambdaSQSSpanTags struct was populated with messages data
func (tags AWSLambdaSQSSpanTags) IsZero() bool {
return len(tags.Messages) == 0
}
// AWSLambdaSpanTags contains fields within the `data.lambda` section of an OT span document
type AWSLambdaSpanTags struct {
// ARN is the ARN of invoked AWS Lambda function with the version attached
ARN string `json:"arn"`
// Runtime is an Instana constant for this AWS lambda runtime (always "go")
Runtime string `json:"runtime"`
// Name is the name of invoked function
Name string `json:"functionName,omitempty"`
// Version is either the numeric version or $LATEST
Version string `json:"functionVersion,omitempty"`
// Trigger is the trigger event type (if any)
Trigger string `json:"trigger,omitempty"`
// ColdStart is true if this is the first time current instance of the function was invoked
ColdStart bool `json:"coldStart,omitempty"`
// MillisecondsLeft is a number of milliseconds until timeout
MillisecondsLeft int `json:"msleft,omitempty"`
// Error is an AWS Lambda specific error
Error string `json:"error,omitempty"`
// CloudWatch holds the details of a CloudWatch event associated with this lambda
CloudWatch *AWSLambdaCloudWatchSpanTags `json:"cw,omitempty"`
// S3 holds the details of a S3 events associated with this lambda
S3 *AWSLambdaS3SpanTags
// SQS holds the details of a SQS events associated with this lambda
SQS *AWSLambdaSQSSpanTags
}
// newAWSLambdaSpanTags extracts AWS Lambda entry span tags from a tracer span
func newAWSLambdaSpanTags(span *spanS) AWSLambdaSpanTags {
tags := AWSLambdaSpanTags{Runtime: "go"}
if v, ok := span.Tags["lambda.arn"]; ok {
readStringTag(&tags.ARN, v)
}
if v, ok := span.Tags["lambda.name"]; ok {
readStringTag(&tags.Name, v)
}
if v, ok := span.Tags["lambda.version"]; ok {
readStringTag(&tags.Version, v)
}
if v, ok := span.Tags["lambda.trigger"]; ok {
readStringTag(&tags.Trigger, v)
}
if v, ok := span.Tags["lambda.coldStart"]; ok {
readBoolTag(&tags.ColdStart, v)
}
if v, ok := span.Tags["lambda.msleft"]; ok {
readIntTag(&tags.MillisecondsLeft, v)
}
if v, ok := span.Tags["lambda.error"]; ok {