Skip to content

anthonyhartanto/muxtrace

Repository files navigation

muxtrace Go Report Card GoDoc

Gorilla Logo

What is opentracing ? Vendor neutral APIs and instrumentation for distributed tracing.

Why you need muxtrace ? For example you are using Datadog Tracer to monitor your application performance on http request. We rely on both Datadog and Mux router. Unfortunately, the datadog package for tracing http request on mux was not compatible with opentracing.



Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Things you need to use the package

  • Gorilla Mux - Router and dispatcher
  • Opentracing - Vendor-neutral APIs and instrumentation for distributed tracing

Installing

With go:

$ go get -u github.com/anthonyhartanto/muxtrace

Example

package main

import (
	"fmt"
	"github.com/anthonyhartanto/dd-trace-go/ddtrace/opentracer"
	"github.com/anthonyhartanto/dd-trace-go/ddtrace/tracer"
	"github.com/opentracing/opentracing-go"
	"github.com/anthonyhartanto/muxtrace"
	"net/http"
)

// ExampleHandler handle example
func ExampleHandler(rw http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(rw, "OK")
}

func main() {
	// Set tracer
	t := opentracer.New(tracer.WithServiceName("example-service"))
	defer tracer.Stop()
	opentracing.SetGlobalTracer(t)

	// Set router
	router := muxtrace.NewRouter()
	router.HandleFunc("/example", ExampleHandler).Methods(http.MethodGet)

	// Run server
	server := &http.Server{
		Addr:    ":8080",
		Handler: router,
	}
	server.ListenAndServe()
}

Result on Datadog:

Datadog Result

Built With

  • Go - The language used

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

About

A mux wrapper with opentracer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages