Created
May 29, 2023 12:45
-
-
Save Alkorin/ba749e56911d887d1acbf1de23604095 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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