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)
}
Environment variable | Default value | Purpose |
---|---|---|
SPLUNK_TRACE_RESPONSE_HEADER_ENABLED |
true |
Adds Server-Timing header to HTTP responses. More |
NewHandler
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.