Socket
Book a DemoInstallSign in
Socket

github.com/vincentfree/opentelemetry-http/otelmiddleware

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/vincentfree/opentelemetry-http/otelmiddleware

Source
Go
Version
v0.1.0
Version published
Created
Source

OpenTelemetry extensions - otelmiddleware

HomeRelated
HomeNone

Go CodeQL Dependency Review Go Reference

Open Telemetry http middleware. This package provides an instrumentation for middleware that can be used to trace HTTP requests.

Package otelmiddleware provides middleware for wrapping http.Server handlers with Open Telemetry tracing support.

The trace.Span is decorated with standard metadata extracted from the http.Request injected into the middleware. the basic information is extracted using the OpenTelemetry semconv package.

When a span gets initialized it uses the following slice of trace.SpanStartOption

opts := []trace.SpanStartOption{
trace.WithAttributes(semconv.NetAttributesFromHTTPRequest("tcp", r)...),
trace.WithAttributes(semconv.EndUserAttributesFromHTTPRequest(r)...),
trace.WithAttributes(semconv.HTTPServerAttributesFromHTTPRequest(r.Host, extractRoute(r.RequestURI), r)...),
trace.WithAttributes(semconv.HTTPClientAttributesFromHTTPRequest(r)...),
trace.WithAttributes(semconv.TelemetrySDKLanguageGo),
trace.WithSpanKind(trace.SpanKindServer),
}

The slice can be extended using the WithAttributes TraceOption function.

After these options are applied a new span is created and the middleware will pass the http.ResponseWriter and http.Request to the next http.Handler.

Functions

func TraceWithOptions(opt ...TraceOption) func (next http.Handler) http.Handler
func Trace(next http.Handler) http.Handler
func WithAttributes(attributes ...attribute.KeyValue) TraceOption
func WithPropagator(p propagation.TextMapPropagator) TraceOption
func WithServiceName(serviceName string) TraceOption
func WithTracer(tracer trace.Tracer) TraceOption

Types

type TraceOption func (*traceConfig)

Structs

type traceConfig struct {
tracer trace.Tracer
propagator propagation.TextMapPropagator
attributes []attribute.KeyValue
serviceName string
}

FAQs

Package last updated on 19 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts