All Projects → epsagon → Epsagon Go

epsagon / Epsagon Go

Licence: mit
Automated tracing library for Go 1.x ⚡️

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Epsagon Go

Iopipe Js Core
Observe and develop serverless apps with confidence on AWS Lambda with Tracing, Metrics, Profiling, Monitoring, and more.
Stars: ✭ 123 (+412.5%)
Mutual labels:  serverless, aws-lambda, lambda, monitoring, debugging
Aws Node Elasticache Vpc
Serverless function using elasticache (redis) within VPC
Stars: ✭ 22 (-8.33%)
Mutual labels:  serverless, aws-lambda, lambda, serverless-functions
Gcf.cr
gcf.cr provides serverless execution and deployment of crystal language code in Google Cloud Functions
Stars: ✭ 51 (+112.5%)
Mutual labels:  serverless, lambda, serverless-functions, lambda-functions
Lamb
monitoring tool for better visibility when developing AWS Lambda functions
Stars: ✭ 11 (-54.17%)
Mutual labels:  serverless, aws-lambda, lambda, monitoring
List Lambdas
Enumerate Lambda functions across all regions with useful metadata 💡💵⚙
Stars: ✭ 156 (+550%)
Mutual labels:  serverless, aws-lambda, lambda, serverless-functions
Lambcycle
🐑🛵 A declarative lambda middleware with life cycle hooks 🐑🛵
Stars: ✭ 88 (+266.67%)
Mutual labels:  serverless, aws-lambda, lambda, lambda-functions
Webiny Js
Enterprise open-source serverless CMS. Includes a headless CMS, page builder, form builder and file manager. Easy to customize and expand. Deploys to AWS.
Stars: ✭ 4,869 (+20187.5%)
Mutual labels:  serverless, aws-lambda, lambda, lambda-functions
Aws Serverless Airline Booking
Airline Booking is a sample web application that provides Flight Search, Flight Payment, Flight Booking and Loyalty points including end-to-end testing, GraphQL and CI/CD. This web application was the theme of Build on Serverless Season 2 on AWS Twitch running from April 24th until end of August in 2019.
Stars: ✭ 1,290 (+5275%)
Mutual labels:  serverless, aws-lambda, lambda, lambda-functions
Aws Lambda List
A list of hopefully useful AWS lambdas and lambda-related resources.
Stars: ✭ 130 (+441.67%)
Mutual labels:  serverless, aws-lambda, lambda, lambda-functions
Serverless Chrome
🌐 Run headless Chrome/Chromium on AWS Lambda
Stars: ✭ 2,625 (+10837.5%)
Mutual labels:  serverless, aws-lambda, lambda, serverless-functions
Serverlessui
A command-line utility for deploying serverless applications to AWS. Complete with custom domains, deploy previews, TypeScript support, and more.
Stars: ✭ 434 (+1708.33%)
Mutual labels:  serverless, lambda, serverless-functions
Serverless Express
Run Node.js web applications and APIs using existing application frameworks on AWS #serverless technologies such as Lambda, API Gateway, Lambda@Edge, and ALB.
Stars: ✭ 4,265 (+17670.83%)
Mutual labels:  serverless, aws-lambda, lambda
Mangum
AWS Lambda & API Gateway support for ASGI
Stars: ✭ 475 (+1879.17%)
Mutual labels:  serverless, aws-lambda, lambda
Downloadthisvideo
Twitter bot for easily downloading videos/GIFs off tweets
Stars: ✭ 530 (+2108.33%)
Mutual labels:  serverless, aws-lambda, lambda-functions
Serverless Rust
⚡ 🦀 a serverless framework plugin for rustlang applications
Stars: ✭ 386 (+1508.33%)
Mutual labels:  serverless, aws-lambda, lambda
Puppeteer Lambda Starter Kit
Starter Kit for running Headless-Chrome by Puppeteer on AWS Lambda.
Stars: ✭ 563 (+2245.83%)
Mutual labels:  serverless, aws-lambda, lambda
Aws Lambda Workshop
Some incremental examples suitable to host an AWS Lambda Functions workshop
Stars: ✭ 18 (-25%)
Mutual labels:  serverless, aws-lambda, lambda
Faas
OpenFaaS - Serverless Functions Made Simple
Stars: ✭ 20,820 (+86650%)
Mutual labels:  serverless, lambda, serverless-functions
Fn
The container native, cloud agnostic serverless platform.
Stars: ✭ 5,046 (+20925%)
Mutual labels:  serverless, lambda, serverless-functions
Archive aws Lambda Go Shim
Author your AWS Lambda functions in Go, effectively.
Stars: ✭ 799 (+3229.17%)
Mutual labels:  serverless, aws-lambda, lambda


Build Status GoDoc

Epsagon Tracing for Go

Trace

