opentelemetry

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 5 Imported by: 3

README

go-opentelemetry GoDoc License

A library to install the opentelemetry exporters rapidly.

Example

module myapp

require (
	github.com/prometheus/client_golang v1.12.2
	github.com/xgfone/go-opentelemetry v0.3.1
	github.com/xgfone/go-opentelemetry/jaegerexporter v0.3.0
	github.com/xgfone/go-opentelemetry/otelhttpx v0.3.1
	github.com/xgfone/go-opentelemetry/promexporter v0.3.0
)

go 1.17
package main

import (
	"net/http"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/xgfone/go-opentelemetry"
	"github.com/xgfone/go-opentelemetry/jaegerexporter"
	"github.com/xgfone/go-opentelemetry/otelhttpx"
	"github.com/xgfone/go-opentelemetry/promexporter"
)

func init() {
	registry := prometheus.NewRegistry()
	http.Handle("/metrics", promexporter.Handler(registry))

	opentelemetry.SetServiceName("ServiceName")
	jaegerexporter.Install(nil, nil)
	promexporter.Install(registry)
	otelhttpx.InstallClient()
}

func wrapHandler(handler http.HandlerFunc) http.Handler {
	return otelhttpx.Handler(handler, "Operation")
}

func main() {
	http.Handle("/path", wrapHandler(func(w http.ResponseWriter, r *http.Request) {
		// TODO
	}))

	http.ListenAndServe(":80", nil)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultResource *resource.Resource

DefaultResource is the default resource used by metric and tracer.

Functions

func SetServiceName

func SetServiceName(serviceName string)

SetServiceName sets the service name in the resource.

func Shutdown added in v0.2.0

func Shutdown(ctx context.Context) (err error)

Shutdown shuts down the tracer provider.

func Stop added in v0.2.0

func Stop()

Stop is equal to Shutdown(context.Background()).

Types

This section is empty.

Directories

Path Synopsis
otelhttpx module
otelsqlx module
promexporter module

Jump to

Keyboard shortcuts

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