A set of instrumentation features for collecting relevant tracing data as well as secure an application

Related tags

Utilities goagent
Overview

Go Agent

goagent provides a set of instrumentation features for collecting relevant tracing data as well as secure an application by blocking requests selectively using Traceable features.

Getting started

Setting up Go Agent can be done with a few lines:

import (
    "github.com/Traceableai/goagent"
    "github.com/Traceableai/goagent/config"
)

//...

func main() {
    cfg := config.Load()
    cfg.Tracing.ServiceName = config.String("myservice")

    shutdown := goagent.Init(cfg)
    defer shutdown()
}

Config values can be declared in config file, env variables or code. For further information about config check this section.

Traceable filter

By default, goagent includes the Traceable filter into server instrumentation (e.g. HTTP server or GRPC server) based on the configuration features. To run Traceable filter we need to:

Fist compile the binary using the build tag traceable_filter, for example:

go build -tags 'traceable_filter' -o myapp

Then, we need to download the library next to the application binary:

# Install libtraceable downloader (run this from a non go.mod folder)
go install github.com/Traceableai/goagent/filter/traceable/cmd/libtraceable-downloader@latest

...

# Pull library in the binary directory
cd /path/to/myapp &&
libtraceable-downloader pull-library

Package net/traceablehttp

HTTP server

The server instrumentation relies on the http.Handler component of the server declarations.

import (
    "net/http"

    "github.com/gorilla/mux"
    "github.com/Traceableai/goagent/instrumentation/net/traceablehttp"
)

func main() {
    // ...

    r := mux.NewRouter()
    r.Handle("/foo/{bar}", traceablehttp.NewHandler(
        fooHandler, // existing user handler
        "/foo/{bar}", // name of the span generated for this handler
    ))

    // ...
}

Options

Filter

Filters allow users to filter requests based on URL, headers or body. Filters can be added in the handler declaration using the traceablehttp.WithFilter option. Multiple filters can be added too by using filter.NewMultiFilter and they will be run in sequence until a filter returns true (request is blocked), or all filters are run.

import "github.com/hypertrace/goagent/sdk/filter"

// ...

    r.Handle("/foo/{bar}", traceablehttp.NewHandler(
        fooHandler,
        "/foo/{bar}",
        traceablehttp.WithFilter(filter.NewMultiFilter(filter1, filter2)),
    ))

// ...

HTTP client

The client instrumentation relies on the http.Transport component of the HTTP client in Go.

import (
    "net/http"
    "github.com/Traceableai/goagent/instrumentation/net/traceablehttp"
)

// ...

client := http.Client{
    Transport: traceablehttp.NewTransport(
        http.DefaultTransport,
    ),
}

req, _ := http.NewRequest("GET", "http://example.com", nil)

res, err := client.Do(req)

// ...

Running HTTP examples

In terminal 1 run the client:

go run ./_examples/http-client/main.go

In terminal 2 run the server:

go run ./_examples/http-server/main.go

Gin-Gonic Server

Gin server instrumentation relies on adding the traceablegin.Middleware middleware to the gin server.

r := gin.Default()

cfg := config.Load()
cfg.ServiceName = config.String("http-gin-server")

flusher := goagent.Init(cfg)
defer flusher()

r.Use(traceablegin.Middleware())

To run an example gin server with the middleware:

go run ./_examples/gin-server/main.go

Then make a request to localhost:8080/ping

Package google.golang.org/traceablegrpc

GRPC server

The server instrumentation relies on the grpc.UnaryServerInterceptor component of the server declarations.

server := grpc.NewServer(
    grpc.UnaryInterceptor(
        traceablegrpc.UnaryServerInterceptor(),
    ),
)

Options

Filter

Filters allow users to filter requests based on URL, headers or body. Filters can be added in the server interceptor declaration using the traceablegrpc.WithFilter option. Multiple filters can be added too by using filter.NewMultiFilter and they will be run in sequence until a filter returns true (request is blocked), or all filters are run.

import "github.com/hypertrace/goagent/sdk/filter"

// ...

    grpc.UnaryInterceptor(
        traceablegrpc.UnaryServerInterceptor(
            traceablegrpc.WithFilter(filter.NewMultiFilter(filter1, filter2))
        ),
    ),

GRPC client

The client instrumentation relies on the http.Transport component of the HTTP client in Go.

import (
    // ...

    traceablegrpc "github.com/Traceableai/goagent/instrumentation/google.golang.org/traceablegrpc"
    "google.golang.org/grpc"
)

func main() {
    // ...
    conn, err := grpc.Dial(
        address,
        grpc.WithInsecure(),
        grpc.WithBlock(),
        grpc.WithUnaryInterceptor(
            traceablegrpc.UnaryClientInterceptor(),
        ),
    )
    if err != nil {
        log.Fatalf("could not dial: %v", err)
    }
    defer conn.Close()

    client := pb.NewCustomClient(conn)

    // ...
}

Running GRPC examples

In terminal 1 run the client:

go run ./_examples/grpc-client/main.go

In terminal 2 run the server:

go run ./_examples/grpc-server/main.go

Other instrumentations

You might also like...
 A rule-based tunnel in Go with experimental features.
A rule-based tunnel in Go with experimental features.

This repository is for archiving only Experimental-Clash A rule-based tunnel in Go with experimental features. Features Local HTTP/HTTPS/SOCKS server

