Skip to content

Instantly share code, notes, and snippets.

@kuenishi
Last active May 10, 2022 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuenishi/69235390f64a31e38bf0c0a3bd3e8a48 to your computer and use it in GitHub Desktop.
Save kuenishi/69235390f64a31e38bf0c0a3bd3e8a48 to your computer and use it in GitHub Desktop.
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