pubsub

package
v1.69.1-rc.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package pubsub provides functions to trace the cloud.google.com/pubsub/go package.

Index

Examples

Constants

This section is empty.

Variables

View Source
var WithMeasured = tracing.WithMeasured

WithMeasured sets the measured tag for traces started by WrapReceiveHandler or Publish.

View Source
var WithServiceName = tracing.WithServiceName

WithServiceName sets the service name tag for traces started by WrapReceiveHandler or Publish.

Functions

func WrapReceiveHandler

func WrapReceiveHandler(s *pubsub.Subscription, f func(context.Context, *pubsub.Message), opts ...Option) func(context.Context, *pubsub.Message)

WrapReceiveHandler returns a receive handler that wraps the supplied handler, extracts any tracing metadata attached to the received message, and starts a receive span.

Types

type Option added in v1.44.0

type Option = tracing.Option

Option is used to customize spans started by WrapReceiveHandler or Publish.

type PublishResult

type PublishResult struct {
	*pubsub.PublishResult
	// contains filtered or unexported fields
}

PublishResult wraps *pubsub.PublishResult

func Publish

func Publish(ctx context.Context, t *pubsub.Topic, msg *pubsub.Message, opts ...Option) *PublishResult

Publish publishes a message on the specified topic and returns a PublishResult. This function is functionally equivalent to t.Publish(ctx, msg), but it also starts a publish span and it ensures that the tracing metadata is propagated as attributes attached to the published message. It is required to call (*PublishResult).Get(ctx) on the value returned by Publish to complete the span.

Example
package main

import (
	"context"
	"log"

	pubsubtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/cloud.google.com/go/pubsub.v1"

	"cloud.google.com/go/pubsub"
)

func main() {
	client, err := pubsub.NewClient(context.Background(), "project-id")
	if err != nil {
		log.Fatal(err)
	}

	topic := client.Topic("topic")
	_, err = pubsubtrace.Publish(context.Background(), topic, &pubsub.Message{Data: []byte("hello world!")}).Get(context.Background())
	if err != nil {
		log.Fatal(err)
	}
}
Output:

func (*PublishResult) Get

func (r *PublishResult) Get(ctx context.Context) (string, error)

Get wraps (pubsub.PublishResult).Get(ctx). When this function returns the publish span created in Publish is completed.

type ReceiveOption deprecated added in v1.28.0

type ReceiveOption = Option

Deprecated: ReceiveOption has been deprecated in favor of Option.

Directories

Path Synopsis
internal
tracing
Package tracing contains tracing logic for the cloud.google.com/go/pubsub.v1 instrumentation.
Package tracing contains tracing logic for the cloud.google.com/go/pubsub.v1 instrumentation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL