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:
parent
9407bf396e
commit
4ec3a3476f
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user