This package provides tracing to Go applications for the collection of distributed tracing and performance metrics in Epsagon.

Contents

Installation

To install Epsagon, simply run:

go get github.com/epsagon/epsagon-go

Or using dep:

dep ensure -add github.com/epsagon/epsagon-go

Usage

Tagging Traces

You can add custom tags to your traces, for easier filtering and aggregations.

Add the following call inside your code:

epsagon.Label("key", "value")
epsagon.Label("user_id", user_id)

You can also use it to ship custom metrics:

epsagon.Label("key", "metric")
epsagon.Label("items_in_cart", items_in_cart)

Valid types are string, bool, int and float. Custom labels are not trimmed with the trace events in case the trace is too big

Custom Errors

You can set a trace as an error (although handled correctly) to get an alert or just follow it on the dashboard. Add the following call inside your code:

epsagon.TypeError("My custom error", "Custom Error Type")
# Or manually add an error
epsagon.TypeError(errors.New("My custom error"), "Custom Error Type")

You can also set a tracer as an error with a default error type:

epsagon.Error("My custom error")
# Or manually add an error
epsagon.Error(errors.New("My custom error"))

Valid types are string and error.

Ignored Keys

You can set keys that will be masked in the sent trace from the events metadata to hide selected information:

	config.IgnoredKeys = []string{"password"}
	client := http.Client{Transport: epsagonhttp.NewTracingTransport(ctx)}
	// This password will be masked in the sent trace:
	decodedJSON, err := json.Marshal(map[string]string{"password": "abcde", "animal": "lion"})
	resp, err := client.Post("http://example.com/upload", "application/json", bytes.NewReader(decodedJSON))

Frameworks

The following frameworks are supported by Epsagon:

Framework Supported Version
AWS Lambda All
Generic Function All
HTTP All
Gin All

AWS Lambda

Tracing Lambda functions can be done in the following method:

package main

import (
	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
	"github.com/epsagon/epsagon-go/epsagon"
	"log"
)

func myHandler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
	log.Println("In myHandler, received body: ", request.Body)
	return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
}

func main() {
	log.Println("enter main")
	lambda.Start(epsagon.WrapLambdaHandler(
        epsagon.NewTracerConfig("app-name-stage","epsagon-token"),
        myHandler))
}

Generic

You can instrument a single function, this function can use go routines inside and their operations will still be traced.

func doTask(a int, b string) (int, error) {
	log.Printf("inside doTask: b = %s", b)
	return a + 1, fmt.Errorf("boom")
}
func main() {
	// With Epsagon instrumentation
	config := epsagon.NewTracerConfig("generic-go-wrapper", "")
	config.Debug = true
	response := epsagon.GoWrapper(config, doTask)(5, "hello")
	res2 := response[0].Int()
	errInterface := response[1].Interface()
}

Optionally, you can pass a custom name for your wrapped function. In the epsagon dashboard, your wrapped function will be displayed with your configured name in all the relevant screens: traces search, service map and more.

	response := epsagon.GoWrapper(config, doTask, "<MyInstrumentedFuncName>")(5, "hello")

Concurrent Generic

In order to support more than one function being traced in the same environment (using different goroutines), use this wrapper as shown in the example below. The wrapped function has to receive a context as its first parameter, and pass it to the relevant wrapped operations.

func doTask(ctx context.Context, a int, b string, wg *sync.WaitGroup) (int, error) {
	defer wg.Done()
	log.Printf("inside doTask: b = %s", b)
	client := epsagonhttp.Wrap(http.Client{}, ctx)
	client.Get("https://epsagon.com/")
	return a + 1, fmt.Errorf("boom")
}

func main() {
	config := epsagon.NewTracerConfig("generic-go-wrapper", "")
	config.Debug = true
	var wg sync.WaitGroup
	for i := 0; i < 5; i++ {
		go epsagon.ConcurrentGoWrapper(config, doTask)(i, "hello", &wg)
	}
	wg.Wait()
	time.Sleep(2 * time.Second)
}

Optionally, you can pass a custom name for your wrapped function. In the epsagon dashboard, your wrapped function will be displayed with your configured name in all the relevant screens: traces search, service map and more.

		go epsagon.ConcurrentGoWrapper(config, doTask, "<MyInstrumentedFuncName>")(i, "hello", &wg)

http

Wrapping http handlers with Epsagon:

import (
	"github.com/epsagon/epsagon-go/epsagon"
	epsagonhttp "github.com/epsagon/epsagon-go/wrappers/net/http"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/ping", epsagonhttp.WrapHandleFunc(
		epsagon.NewTracerConfig("test-http-mux", ""),
		func(w http.ResponseWriter, req *http.Request) {
			io.WriteString(w, "pong\n")
		}),
        "my-handler-name",
	)

	http.ListenAndServe(":8080", mux)
}

