muxtrace

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package muxtrace provides tracing functions for the Gorilla Mux framework.

Example
package main

import (
	"fmt"
	"net/http"

	"github.com/DataDog/dd-trace-go/tracer"
	"github.com/DataDog/dd-trace-go/tracer/contrib/gorilla/muxtrace"
	"github.com/gorilla/mux"
)

// handler is a simple handlerFunc that logs some data from the span
// that is injected into the requests' context.
func handler(w http.ResponseWriter, r *http.Request) {
	span := tracer.SpanFromContextDefault(r.Context())
	fmt.Printf("tracing service:%s resource:%s", span.Service, span.Resource)
	w.Write([]byte("hello world"))
}

func main() {
	router := mux.NewRouter()
	muxTracer := muxtrace.NewMuxTracer("my-web-app", tracer.DefaultTracer)

	// Add traced routes directly.
	muxTracer.HandleFunc(router, "/users", handler)

	// and subroutes as well.
	subrouter := router.PathPrefix("/user").Subrouter()
	muxTracer.HandleFunc(subrouter, "/view", handler)
	muxTracer.HandleFunc(subrouter, "/create", handler)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestSpan

func GetRequestSpan(r *http.Request) (*tracer.Span, bool)

GetRequestSpan will return the span associated with the given request. It will return nil/false if it doesn't exist.

func SetRequestSpan

func SetRequestSpan(r *http.Request, span *tracer.Span) *http.Request

SetRequestSpan sets the span on the request's context.

Types

type MuxTracer

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

MuxTracer is used to trace requests in a mux server.

func NewMuxTracer

func NewMuxTracer(service string, t *tracer.Tracer) *MuxTracer

NewMuxTracer creates a MuxTracer for the given service and tracer.

func (*MuxTracer) HandleFunc

func (m *MuxTracer) HandleFunc(router *mux.Router, pattern string, handler http.HandlerFunc) *mux.Route

HandleFunc will add a traced version of the given handler to the router.

func (*MuxTracer) TraceHandleFunc

func (m *MuxTracer) TraceHandleFunc(handler http.HandlerFunc) http.HandlerFunc

TraceHandleFunc will return a HandlerFunc that will wrap tracing around the given handler func.

Jump to

Keyboard shortcuts

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