Documentation ¶
Overview ¶
Package splunkhttp provides functions that add additional Splunk specific instrumentation by wrapping existing handlers.
Example ¶
package main import ( "fmt" "io" "net/http" "net/http/httptest" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "go.opentelemetry.io/otel/sdk/trace" "github.com/signalfx/splunk-otel-go/instrumentation/net/http/splunkhttp" ) func main() { var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello world") //nolint:errcheck }) handler = splunkhttp.NewHandler(handler) handler = otelhttp.NewHandler(handler, "server", otelhttp.WithTracerProvider(trace.NewTracerProvider())) ts := httptest.NewServer(handler) defer ts.Close() resp, _ := ts.Client().Get(ts.URL) //nolint fmt.Println("Access-Control-Expose-Headers:", resp.Header.Get("Access-Control-Expose-Headers")) fmt.Println("Server-Timing:", resp.Header.Get("Server-Timing")) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
NewHandler wraps the passed handler in a span named after the operation and with any provided Options. This will also enable all the Splunk specific defaults for HTTP tracing.
func TraceResponseHeaderMiddleware ¶
TraceResponseHeaderMiddleware wraps the passed handler, functioning like middleware. It adds trace context in traceparent form (https://www.w3.org/TR/trace-context/#traceparent-header) as Server-Timing header (https://www.w3.org/TR/server-timing/) to the HTTP response.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used for setting optional config properties.
func WithTraceResponseHeader ¶
WithTraceResponseHeader enables or disables the TraceResponseHeaderMiddleware.
The default is to enable the TraceResponseHeaderMiddleware if this option is not passed. Additionally, the SPLUNK_TRACE_RESPONSE_HEADER_ENABLED environment variable can be set to TRUE or FALSE to specify this option. This option value will be given precedence if both it and the environment variable are set.