-
Notifications
You must be signed in to change notification settings - Fork 43
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
1 parent
8845061
commit ecfddc3
Showing
3 changed files
with
36 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,49 @@ | ||
# dd-lambda-go | ||
|
||
Datadog's Lambda Go client library enables distributed tracing between serverful and serverless environments. | ||
|
||
## Installation | ||
|
||
```bash | ||
go get github.com/DataDog/dd-lambda-go | ||
``` | ||
|
||
## Usage | ||
|
||
Datadog needs to be able to read headers from the incoming Lambda event, in order to add datadog metadata to the go context. | ||
Wrap your lambda handler like so. | ||
Datadog needs to be able to read headers from the incoming Lambda event. Wrap your Lambda handler function like so: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/DataDog/dd-lambda-go" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/DataDog/dd-lambda-go" | ||
) | ||
|
||
func main() { | ||
// Wrap your lambda handler like this | ||
lambda.Start( ddlambda.WrapHandler(myHandler)) | ||
// Wrap your lambda handler like this | ||
lambda.Start( ddlambda.WrapHandler(myHandler)) | ||
} | ||
|
||
func myHandler(ctx context.Context, event MyEvent) (string, error) { | ||
// Add headers to outbound using the context object | ||
req, err := http.NewRequest("GET", "http://api.youcompany.com/status") | ||
ddlambda.AddTraceHeaders(ctx) | ||
// ... | ||
} | ||
``` | ||
|
||
client := http.Client{} | ||
client.Do(req) | ||
Make sure any outbound requests have Datadog's tracing headers. | ||
|
||
return "Success", nil | ||
```go | ||
req, err := http.NewRequest("GET", "http://api.youcompany.com/status") | ||
// Use the same Context object given to your lambda handler. | ||
ddlambda.AddTraceHeaders(ctx, req) | ||
|
||
client := http.Client{} | ||
client.Do(req) | ||
} | ||
``` | ||
``` | ||
|
||
## Non-proxy integration | ||
|
||
If your Lambda function is triggered by API Gateway via the non-proxy integration, then you have to set up a mapping template, which passes the Datadog trace context from the incoming HTTP request headers to the Lambda function via the event object. | ||
|
||
If your Lambda function is deployed by the Serverless Framework, such a mapping template gets created by default. |
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