Created
June 7, 2022 15:06
-
-
Save MadVikingGod/bb94159fcda5844c99d447cf1339d36f to your computer and use it in GitHub Desktop.
example of #2946
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 ( | |
"context" | |
"fmt" | |
"go.opentelemetry.io/otel" | |
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace" | |
"go.opentelemetry.io/otel/sdk/trace" | |
"golang.org/x/sync/errgroup" | |
) | |
func main() { | |
exp, _ := stdouttrace.New() | |
tp := trace.NewTracerProvider( | |
trace.WithSpanProcessor(trace.NewSimpleSpanProcessor(exp)), | |
) | |
otel.SetTracerProvider(tp) | |
ctx, cancel := context.WithCancel(context.Background()) | |
ctx, span := otel.Tracer("app").Start(ctx, "parent") | |
defer span.End() | |
eg, ctx := errgroup.WithContext(ctx) | |
subspans := make([]struct{}, 100) | |
for j := range subspans { | |
idx := j | |
eg.Go(func() error { | |
_, subSpan := otel.Tracer("app").Start(ctx, fmt.Sprintf("subtree_%d", idx)) | |
defer subSpan.End() | |
// fmt.Printf("subtree_%d\n", idx) | |
cancel() | |
return fmt.Errorf("stuff") | |
}) | |
} | |
eg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment