Skip to content

Commit

Permalink
Include Lambda trigger event type into the entry span payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Slotin committed Nov 13, 2020
1 parent ae3920f commit e835f89
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions json_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ type AWSLambdaSpanTags struct {
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"`
}

// NewAWSLambdaSpanTags extracts AWS Lambda entry span tags from a tracer span
Expand All @@ -586,6 +588,10 @@ func NewAWSLambdaSpanTags(span *spanS) AWSLambdaSpanTags {
readStringTag(&tags.Version, v)
}

if v, ok := span.Tags["lambda.trigger"]; ok {
readStringTag(&tags.Trigger, v)
}

return tags
}

Expand Down
37 changes: 34 additions & 3 deletions json_span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,40 @@ func TestNewAWSLambdaSpanData(t *testing.T) {
Runtime: "go",
Name: "test-lambda",
Version: "42",
Trigger: "aws:api.gateway",
},
HTTP: &instana.HTTPSpanTags{
URL: "https://example.com/lambda",
Status: 404,
Method: "GET",
Path: "/lambda",
Params: "q=test&secret=classified",
Headers: map[string]string{"x-custom-header-1": "test"},
Host: "example.com",
Protocol: "https",
Error: "Not Found",
},
},
},
"aws:application.load.balancer": {
Tags: opentracing.Tags{
"http.protocol": "https",
"http.url": "https://example.com/lambda",
"http.host": "example.com",
"http.method": "GET",
"http.path": "/lambda",
"http.params": "q=test&secret=classified",
"http.header": map[string]string{"x-custom-header-1": "test"},
"http.status": 404,
"http.error": "Not Found",
},
Expected: instana.AWSLambdaSpanData{
Snapshot: instana.AWSLambdaSpanTags{
ARN: "lambda-arn-1",
Runtime: "go",
Name: "test-lambda",
Version: "42",
Trigger: "aws:application.load.balancer",
},
HTTP: &instana.HTTPSpanTags{
URL: "https://example.com/lambda",
Expand All @@ -125,9 +159,6 @@ func TestNewAWSLambdaSpanData(t *testing.T) {
},
}

// ALB tags set is the same as for API Gateway, so we just copy it over
examples["aws:application.load.balancer"] = examples["aws:api.gateway"]

for trigger, example := range examples {
t.Run(trigger, func(t *testing.T) {
recorder := instana.NewTestRecorder()
Expand Down

0 comments on commit e835f89

Please sign in to comment.