Skip to content

Instantly share code, notes, and snippets.

@Alkorin
Created May 29, 2023 12:45
Show Gist options
  • Save Alkorin/ba749e56911d887d1acbf1de23604095 to your computer and use it in GitHub Desktop.
Save Alkorin/ba749e56911d887d1acbf1de23604095 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"context"
"fmt"
"io"
"log"
"net/http"
"net/http/httptest"
"net/http/httptrace"
"go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace"
)
func main() {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, client")
}))
defer ts.Close()
clientTrace := otelhttptrace.NewClientTrace(context.Background())
ctx := httptrace.WithClientTrace(context.Background(), clientTrace)
req, _ := http.NewRequestWithContext(ctx, "POST", ts.URL, bytes.NewReader([]byte("test")))
req.Header.Set("Expect", "100-continue")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
io.Copy(io.Discard, res.Body)
res.Body.Close()
log.Printf("%v", res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment