Coder Social home page Coder Social logo

goagent's Introduction

Go Agent

test codecov

goagent provides a set of complementary instrumentation features for collecting relevant data to be processed by Hypertrace.

Getting started

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

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

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

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

Package net/hyperhttp

HTTP server

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

import (
    "net/http"

    "github.com/gorilla/mux"
    "github.com/hypertrace/goagent/instrumentation/hypertrace/net/hyperhttp"
)

func main() {
    // ...

    r := mux.NewRouter()
    r.Handle("/foo/{bar}", hyperhttp.NewHandler(
        fooHandler,
        "/foo/{bar}",
    ))

    // ...
}

HTTP client

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

import (
    "net/http"
    "github.com/hypertrace/goagent/instrumentation/hypertrace/net/hyperhttp"
)

// ...

client := http.Client{
    Transport: hyperhttp.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 ./instrumentation/hypertrace/net/hyperhttp/examples/client/main.go

In terminal 2 run the server:

go run ./instrumentation/hypertrace/net/hyperhttp/examples/server/main.go

Package google.golang.org/hypergrpc

GRPC server

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

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

GRPC client

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

import (
    // ...

    hypergrpc "github.com/hypertrace/goagent/instrumentation/hypertrace/google.golang.org/hypergrpc"
    "google.golang.org/grpc"
)

func main() {
    // ...
    conn, err := grpc.Dial(
        address,
        grpc.WithInsecure(),
        grpc.WithBlock(),
        grpc.WithUnaryInterceptor(
            hypergrpc.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 ./instrumentation/hypertrace/google.golang.org/grpc/examples/client/main.go

In terminal 2 run the server:

go run ./instrumentation/hypertrace/google.golang.org/grpc/examples/server/main.go

Other instrumentations

Contributing

Running tests

Tests can be run with (requires docker)

make test

for unit tests only

make test-unit

Releasing

Run ./release.sh <version_number> (<version_number> should follow semver, e.g. 1.2.3). The script will change the hardcoded version, commit it, push a tag and prepare the hardcoded version for the next release.

goagent's People

Contributors

davexroth avatar jbahire avatar jcchavezs avatar mohit-a21 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.