Skip to content

Commit

Permalink
Add instana.AWSSQSSpanType
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Slotin committed Jan 22, 2021
1 parent b238efc commit fa6166d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 7 deletions.
87 changes: 80 additions & 7 deletions json_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
AWSLambdaEntrySpanType = RegisteredSpanType("aws.lambda.entry")
// AWS S3 client span
AWSS3SpanType = RegisteredSpanType("s3")
// AWS SQS client span
AWSSQSSpanType = RegisteredSpanType("sqs")
)

// RegisteredSpanType represents the span type supported by Instana
Expand All @@ -67,6 +69,8 @@ func (st RegisteredSpanType) ExtractData(span *spanS) typedSpanData {
return NewAWSLambdaSpanData(span)
case AWSS3SpanType:
return NewAWSS3SpanData(span)
case AWSSQSSpanType:
return NewAWSSQSSpanData(span)
default:
return NewSDKSpanData(span)
}
Expand Down Expand Up @@ -944,12 +948,16 @@ func (d AWSS3SpanData) Kind() SpanKind {

// AWSS3SpanTags contains fields within the `data.s3` section of an OT span document
type AWSS3SpanTags struct {
Region string `json:"region,omitempty"`
// Region is the AWS region used to access S3
Region string `json:"region,omitempty"`
// Operation is the operation name, as defined by AWS S3 API
Operation string `json:"op,omitempty"`
Bucket string `json:"bucket,omitempty"`
Key string `json:"key,omitempty"`
Exists string `json:"exists,omitempty"`
Error string `json:"error,omitempty"`
// Bucket is the bucket name
Bucket string `json:"bucket,omitempty"`
// Key is the object key
Key string `json:"key,omitempty"`
// Error is an optional error returned by AWS API
Error string `json:"error,omitempty"`
}

// NewAWSS3SpanTags extracts AWS S3 span tags from a tracer span
Expand All @@ -965,8 +973,6 @@ func NewAWSS3SpanTags(span *spanS) AWSS3SpanTags {
readStringTag(&tags.Bucket, v)
case "s3.key":
readStringTag(&tags.Key, v)
case "s3.exists":
readStringTag(&tags.Exists, v)
case "s3.error":
readStringTag(&tags.Error, v)
}
Expand All @@ -975,6 +981,73 @@ func NewAWSS3SpanTags(span *spanS) AWSS3SpanTags {
return tags
}

// AWSSQSSpanData represents the `data` section of a AWS SQS span sent within an OT span document
type AWSSQSSpanData struct {
SpanData
Tags AWSSQSSpanTags `json:"sqs"`
}

// NewAWSSQSSpanData initializes a new AWS SQS span data from tracer span
func NewAWSSQSSpanData(span *spanS) AWSSQSSpanData {
data := AWSSQSSpanData{
SpanData: NewSpanData(span, AWSSQSSpanType),
Tags: NewAWSSQSSpanTags(span),
}

return data
}

// Kind returns the span kind for a AWS SQS span
func (d AWSSQSSpanData) Kind() SpanKind {
switch d.Tags.Sort {
case "entry":
return EntrySpanKind
case "exit":
return ExitSpanKind
default:
return IntermediateSpanKind
}
}

// AWSSQSSpanTags contains fields within the `data.sqs` section of an OT span document
type AWSSQSSpanTags struct {
// Sort is the direction of the call, wither "entry" or "exit"
Sort string `json:"sort,omitempty"`
// Queue is the queue name
Queue string `json:"queue,omitempty"`
// Type is the operation name
Type string `json:"type,omitempty"`
// MessageGroupID is the message group ID specified while sending messages
MessageGroupID string `json:"group,omitempty"`
// Size is the optional batch size
Size int `json:"size,omitempty"`
// Error is an optional error returned by AWS API
Error string `json:"error,omitempty"`
}

// NewAWSSQSSpanTags extracts AWS SQS span tags from a tracer span
func NewAWSSQSSpanTags(span *spanS) AWSSQSSpanTags {
var tags AWSSQSSpanTags
for k, v := range span.Tags {
switch k {
case "sqs.sort":
readStringTag(&tags.Sort, v)
case "sqs.queue":
readStringTag(&tags.Queue, v)
case "sqs.type":
readStringTag(&tags.Type, v)
case "sqs.group":
readStringTag(&tags.MessageGroupID, v)
case "sqs.size":
readIntTag(&tags.Size, v)
case "sqs.error":
readStringTag(&tags.Error, v)
}
}

return tags
}

// readStringTag populates the &dst with the tag value if it's of either string or []byte type
func readStringTag(dst *string, tag interface{}) {
switch s := tag.(type) {
Expand Down
4 changes: 4 additions & 0 deletions json_span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func TestRegisteredSpanType_ExtractData(t *testing.T) {
Operation: "s3",
Expected: instana.AWSS3SpanData{},
},
"aws sqs": {
Operation: "sqs",
Expected: instana.AWSSQSSpanData{},
},
}

for name, example := range examples {
Expand Down

0 comments on commit fa6166d

Please sign in to comment.