lumigo-go-tracer
This is lumigo/lumigo-go-tracer, Lumigo's Golang tracer for distributed tracing and monitoring.
Supported Go versions: 1.16, 1.17 and 1.18
Installation
lumigo-go-tracer
can be installed like any other Go library through go get
:
$ go get github.com/lumigo-io/lumigo-go-tracer
Or, if you are already using
Go Modules, you may specify a
version number as well:
$ go get github.com/lumigo-io/lumigo-go-tracer@master
Configuration
Lumigo Go tracer offers several different configuration options. Pass these to the Lambda function as environment variables:
Name |
Type |
Description |
Required |
LUMIGO_USE_TRACER_EXTENSION |
bool |
Enables usage of Go tracer |
true |
LUMIGO_DEBUG |
bool |
Enables debug logging |
false |
LUMIGO_TRACER_TOKEN |
string |
Your Lumigo token |
false |
Usage
Add AWS Lambda Layer:
arn:aws:lambda:<your-region>:114300393969:layer:lumigo-tracer-extension:38
Add Environment variable:
LUMIGO_USE_TRACER_EXTENSION=true
Setup - Code
You need a lumigo token which you can find under the Project Settings
and Tracing
tab in lumigo platform. Then you need to wrap your Lambda:
import (
//other imports
lumigotracer "github.com/lumigo-io/lumigo-go-tracer"
)
type MyEvent struct {
Name string `json:"name"`
}
func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
return fmt.Sprintf("Hello %s!", name.Name ), nil
}
func main() {
wrappedHandler := lumigotracer.WrapHandler(HandleRequest, &lumigotracer.Config{
Token: "<your-token>",
})
lambda.Start(wrappedHandler)
}
Another option is to pass the token via the environment variable: LUMIGO_TRACER_TOKEN
.
Then the wrapping will look like this:
wrappedHandler := lumigotracer.WrapHandler(HandleRequest, &lumigotracer.Config{})
HTTP Tracking
For tracing AWS SDK v2.0 calls check the following example:
client := &http.Client{
Transport: lumigotracer.NewTransport(http.DefaultTransport),
}
// for AWS SDK v1.x
sess := session.Must(session.NewSession(&aws.Config{
HTTPClient: client,
}))
svc := s3.New(sess)
// for AWS SDK v2.x
cfg, _ := config.LoadDefaultConfig(context.Background(), config.WithHTTPClient(client))
svc := s3.NewFromConfig(cfg)
For tracing HTTP calls check the following example:
client := &http.Client{
Transport: lumigotracer.NewTransport(http.DefaultTransport),
}
req, _ := http.NewRequest("GET", "https://<your-url>", nil)
// for net/http
res, err := client.Do(req)
// for golang.org/x/net/context/ctxhttp
res, err := ctxhttp.Do(context.Background(), client, req)
Contributing
Contributions to this project are welcome from all! Below are a couple pointers on how to prepare your machine, as well as some information on testing.
If you want to deploy the example lambda for real testing you need:
Lint
Linting the codebase:
make lint
Test suite
Run the test suite:
make test
Check styles
Runs go vet and lint in parallel
make checks
Deploy example
Deploys in AWS a lambda function wrapped by tracer and prints tracing in logs (stdout):
export AWS_PROFILE=<your-profile>
make deploy-example
After you finished testing just destroy the AWS infrastructure resources for Lambda:
export AWS_PROFILE=<your-profile>
make destroy-example
Releases
Everytime we merge in master we push a new release version. Based on the semantic versioning
we use the follow format:
Patch Release
Example commit message:
patch: fix a buf for spans
Minor Release
Example commit message:
minor: add a feature for tracking http
Major Release
Example commit message:
major: upgrade telemetry sdk
After merging, a new tag will be pushed on the previous available version. IN parallel a Github Release will be pushed automatically.