ipld-eth-server/vendor/gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer/example_test.go

35 lines
840 B
Go
Raw Normal View History

2018-09-04 16:35:38 +00:00
package tracer
import (
"io/ioutil"
"log"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
)
// A basic example demonstrating how to start the tracer, as well as how
// to create a root span and a child span that is a descendant of it.
func Example() {
// Start the tracer and defer the Stop method.
Start(WithAgentAddr("host:port"))
defer Stop()
// Start a root span.
span := StartSpan("get.data")
defer span.Finish()
// Create a child of it, computing the time needed to read a file.
child := StartSpan("read.file", ChildOf(span.Context()))
child.SetTag(ext.ResourceName, "test.json")
// Perform an operation.
_, err := ioutil.ReadFile("~/test.json")
// We may finish the child span using the returned error. If it's
// nil, it will be disregarded.
child.Finish(WithError(err))
if err != nil {
log.Fatal(err)
}
}