1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-05 22:54:18 +02:00

Fix getting-started.md Run function (#2527)

* Fix getting-started.md Run function, it assigns this new context to a variable shared between connections in to accept loop. Thus creating a growing chain of contexts. so every calculate fibonacci request, all spans in a trace.

* add a comment explaining the reason for that new variable

* update example fib
This commit is contained in:
thinkgo 2022-01-23 00:28:40 +08:00 committed by GitHub
parent 9407bf396e
commit 4ec3a3476f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -44,16 +44,16 @@ func NewApp(r io.Reader, l *log.Logger) *App {
// Run starts polling users for Fibonacci number requests and writes results.
func (a *App) Run(ctx context.Context) error {
for {
var span trace.Span
ctx, span = otel.Tracer(name).Start(ctx, "Run")
// Each execution of the run loop, we should get a new "root" span and context.
newCtx, span := otel.Tracer(name).Start(ctx, "Run")
n, err := a.Poll(ctx)
n, err := a.Poll(newCtx)
if err != nil {
span.End()
return err
}
a.Write(ctx, n)
a.Write(newCtx, n)
span.End()
}
}

View File

@ -184,16 +184,16 @@ Start by instrumenting the `Run` method.
// Run starts polling users for Fibonacci number requests and writes results.
func (a *App) Run(ctx context.Context) error {
for {
var span trace.Span
ctx, span = otel.Tracer(name).Start(ctx, "Run")
// Each execution of the run loop, we should get a new "root" span and context.
newCtx, span := otel.Tracer(name).Start(ctx, "Run")
n, err := a.Poll(ctx)
n, err := a.Poll(newCtx)
if err != nil {
span.End()
return err
}
a.Write(ctx, n)
a.Write(newCtx, n)
span.End()
}
}