Skip to content

Commit

Permalink
Update autosdk to wait for signal
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Oct 24, 2024
1 parent 84c4e2e commit 72e42aa
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions internal/test/e2e/autosdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"os"
"os/signal"
"syscall"
"time"

"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -76,8 +77,18 @@ func sig(ctx context.Context) <-chan msg {
}

func main() {
// give time for auto-instrumentation to start up
time.Sleep(5 * time.Second)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGCONT)

// Wait for auto-instrumentation.
select {
case <-ctx.Done():
os.Exit(1)
case <-sigChan:
}

provider := sdk.GetTracerProvider()
tracer := provider.Tracer(
Expand All @@ -87,9 +98,6 @@ func main() {
)
app := app{tracer: tracer}

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

ctx, span := tracer.Start(ctx, "main", trace.WithTimestamp(y2k))

err := app.Run(ctx, "Alice", true, sig(ctx))
Expand All @@ -104,7 +112,4 @@ func main() {
}

span.End(trace.WithTimestamp(y2k.Add(5 * time.Second)))

// give time for auto-instrumentation to report signal
time.Sleep(5 * time.Second)
}

0 comments on commit 72e42aa

Please sign in to comment.