Skip to content

Latest commit

 

History

History

splunkhttp

Splunk specific instrumentation for net/http

Example

Simplified example:

package main

import (
	"net/http"

	"github.com/signalfx/splunk-otel-go/distro"
	"github.com/signalfx/splunk-otel-go/instrumentation/net/http/splunkhttp"
	"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

func main() {
	distro.Run()

	var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello"))
	})
	handler = splunkhttp.NewHandler(handler)
	handler = otelhttp.NewHandler(handler, "my-service")

	http.ListenAndServe(":9090", handler)
}

Configuration

Splunk distribution configuration

Code Environment variable Default value Purpose
WithTraceResponseHeader, TraceResponseHeaderMiddleware SPLUNK_TRACE_RESPONSE_HEADER_ENABLED true Adds Server-Timing header to HTTP responses. More

Features

Trace linkage between the APM and RUM products

TraceResponseHeaderMiddleware wraps the passed handler, functioning like middleware. It adds trace context in traceparent form as Server-Timing header to the HTTP response:

Access-Control-Expose-Headers: Server-Timing
Server-Timing: traceparent;desc="00-<serverTraceId>-<serverSpanId>-01"

This information can be later consumed by the splunk-otel-js-web library.