smithyoteltracing

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package smithyoteltracing implements a Smithy client tracing adapter for the OTEL Go SDK.

Usage

Callers use the Adapt API in this package to wrap a concrete OTEL SDK TracerProvider.

The following example uses the AWS SDK for S3:

import (
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/s3"
	"github.com/aws/smithy-go/tracing/smithyoteltracing"
	"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
	"go.opentelemetry.io/otel/sdk/trace"
)

func main() {
	exporter, err := stdouttrace.New()
	if err != nil {
		panic(err)
	}

	cfg, err := config.LoadDefaultConfig(context.Background())
	if err != nil {
		panic(err)
	}

	provider := trace.NewTracerProvider(trace.WithBatcher(exporter))
	svc := s3.NewFromConfig(cfg, func(o *s3.Options) {
		o.TracerProvider = smithyoteltracing.Adapt(provider)
	})
	// ...
}

OTEL Attributes

This adapter supports all attribute types used in the OTEL SDK (including their slice-of variants):

  • bool
  • int
  • int64
  • float64
  • string

A key-value pair set on a smithy.Properties container in any of the tracing APIs will automatically propagate to the underlying OTEL SDK if its key is of type string and its value is one of those supported. Otherwise, the adapter will make an effort to stringify the key or value as follows:

  • if value implements String(), use that value
  • otherwise, use the Go-string representation of the value (the result of fmt.Sprintf("%#v", ...))

e.g.

type key struct{}

func (k key) String() string {
	return "app.key"
}

type key2 struct{}

ctx, span := tracing.StartSpan(ctx, "Foo", func(o *tracing.SpanOptions) {
	o.Properties.Set("app.version", "bar") // -> ("app.version", "bar")
	o.Properties.Set(key{}, "baz")         // -> ("app.key", "baz")
	o.Properties.Set(key2{}, "qux")        // -> ("main.key2{}", "qux")
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapt

Adapt wraps a concrete OpenTelemetry SDK TraceProvider for use with Smithy SDK clients.

Adapt can be called multiple times on a single TracerProvider.

Types

This section is empty.

Jump to

Keyboard shortcuts

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