Go

Instructions for installing the Lumigo tracer in a AWS Lambda function using a Go runtime

Supported Go versions

  • 1.16
  • 1.17
  • 1.18

Setup

Import the Lumigo Tracer as a dependency

$ go get github.com/lumigo-io/[email protected]

Or, if you are already using Go Modules, you may specify a version number as well:

$ go get github.com/lumigo-io/[email protected]

Add the Lumigo Lambda Layer

Add AWS Lambda Layer:

arn:aws:lambda:<your-region>:114300393969:layer:lumigo-tracer-extension:38

Activate the Lumigo extension

Set the LUMIGO_USE_TRACER_EXTENSION environment variable of your Lambda function as follows; refer to the Using AWS Lambda environment variables documentation for more information.

KeyValue
LUMIGO_USE_TRACER_EXTENSIONtrue

Wrapping Your Lambda

You need a Lumigo token which you can find under the Project Settings in the Lumigo platform. Then you need to wrap your Lambda:

import (
        ...
        lumigotracer "github.com/lumigo-io/lumigo-go-tracer"
        os
)

...

func main() {
   wrappedHandler := lumigotracer.WrapHandler(Handler, &lumigotracer.Config{})
   lambda.Start(wrappedHandler)
}

Then the wrapping will look like this:

import (
        ...
        lumigotracer "github.com/lumigo-io/lumigo-go-tracer"
)

...

func main() {
   wrappedHandler := lumigotracer.WrapHandler(Handler, &lumigotracer.Config{})
   lambda.Start(wrappedHandler)
}

Connect Your Lumigo Account

Set your Lumigo token as the LUMIGO_TRACER_TOKEN environment variable of your Lambda function; refer to the Using AWS Lambda environment variables documentation for more information. Your Lumigo token is available in Settings -> Tracing -> Manual tracing, see the Lumigo Tokens documentation.

We advise you to use the most secure available to you to store secrets such as your LUMIGO_TRACER_TOKEN; refer to AWS Lambda's Securing environment variables documentation for guidance on keeping the values of your Lambda environment variables secure.

Track HTTP Requests Beta

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)