-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathexample_test.go
38 lines (31 loc) · 983 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// (c) Copyright IBM Corp. 2021
// (c) Copyright Instana Inc. 2020
package pubsub_test
import (
"encoding/json"
"fmt"
"net/http"
instana "github.com/instana/go-sensor"
"github.com/instana/go-sensor/instrumentation/cloud.google.com/go/pubsub"
)
// This example show how to instrument and HTTP handler that receives Google Cloud Pub/Sub messages
// via the push delivery method.
func ExampleTracingHandlerFunc() {
// Initialize collector
c := instana.InitCollector(&instana.Options{
Service: "pubsub-consumer",
})
defer instana.ShutdownCollector()
// Wrap your Pub/Sub message handler with pubsub.TracingHandlerFunc
http.Handle("/", pubsub.TracingHandlerFunc(c, "/", func(w http.ResponseWriter, req *http.Request) {
var delivery struct {
Message struct {
Data []byte `json:"data"`
} `son:"message"`
}
if err := json.NewDecoder(req.Body).Decode(&delivery); err != nil {
// handle the error
}
fmt.Printf("got %q", delivery.Message.Data)
}))
}