A library that provides Go Generics friendly "optional" features.

go-optional A library that provides Go Generics friendly "optional" features. Synopsis some := optional.Some[int](123) fmt.Printf("%v\n", some.IsSome(

Like tools/cmd/stringer with bitmask features

Bitmasker Bitmasker is a tool used to automate the creation of helper methods when dealing with bitmask-type constant flags. Given the name of an unsi

CSPFinder is a tool to compare ROI of selling Cash Secure Put options between different tickers for different expiry dates.

CSPFinder is a tool to compare ROI of selling Cash Secure Put options between different tickers for different expiry dates. It is intended to help open new cash secured put positions.

ms - 'my story' creates a secure password string which can be memorized with a technique shared by Max.

On 23.12.21 20:22, Stefan Claas wrote: [...] Yes, I am aware of that, but how can one memorize a key when traveling and not taking any devices

Print random bytes from a secure source to stdout.

Print random bytes from a secure source to stdout.

Automatically set GOMAXPROCS to match Linux container CPU quota.

automaxprocs Automatically set GOMAXPROCS to match Linux container CPU quota. Installation go get -u go.uber.org/automaxprocs Quick Start import _ "go

redis-util business-friendly encapsulation of redis operations, such as the common cache set get operation

redis-util 方便业务使用的redis操作封装,比如常见的缓存set get操作, 一行代码搞定,不像开源库需要写好多行 使用方法

Simple utility to get/set the PWM duty cycle and to measure the RPM for a fan connected to the 4-pin header on the CM4IO.

cm4iofan Simple utility to get/set the PWM duty cycle and to measure the RPM for a fan connected to the 4-pin header on the CM4IO. Requirements Enable

Releases(v0.3.1)
  • v0.3.1(Mar 10, 2022)

  • v0.3.0(Dec 21, 2021)

  • v0.2.0(Dec 14, 2021)

    What's Changed

    • feat: adds support for body_max_processing_size by @jcchavezs

    Full Changelog: https://github.com/Traceableai/goagent/compare/v0.1.5...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.5(Dec 5, 2021)

    What's Changed

    • feat: adds InitAsAdditional feature to allows interop with other otel tracers

    Full Changelog: https://github.com/Traceableai/goagent/compare/v0.1.4...v0.1.5

    Source code(tar.gz)
    Source code(zip)
  • v0.1.4(Dec 3, 2021)

    What's Changed

    • fix: adds dummy packages so that libtraceable.so files get pulled whenever we run go mod vendor.
    • feat: adds gin instrumentation.
    • fix: upgrades libtraceable to 0.1.98-rc.31.

    Full Changelog: https://github.com/Traceableai/goagent/compare/v0.1.3...v0.1.4

    Source code(tar.gz)
    Source code(zip)
  • v0.1.3(Nov 30, 2021)

    feat: adds support for enabling disabling tracing in the agent. fix: upgrades libtraceable to fix region blocking

    Full Changelog: https://github.com/Traceableai/goagent/compare/v0.1.2...v0.1.3

    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Nov 19, 2021)

Owner
null
An application written in Go to generate fractals like the Mandelbrot set and the Julia set.

Fractals An application written in Go to generate fractals like the Mandelbrot set and the Julia set. Screenshots Mandelbrot set Julia set Prerequisit

null 0 May 9, 2022
go-sysinfo is a library for collecting system information.

go-sysinfo go-sysinfo is a library for collecting system information. This includes information about the host machine and processes running on the ho

elastic 220 Dec 26, 2022
Tiny Go tool for running multiple functions concurrently and collecting their results into an error slice.

Overview Short for "ConCurrent". Tiny Go tool for running multiple functions concurrently and collecting their results into an error slice. Dependency

Nelo Mitranim 0 Nov 22, 2021
libraries for various programming languages that make it easy to generate per-process trace files that can be loaded into chrome://tracing

chrometracing: chrome://tracing trace_event files The chrometracing directory contains libraries for various programming languages that make it easy t

Google 23 Oct 6, 2022
A well tested and comprehensive Golang statistics library package with no dependencies.

Stats - Golang Statistics Package A well tested and comprehensive Golang statistics library / package / module with no dependencies. If you have any s

Montana Flynn 2.6k Dec 30, 2022
sigbypass4xx is a utility to automate well-know techniques used to bypass access control restrictions.

sigbypass4xx sigbypass4xx is a utility to automate well-know techniques used to bypass access control restrictions. Resources Usage Installation From

Signed Security 8 Nov 9, 2022
An API that provides a small but well-thought service converting Euro to US Dollar and vice-versa

Currency Converter ###Problem An API that provides a small but well-thought service converting Euro to US Dollar and vice-versa. That API should only

Akshay Nambiar 0 Jan 30, 2022
This project contains an example that showcases different features from the official Go Client for Elasticsearch

Elasticsearch for Gophers This project contains an example that showcases different features from the official Go Client for Elasticsearch that you ca

Ricardo Ferreira 19 Oct 12, 2022
Yet another StructTag, with some features liked cache and alias.

Yet another StructTag, with some features liked cache and alias.

Ryan Liu 2 Nov 1, 2021
xgen generator with extend features

XGen Plus Generator Introduction xgen is a library written in pure Go providing a set of functions that allow you to parse XSD (XML schema definition)

ZaharovII 0 Dec 8, 2021