instamux

package module
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 3 Imported by: 0

README

Instana instrumentation for gorilla mux

This module contains middleware to instrument HTTP services written with github.com/gorilla/mux.

PkgGoDev

Installation

To add the module to your go.mod file run the following command in your project directory:

$ go get github.com/instana/go-sensor/instrumentation/instamux

Usage

// Create a sensor
sensor := instana.NewSensor("my-web-server")

// Create router
r := mux.NewRouter()

// Instrument your router by adding a middleware
instamux.AddMiddleware(sensor, r)

// Define handlers
r.HandleFunc("/foo", func(writer http.ResponseWriter, request *http.Request) {})
...

Full example

Documentation

Overview

Example

This example shows how to instrument an HTTP server that uses github.com/gorilla/mux with Instana

package main

import (
	"log"
	"net/http"

	"github.com/gorilla/mux"
	instana "github.com/instana/go-sensor"
	"github.com/instana/go-sensor/instrumentation/instamux"
)

func main() {
	sensor := instana.NewSensor("my-web-server")
	r := mux.NewRouter()

	// Add an instrumentation middleware to the router. This middleware will be applied to all handlers
	// registered with this instance.
	instamux.AddMiddleware(sensor, r)

	// Use mux.Router to register request handlers as usual
	r.HandleFunc("/foo", func(w http.ResponseWriter, req *http.Request) {
		// ...
	})

	if err := http.ListenAndServe(":0", nil); err != nil {
		log.Fatalf("failed to start server: %s", err)
	}
}
Output:

Index

Examples

Constants

View Source
const Version = "1.16.0"

Version is the instrumentation module semantic version

Variables

This section is empty.

Functions

func AddMiddleware

func AddMiddleware(sensor instana.TracerLogger, router *mux.Router)

AddMiddleware instruments the mux.Router instance with Instana

func NewRouter added in v1.2.0

func NewRouter(sensor instana.TracerLogger) *mux.Router

NewRouter is wrapper for mux.NewRouter()

Types

This section is empty.

Jump to

Keyboard shortcuts

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