
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
github.com/vincentfree/opentelemetry-http/otelmiddleware
Advanced tools
| Home | Related |
|---|---|
| Home | None |
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.
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
type TraceOption func (*traceConfig)
type traceConfig struct {
tracer trace.Tracer
propagator propagation.TextMapPropagator
attributes []attribute.KeyValue
serviceName string
}
FAQs
Unknown package
Did you know?

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.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.