lumigotracer

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2022 License: Apache-2.0 Imports: 33 Imported by: 14

README

CircleCI Go Report Card codecov GoDoc

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

Setup - Configure Your Environment

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 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)

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.

Required Tools:
  • go v1.16 and later
  • make

If you want to deploy the example lambda for real testing you need:

  • terraform 0.14.5
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.

Documentation

Index

Constants

View Source
const SPANS_DIR = "/tmp/lumigo-spans"

Variables

View Source
var ErrInvalidToken = errors.New("invalid Token. Go to Lumigo Settings to get a valid token")

ErrInvalidToken an error about a missing token

Functions

func NewTracer

func NewTracer(ctx context.Context, cfg Config, payload json.RawMessage) (retTracer *tracer, err error)

func WrapHandler

func WrapHandler(handler interface{}, conf *Config) interface{}

WrapHandler wraps the lambda handler

Types

type Config

type Config struct {

	// Token is used to interact with Lumigo API
	Token string

	// PrintStdout prints in stdout
	PrintStdout bool

	// Maximium size for request body, request header, response body and response header
	MaxEntrySize int

	// MaxSizeForRequest is the maximum amount of byte to be sent to the edge
	MaxSizeForRequest int
	// contains filtered or unexported fields
}

Config describes the struct about the configuration of the wrap handler for tracer

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter exports OpenTelemetry data to Lumigo.

func (*Exporter) ExportSpans

func (e *Exporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error

ExportSpans writes spans in json format to file.

func (*Exporter) Shutdown

func (e *Exporter) Shutdown(ctx context.Context) error

Shutdown is called to stop the exporter, it preforms no action.

type LogFormatter added in v0.1.0

type LogFormatter struct{}

Log custom format

func (*LogFormatter) Format added in v0.1.0

func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error)

Format details

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

func NewTransport

func NewTransport(transport http.RoundTripper) *Transport

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL