github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/example_collector_test.go (about) 1 // (c) Copyright IBM Corp. 2023 2 3 package instana_test 4 5 import ( 6 "fmt" 7 "net/http" 8 "time" 9 10 instana "github.com/instana/go-sensor" 11 ) 12 13 func Example_collectorBasicUsage() { 14 // Initialize the collector 15 c := instana.InitCollector(&instana.Options{ 16 // If Service is not provided, the executable filename will be used instead. 17 // We recommend that Service be set. 18 Service: "my-go-app", 19 }) 20 21 // Instrument something 22 sp := c.StartSpan("my_span") 23 24 time.Sleep(time.Second * 3) 25 26 sp.Finish() 27 } 28 29 func Example_collectorWithHTTPServer() { 30 c := instana.InitCollector(&instana.Options{ 31 Service: "my-go-app", 32 }) 33 34 handler := func(w http.ResponseWriter, r *http.Request) { 35 fmt.Fprint(w, "Ok") 36 } 37 38 http.HandleFunc("/foo", instana.TracingHandlerFunc(c.LegacySensor(), "/foo", handler)) 39 }