tracinggin

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	OtelTraceContextKey = "opentelemetry.gin"
)

Variables

This section is empty.

Functions

func CaptureException

func CaptureException(repanic bool) gin.HandlerFunc

CaptureException captures error and panic to open-telemetry.

Example
package main

import (
	"github.com/gin-gonic/gin"

	tracinggin2 "github.com/yeqown/opentelemetry-quake/contrib/gin"
)

func main() {
	r := gin.Default()

	r.Use(
		tracinggin2.CaptureException(false),
	)
}
Output:

func SentryCarrierAdaptor

func SentryCarrierAdaptor(h http.Header) tracing.TraceContextCarrier

SentryCarrierAdaptor is an adapter that let sentry trace is valid for open-telemetry.

func Tracing

func Tracing(opts ...TracingOption) gin.HandlerFunc

Tracing creates a new otel.Tracer if never created and returns a gin.HandlerFunc. You only need to specify a CarrierFactory if your frontend doesn't obey TraceContext specification https://www.w3.org/TR/trace-context, otherwise you can leave it nil.

Example
package main

import (
	"github.com/gin-gonic/gin"

	tracinggin2 "github.com/yeqown/opentelemetry-quake/contrib/gin"
)

func main() {
	r := gin.Default()

	r.Use(
		tracinggin2.Tracing(),
	)

	// sentry trace header
	r.Use(tracinggin2.Tracing(
		tracinggin2.WithCarrierFactory(tracinggin2.SentryCarrierAdaptor),
		tracinggin2.WithRecordPayloads(),
	))
}
Output:

func TracingContextFrom

func TracingContextFrom(c *gin.Context) context.Context

TracingContextFrom read trace context from gin context. it never returns nil.

Types

type TracingOption

type TracingOption interface {
	// contains filtered or unexported methods
}

func WithCarrierFactory

func WithCarrierFactory(adaptor func(h http.Header) tracing.TraceContextCarrier) TracingOption

func WithRecordPayloads

func WithRecordPayloads() TracingOption

Jump to

Keyboard shortcuts

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