forked from aws/aws-xray-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package lambda | ||
|
||
import ( | ||
"github.com/aws/aws-lambda-go/events" | ||
"strings" | ||
) | ||
|
||
func IsSampled(sqsMessge *events.SQSMessage) bool { | ||
value, ok := sqsMessge.Attributes["AWSTraceHeader"] | ||
|
||
if !ok { | ||
return false | ||
} else { | ||
return strings.Contains(value, "Sampled=1") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package lambda | ||
|
||
import ( | ||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestSQSMessageHelper(t *testing.T) { | ||
testTrue(t, "Root=1-632BB806-bd862e3fe1be46a994272793;Sampled=1") | ||
testTrue(t, "Root=1-5759e988-bd862e3fe1be46a994272793;Sampled=1") | ||
testTrue(t, "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1") | ||
|
||
testFalse(t, "Root=1-632BB806-bd862e3fe1be46a994272793") | ||
testFalse(t, "Root=1-632BB806-bd862e3fe1be46a994272793;Sampled=0") | ||
testFalse(t, "Root=1-5759e988-bd862e3fe1be46a994272793;Sampled=0") | ||
testFalse(t, "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=0") | ||
} | ||
|
||
func testTrue(t *testing.T, header string) { | ||
var sqsMessage events.SQSMessage | ||
sqsMessage.Attributes = make(map[string]string) | ||
sqsMessage.Attributes["AWSTraceHeader"] = header | ||
assert.True(t, IsSampled(&sqsMessage)) | ||
} | ||
|
||
func testFalse(t *testing.T, header string) { | ||
var sqsMessage events.SQSMessage | ||
sqsMessage.Attributes = make(map[string]string) | ||
sqsMessage.Attributes["AWSTraceHeader"] = header | ||
assert.False(t, IsSampled(&sqsMessage)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters