Last active
May 10, 2022 13:53
-
-
Save kuenishi/69235390f64a31e38bf0c0a3bd3e8a48 to your computer and use it in GitHub Desktop.
Bad example patch against https://github.com/open-telemetry/opentelemetry-go-contrib/tree/6feda8333ee4608534f51a0bcd3e2fe8b60ab900
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
diff --git a/instrumentation/net/http/otelhttp/example/server/server.go b/instrumentation/net/http/otelhttp/example/server/server.go | |
index 7389c267..f128042b 100644 | |
--- a/instrumentation/net/http/otelhttp/example/server/server.go | |
+++ b/instrumentation/net/http/otelhttp/example/server/server.go | |
@@ -19,6 +19,7 @@ import ( | |
"io" | |
"log" | |
"net/http" | |
+ "sync" | |
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" | |
@@ -53,7 +54,7 @@ func initTracer() *sdktrace.TracerProvider { | |
return tp | |
} | |
-func main() { | |
+func start() *sync.WaitGroup { | |
tp := initTracer() | |
defer func() { | |
if err := tp.Shutdown(context.Background()); err != nil { | |
@@ -75,8 +76,21 @@ func main() { | |
otelHandler := otelhttp.NewHandler(http.HandlerFunc(helloHandler), "Hello") | |
http.Handle("/hello", otelHandler) | |
- err := http.ListenAndServe(":7777", nil) | |
- if err != nil { | |
- panic(err) | |
- } | |
+ wg := &sync.WaitGroup{} | |
+ wg.Add(1) | |
+ | |
+ go func() { | |
+ defer wg.Done() | |
+ err := http.ListenAndServe(":7777", nil) | |
+ if err != nil { | |
+ panic(err) | |
+ } | |
+ }() | |
+ | |
+ return wg | |
+} | |
+ | |
+func main() { | |
+ wg := start() | |
+ wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment