pubsub

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pubsub provides helpers for configuring PubSub clients with OpenTelemetry tracing (for both producers and consumers).

This is v2 of the package, which replaces the positional config and client options arguments with a functional options pattern for a more ergonomic and extensible API. Migrate from v1 by replacing:

pubsub.NewClient(ctx, projectID, config, opts...)

with:

pubsubv2.NewClient(ctx, projectID, pubsubv2.WithConfig(config), pubsubv2.WithClientOptions(opts...))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(ctx context.Context, projectID string, opts ...Option) (*pubsub.Client, error)

NewClient initializes a new GCP PubSub client.

By default, OpenTelemetry tracing is enabled at the pubsub library level. This behaviour can be changed in two independent ways:

Returns a new *pubsub.Client and an error if the client could not be created.

Types

type Option

type Option func(*options)

Option is a functional option for configuring the PubSub client.

func WithClientOptions

func WithClientOptions(opts ...option.ClientOption) Option

WithClientOptions sets additional Google API client options on the PubSub client. These are passed directly to the underlying pubsub.NewClientWithConfig call and are useful for configuring credentials, endpoints, or transport settings. Multiple calls to WithClientOptions overwrite previous ones; use a single call with all desired options if multiple are needed.

func WithConfig

func WithConfig(cfg *pubsub.ClientConfig) Option

WithConfig sets a custom pubsub.ClientConfig on the client. When provided, the caller controls all fields in the config, including EnableOpenTelemetryTracing. Passing nil resets to the default behaviour: an empty config with EnableOpenTelemetryTracing set to true.

func WithDisabledGrpcTracing

func WithDisabledGrpcTracing() Option

WithDisabledGrpcTracing disables gRPC-level telemetry on the PubSub client by appending option.WithTelemetryDisabled to the client options. This operates at the transport layer and is independent of the EnableOpenTelemetryTracing field in pubsub.ClientConfig, which controls OTel tracing at the pubsub library level.

Jump to

Keyboard shortcuts

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