event: suggestion: event.Start returns end

The majority of calls to start a trace span will be followed by a deferred call to end one:

    ctx = event.To(ctx).Start(name)
    defer event.To(ctx).End()

The main problem with this is that it is easy to forget that end must
be called. It's also more verbose than necessary.

Instead, have event.Start return both a context and a function that
can be deferred:

    ctx, end := event.To(ctx).Start(name)
    defer end()

The second return value will make it hard to forget the defer, and it
follows a common Go pattern.

You can also ignore it and call event.To(ctx).End() elsewhere if that
suits you.

Lastly, remove Builder.Start. It invites misuse by end users: they
should always do tracing with event.Start to properly construct the
span tree. (If you really want to do it, you can still call Deliver.)

Change-Id: Ibe7780ce5277e9d6dac5406e879a35d727a89eff
Reviewed-on: https://go-review.googlesource.com/c/exp/+/313409
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
4 files changed
tree: 2f182ae1fb323234184474b254467195bed938ef
  1. .gitattributes
  2. .gitignore
  3. AUTHORS
  4. CONTRIBUTING.md
  5. CONTRIBUTORS
  6. LICENSE
  7. PATENTS
  8. README.md
  9. apidiff/
  10. cmd/
  11. codereview.cfg
  12. ebnf/
  13. ebnflint/
  14. errors/
  15. event/
  16. fsnotify/
  17. go.mod
  18. go.sum
  19. inotify/
  20. io/
  21. mmap/
  22. rand/
  23. shiny/
  24. shootout/
  25. sumdb/
  26. utf8string/
  27. winfsnotify/
README.md

exp

PkgGoDev

This subrepository holds experimental and deprecated (in the old directory) packages.

The idea for this subrepository originated as the pkg/exp directory of the main repository, but its presence there made it unavailable to users of the binary downloads of the Go installation. The subrepository has therefore been created to make it possible to go get these packages.

Warning: Packages here are experimental and unreliable. Some may one day be promoted to the main repository or other subrepository, or they may be modified arbitrarily or even disappear altogether.

In short, code in this subrepository is not subject to the Go 1 compatibility promise. (No subrepo is, but the promise is even more likely to be violated by go.exp than the others.)

Caveat emptor.