Documentation ¶
Overview ¶
Package pubsub provides Instana tracing instrumentation for Google Cloud Pub/Sub producers and consumers that use cloud.google.com/go/pubsub.
Index ¶
- func TracingHandlerFunc(sensor instana.TracerLogger, pathTemplate string, handler http.HandlerFunc) http.HandlerFunc
- type Client
- func (c *Client) CreateSubscription(ctx context.Context, id string, cfg pubsub.SubscriptionConfig) (*Subscription, error)
- func (c *Client) CreateTopic(ctx context.Context, id string) (*Topic, error)
- func (c *Client) CreateTopicWithConfig(ctx context.Context, topicID string, tc *pubsub.TopicConfig) (*Topic, error)
- func (c *Client) Subscription(id string) *Subscription
- func (c *Client) SubscriptionInProject(id, projectID string) *Subscription
- func (c *Client) Subscriptions(ctx context.Context) *SubscriptionIterator
- func (c *Client) Topic(id string) *Topic
- func (c *Client) TopicInProject(id, projectID string) *Topic
- func (c *Client) Topics(ctx context.Context) *TopicIterator
- type Message
- type PublishResult
- type Snapshot
- type Subscription
- type SubscriptionIterator
- type Topic
- type TopicIterator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TracingHandlerFunc ¶
func TracingHandlerFunc(sensor instana.TracerLogger, pathTemplate string, handler http.HandlerFunc) http.HandlerFunc
TracingHandlerFunc wraps an HTTP handler that handles Google Cloud Pub/Sub push deliveries sent via POST requests. If a request uses any other method, the wrapper uses instana.TracingHandlerFunc() to trace it as a regular HTTP request.
Please note, that this wrapper consumes the request body in order to to extract the trace context from the message, thus the (net/http.Request).Body is a copy of received data.
Example ¶
This example show how to instrument and HTTP handler that receives Google Cloud Pub/Sub messages via the push delivery method.
package main import ( "encoding/json" "fmt" "net/http" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/cloud.google.com/go/pubsub" ) func main() { // Initialize sensor sensor := instana.NewSensor("pubsub-consumer") // Wrap your Pub/Sub message handler with pubsub.TracingHandlerFunc http.Handle("/", pubsub.TracingHandlerFunc(sensor, "/", 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) })) }
Output:
Types ¶
type Client ¶
Client is an instrumented wrapper for cloud.google.com/go/pubsub.Client that traces message reads and writes to and from Google Cloud Pub/Sub topics. It also and ensures Instana trace propagation across the Pub/Sub producers and consumers.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client for further details on wrapped type.
func NewClient ¶
func NewClient(ctx context.Context, projectID string, sensor instana.TracerLogger, opts ...option.ClientOption) (*Client, error)
NewClient returns a new wrapped cloud.google.com/go/pubsub.Client that uses provided instana.Sensor to trace the publish/receive operations.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#NewClient for further details on wrapped method.
func (*Client) CreateSubscription ¶
func (c *Client) CreateSubscription(ctx context.Context, id string, cfg pubsub.SubscriptionConfig) (*Subscription, error)
CreateSubscription calls CreateSubscription() of underlying Client and wraps the returned subscription.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.CreateSubscription for further details on wrapped method.
func (*Client) CreateTopic ¶
CreateTopic calls CreateTopic() of underlying Client and wraps the returned topic.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.CreateTopic for further details on wrapped method.
func (*Client) CreateTopicWithConfig ¶
func (c *Client) CreateTopicWithConfig(ctx context.Context, topicID string, tc *pubsub.TopicConfig) (*Topic, error)
CreateTopicWithConfig calls CreateTopicWithConfig() of underlying Client and wraps returned topic.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.CreateTopicWithConfig for further details on wrapped method.
func (*Client) Subscription ¶
func (c *Client) Subscription(id string) *Subscription
Subscription calls Subscription() of underlying Client and wraps the returned subscription.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.Subscription for further details on wrapped method.
func (*Client) SubscriptionInProject ¶
func (c *Client) SubscriptionInProject(id, projectID string) *Subscription
SubscriptionInProject calls SubscriptionInProject() of underlying Client and wraps the returned subscription.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.SubscriptionInProject for further details on wrapped method.
func (*Client) Subscriptions ¶
func (c *Client) Subscriptions(ctx context.Context) *SubscriptionIterator
Subscriptions calls Subscriptions() of underlying Client and wraps the returned subscription iterator.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.Subscriptions for further details on wrapped method.
func (*Client) Topic ¶
Topic calls Topic() of underlying Client and wraps the returned topic.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.Topic for further details on wrapped method.
func (*Client) TopicInProject ¶
TopicInProject calls TopicInProject() of underlying Client and wraps the returned topic.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.TopicInProject for further details on wrapped method.
func (*Client) Topics ¶
func (c *Client) Topics(ctx context.Context) *TopicIterator
Topics calls Topics() of underlying Client and wraps the returned topic iterator.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Client.Topics for further details on wrapped method.
type PublishResult ¶
type PublishResult = pubsub.PublishResult
PublishResult is a type alias for cloud.google.com/go/pubsub.PublishResult
type Subscription ¶
type Subscription struct { *pubsub.Subscription // contains filtered or unexported fields }
Subscription is an instrumented wrapper for cloud.google.com/go/pubsub.Subscription that traces Receive() calls and ensures Instana trace propagation across the Pub/Sub producers and consumers.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Subscription for further details on wrapped type.
func (*Subscription) Receive ¶
func (sub *Subscription) Receive(ctx context.Context, f func(context.Context, *pubsub.Message)) error
Receive wraps the Receive() call of the underlying cloud.google.com/go/pubsub.Subscription starting a new entry span using the provided instana.Sensor and ensuring the trace continuation.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Subscription.Receive for further details on wrapped method.
type SubscriptionIterator ¶
type SubscriptionIterator struct { *pubsub.SubscriptionIterator // contains filtered or unexported fields }
SubscriptionIterator is a wrapper for cloud.google.com/go/pubsub.SubscriptionIterator that retrieves and instruments subscriptions in a project.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#SubscriptionIterator for further details on wrapped type.
func (*SubscriptionIterator) Next ¶
func (it *SubscriptionIterator) Next() (*Subscription, error)
Next fetches the next subscription in project via the wrapped SubscriptionIterator and returns its wrapped version.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#SubscriptionIterator.Next for further details on wrapped method.
type Topic ¶
Topic is an instrumented wrapper for cloud.google.com/go/pubsub.Topic that traces Publish() calls and ensures Instana trace propagation across the Pub/Sub producers and consumers.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Topic for further details on wrapped type.
func (*Topic) Publish ¶
Publish adds the trace context found in ctx to the message and publishes it to the wrapped topic. The exit span created for this operation will be finished only after the message was submitted to the server.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Topic.Publish for further details on wrapped method.
func (*Topic) Subscriptions ¶
func (top *Topic) Subscriptions(ctx context.Context) *SubscriptionIterator
Subscriptions calls Subscriptions() of underlying Topic and wraps the returned subscription iterator.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#Topic.Subscriptions for further details on wrapped method.
type TopicIterator ¶
type TopicIterator struct { *pubsub.TopicIterator // contains filtered or unexported fields }
TopicIterator is a wrapper for cloud.google.com/go/pubsub.TopicIterator that retrieves and instruments topics in a project.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#TopicIterator for further details on wrapped type.
func (*TopicIterator) Next ¶
func (it *TopicIterator) Next() (*Topic, error)
Next fetches the next topic in project via the wrapped TopicIterator and returns its wrapped version.
See https://pkg.go.dev/cloud.google.com/go/pubsub?tab=doc#TopicIterator.Next for further details on wrapped method.