Documentation ¶
Index ¶
- Constants
- func CaptureError() gin.HandlerFunc
- func ContextFrom(c *gin.Context) context.Context
- func SpanFromContext(c *gin.Context) trace.Span
- func StartSpan(c *gin.Context, op string, opts ...trace.SpanStartOption) (ctx context.Context, sp trace.Span)
- func Tracing(config *Config) gin.HandlerFunc
- type CarrierFactory
- type Config
Examples ¶
Constants ¶
const (
OtelTraceContextKey = "opentelemetry.gin"
)
Variables ¶
This section is empty.
Functions ¶
func CaptureError ¶
func CaptureError() gin.HandlerFunc
CaptureError captures error and panic to open-telemetry.
Example ¶
package main import ( "github.com/gin-gonic/gin" otelgin "github.com/yeqown/opentelemetry-quake/x/gin" ) func main() { r := gin.Default() r.Use( otelgin.CaptureError(), ) }
Output:
func SpanFromContext ¶
SpanFromContext get the raw span from gin.Context.
func StartSpan ¶
func StartSpan(c *gin.Context, op string, opts ...trace.SpanStartOption) (ctx context.Context, sp trace.Span)
StartSpan is a wrapper of opentelemetry.StartSpan, but it extracts span from gin.Context rather than context.Context. The return span is that derived by root span which is created by Tracing middleware.
func Tracing ¶
func Tracing(config *Config) 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" sentryexporter "github.com/yeqown/opentelemetry-quake/sentryexporter" otelgin "github.com/yeqown/opentelemetry-quake/x/gin" ) func main() { r := gin.Default() r.Use( otelgin.Tracing(otelgin.DefaultConfig()), ) // sentry trace header r.Use( otelgin.Tracing(&otelgin.Config{ Factory: sentryexporter.CarrierFactory, LogRequest: true, LogResponse: true, }), ) }
Output:
Types ¶
type CarrierFactory ¶
type CarrierFactory func(h http.Header) propagation.TextMapCarrier
CarrierFactory is a factory function to tell Tracing middleware how to fill the TraceContext from carrier. Checkout pkg/exporter/sentry/adaptor.go#CarrierFactory for detail.
type Config ¶
type Config struct { Factory CarrierFactory LogRequest, LogResponse bool }
Config helps user to control Tracing middleware about how to handle the request and response. Such as: - log the request and response body or not, - how to extract TraceContext from request.
func DefaultConfig ¶
func DefaultConfig() *Config
func (*Config) ApplyCarrierFactory ¶
func (c *Config) ApplyCarrierFactory(factory CarrierFactory) *Config