otelsetup

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 9

README

go-otelsetup

opentelemetry-goを用いてOTel SDKのセットアップを行うためのライブラリ

利用方法

インストール:

go get github.com/sacloud/go-otelsetup

環境変数OTEL_EXPORTER_OTLP_ENDPOINTでOTLPエンドポイントを指定することでトレース/メトリクスが有効になります。

例: OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

また、OTEL_SDK_DISABLEDに空文字以外の値を指定することでトレース/メトリクスを無効化できます。

利用例

	// SDKの初期化
	shutdown, err := otelsetup.Init(context.Background(), "go-otelsetup", "0.0.1")
	if err != nil {
		panic(err)
	}
	defer shutdown(context.Background())

	// トレースの開始
	tracer := otel.Tracer("github.com/sacloud/go-otelsetup")
	ctx, span := tracer.Start(context.Background(), "example")
	defer span.End()

	fmt.Println("SpanID:", trace.SpanContextFromContext(ctx).SpanID())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextForTrace added in v0.0.4

func ContextForTrace(ctx context.Context) context.Context

ContextForTrace 環境変数からトレースコンテキストを読み取り、propagator経由で値を反映させたコンテキストを返す

func Enabled added in v0.0.2

func Enabled() bool

func ExtractTextMapCarrier added in v0.0.4

func ExtractTextMapCarrier(ctx context.Context) propagation.TextMapCarrier

ExtractTextMapCarrier 現在のコンテキストからTextMapCarrierを抽出する

func Init

func Init(ctx context.Context, serviceName, serviceVersion string) (shutdown func(context.Context) error, err error)

func InitWithOptions added in v0.0.5

func InitWithOptions(ctx context.Context, opts Options) (shutdown func(context.Context) error, err error)

Types

type Options added in v0.0.5

type Options struct {
	ServiceName      string
	ServiceVersion   string
	ServiceNamespace string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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