1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-04 09:43:23 +02:00

Fixed OTLP example's accidental early close of exporter

* The exp.Stop() as argument to handleErr is getting executed
  immediately.  Wrap this with an anonymous func so that this
  argument is executed when the defer statement is activated.
* From the "Tour of Go" docs on Defer: "The deferred call's arguments
  are evaluated immediately, but the function call is not executed
  until the surrounding function returns."
This commit is contained in:
David C Wang 2020-06-09 13:08:10 -07:00
parent a98bb979df
commit ce49579d66

View File

@ -63,7 +63,7 @@ func initProvider() (*otlp.Exporter, *push.Controller) {
func main() {
exp, pusher := initProvider()
defer handleErr(exp.Stop(), "Failed to stop exporter")
defer func() { handleErr(exp.Stop(), "Failed to stop exporter") }()
defer pusher.Stop() // pushes any last exports to the receiver
tracer := global.Tracer("mage-sense")