Skip to content

Commit

Permalink
Fix getting-started.md Run function (#2527)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thinkgos committed Jan 22, 2022
1 parent 9407bf3 commit 4ec3a34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions example/fib/app.go
Expand Up @@ -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()
}
}
Expand Down
8 changes: 4 additions & 4 deletions website_docs/getting-started.md
Expand Up @@ -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()
}
}
Expand Down

0 comments on commit 4ec3a34

Please sign in to comment.