The third and fourth arguments to epsagonhttp.WrapHandleFunc are optional and set the resource name and the hostname. If the resource name is not set then the wrapped funcdtion name is used and the hostname is taken from the request URL if omitted.

	mux.HandleFunc("/ping", epsagonhttp.WrapHandleFunc(
		epsagon.NewTracerConfig("test-http-mux", ""),
		func(w http.ResponseWriter, req *http.Request) {
			io.WriteString(w, "pong\n")
		}),
        "my-handler-name",
		"test.hostname.com",
	)

To wrap nested libraries you can get the epsagon context from the request context:

client := http.Client{
    Transport: epsagonhttp.NewTracingTransport(req.Context())}
resp, err := client.Get("http://example.com")

gin

You can easily instrument gin applications with Epsagon:

import (
	"github.com/epsagon/epsagon-go/epsagon"
	epsagongin "github.com/epsagon/epsagon-go/wrappers/gin"
	"github.com/gin-gonic/gin"
)

func main() {
	r := epsagongin.GinRouterWrapper{
		IRouter:  gin.Default(),
		Hostname: "my_site",
        Config:   epsagon.NewTracerConfig(
        "test-gin-application", "",
        ),
	}

	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	r.IRouter.(*gin.Engine).Run()

If you want to instument other integrated libraries inside the gin handler you can get the Epsagon context from the gin.Context to do that:

client := http.Client{
    Transport: epsagonhttp.NewTracingTransport(epsagongin.EpsagonContext(c))}
resp, err := client.Get("http://example.com")

Integrations

Epsagon provides out-of-the-box instrumentation (tracing) for many popular frameworks and libraries.

Library Supported Version
net/http Fully supported
aws-sdk-go >=1.10.0
aws-sdk-go-v2 >=0.23.0

net/http

Any http request can be traced using a custom RoundTripper implementation and using that in an http.Client:

import (
	"github.com/epsagon/epsagon-go/wrappers/net/http"
...
	client := http.Client{Transport: epsagonhttp.NewTracingTransport()}
	resp, err := client.Get(anyurl)

If you are already using a custom RoundTripper implementation, such as for AWS V4 request signing, you can wrap it:

import (
	"github.com/epsagon/epsagon-go/wrappers/net/http"
...
	rt := &custom.Roundtripper{}
	client := http.Client{Transport: epsagonhttp.NewWrappedTracingTransport(rt)}
	resp, err := client.Get(anyurl)

The wrapped http.Client functionality exists for backwards compatibility:

import (
	"github.com/epsagon/epsagon-go/wrappers/net/http"
...
	client := epsagonhttp.Wrap(http.Client{})
	resp, err := client.Get(anyurl)

If you want to disable data collection only for the calls made by this client set client.MetadataOnly = true

aws-sdk-go

Wrapping of aws-sdk-go is done through the Session object that has to be created to communicate with AWS:

import (
...
	"github.com/epsagon/epsagon-go/wrappers/aws/aws-sdk-go/aws"
)
    ...
	sess := epsagonawswrapper.WrapSession(session.Must(session.NewSession()))
	svcSQS := sqs.New(sess)

aws-sdk-go-v2

Wrapping of aws-sdk-go-v2 is done through the service object:

import (
...
	"github.com/aws/aws-sdk-go-v2/service/dynamodb"
	"github.com/epsagon/epsagon-go/epsagon"
)

	svc := epsagon.WrapAwsV2Service(dynamodb.New(cfg)).(*dynamodb.Client)
    ...

Configuration

Advanced options can be configured as a parameter to the Config struct to the WrapLambdaHandler or as environment variables.

Parameter Environment Variable Type Default Description
Token EPSAGON_TOKEN String - Epsagon account token
ApplicationName - String - Application name that will be set for traces
MetadataOnly EPSAGON_METADATA Boolean true Whether to send only the metadata (True) or also the payloads (False)
CollectorURL EPSAGON_COLLECTOR_URL String - The address of the trace collector to send trace to
Debug EPSAGON_DEBUG Boolean False Enable debug prints for troubleshooting
SendTimeout EPSAGON_SEND_TIMEOUT_SEC String 1s The timeout duration to send the traces to the trace collector

Getting Help

If you have any issue around using the library or the product, please don't hesitate to:

  • Use the documentation.
  • Use the help widget inside the product.
  • Open an issue in GitHub.

Opening Issues

If you encounter a bug with the Epsagon library for Go, we want to hear about it.

When opening a new issue, please provide as much information about the environment:

  • Library version, Go runtime version, dependencies, etc.
  • Snippet of the usage.
  • A reproducible example can really help.

The GitHub issues are intended for bug reports and feature requests. For help and questions about Epsagon, use the help widget inside the product.

License

Provided under the MIT license. See LICENSE for details.

Copyright 2020, Epsagon

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].