spannerotel

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT

README

spannerotel

OpenTelemetry helpers for cloud.google.com/go/spanner:

  • interceptor/ — gRPC stream interceptor that decorates spans with query stats and GFE timing
  • internal/plantotrace/ — PROFILE plan node spans (requires query plan in ResultSetStats)
  • tracing/ — TracerProvider setup for Cloud Trace, OTLP/gRPC, or stderr JSON export

Spanner v1.90+ emits traces via OpenTelemetry natively; an OpenCensus bridge is not required.

Usage

import (
	"cloud.google.com/go/spanner"
	"github.com/apstndb/spannerotel/interceptor"
	"github.com/apstndb/spannerotel/tracing"
	"google.golang.org/api/option"
	"google.golang.org/grpc"
)

tp, err := tracing.NewTracerProvider(tracing.Config{
	Exporter:    tracing.ExporterOTLP,
	ServiceName: "my-app",
	OTLPEndpoint: "localhost:4317",
	OTLPInsecure: true,
})
if err != nil {
	// handle error
}
defer tracing.Shutdown(ctx, tp)

client, err := spanner.NewClientWithConfig(ctx, database, spanner.ClientConfig{},
	option.WithGRPCDialOption(grpc.WithChainStreamInterceptor(
		interceptor.StreamInterceptor(interceptor.WithDefaultDecorators()),
	)),
)
Exporters
Exporter Use case
ExporterCloudTrace Google Cloud Trace (CloudTraceProject required)
ExporterOTLP Local collector, Jaeger, Grafana Tempo, etc. (OTLPEndpoint, optional OTLPInsecure)
ExporterStdout Pretty JSON to stderr (StdoutWriter, PrettyStdout)

Plan node spans from plantotrace appear only when the Spanner client returns a PROFILE query plan in stats.

See example/query for a PROFILE query with stderr tracing.

Directories

Path Synopsis
example
query command
Example program runs a PROFILE query with stdout trace export.
Example program runs a PROFILE query with stdout trace export.
internal

Jump to

Keyboard shortcuts

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