gootel

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 14 Imported by: 0

README

go-opentelemetry v2

Go OpenTelemetry Helper.

Why we need v2?

  1. Span trace front to back (context propagation).
  2. Upgrade go version to v1.21.0 and otel version from v1.10.0 to v1.28.0, see why_need_upgrade_version.
  3. Better library API. See better_api.md

Feature

  • Opentelemetry Trace
  • Opentelemetry Context Propagation

context_propagation

Installation v2

go get github.com/erajayatech/go-opentelemetry/v2@v2.0.0-alpha.10
import gootel "github.com/erajayatech/go-opentelemetry/v2"

Checklist implement v2

Here is checklist for you to check wheter you already implement this v2 fully.

  1. Your import is using v2 and ranme.
import gootel "github.com/erajayatech/go-opentelemetry/v2"
  1. You create new trace provider and shutdown it properly. See example.
tp, err := gootel.NewTraceProvider(context.Background())
fatalIfErr(err)
defer func() {
    err := tp.Shutdown(context.Background())
    warnIfErr(err)
}()
  1. Your server ready to receive context propagation. See example gin and See example grpc.
ginEngine := gin.Default()
ginEngine.Use(otelgin.Middleware(""))
grpcServer := grpc.NewServer(grpc.StatsHandler(otelgrpc.NewServerHandler()))
  1. You record the span.
ctx, span := gootel.RecordSpan(ctx)
defer span.End()
  1. Your client sent context propagation. See example http and example grpc.
client := &http.Client{Transport: otelhttp.NewTransport(http.DefaultTransport)}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost:4000/foo", nil)
conn, err := grpc.NewClient("localhost:4001", grpc.WithStatsHandler(otelgrpc.NewClientHandler()), grpc.WithTransportCredentials(insecure.NewCredentials()))

Usage

See example server and example client.

In New Relic you will get.

grpc-client-span

http-client-span

Migrate from v1

See Migrate from v1

Things should be highlighted in v2

See highlighted_in_v2.md

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSpanError deprecated

func AddSpanError(span trace.Span, err error)

AddSpanError is retained for compatibility with version 1.

Deprecated: Use span.RecordError(err) instead.

func AddSpanEvents deprecated

func AddSpanEvents(span trace.Span, name string, events map[string]string)

AddSpanEvents is retained for compatibility with version 1.

Deprecated: Use span.AddEvent instead.

func AddSpanTags deprecated

func AddSpanTags(span trace.Span, tags map[string]string)

AddSpanTags is retained for compatibility with version 1.

Deprecated: Use span.SetAttributes instead.

func ConstructOtelTracer deprecated

func ConstructOtelTracer() *otelTracer

ConstructOtelTracer is retained for compatibility with version 1.

Deprecated: Use NewTraceProvider instead. See v2/example/server/main.go

func FailSpan deprecated

func FailSpan(span trace.Span, msg string)

SetStatus is retained for compatibility with version 1.

Deprecated: Use span.SetStatus(codes.Error, msg) instead.

func NewHttpSpan deprecated

func NewHttpSpan(ctx context.Context, name string, operation string, httpSpanAttribute HttpSpanAttribute) (context.Context, trace.Span)

AddSpanTags is retained for compatibility with version 1.

Deprecated: Use RecordSpan instead.

func NewSpan deprecated

func NewSpan(ctx context.Context, args ...string) (context.Context, trace.Span)

NewSpan is retained for compatibility with version 1.

Deprecated: Use RecordSpan instead.

func NewTraceProvider

func NewTraceProvider(ctx context.Context) (*sdktrace.TracerProvider, error)

NewTraceProvider return opentelemetry trace provider.

func RecordSpan

func RecordSpan(ctx context.Context) (context.Context, trace.Span)

RecordSpan to record span.

func SpanFromContext deprecated

func SpanFromContext(ctx context.Context) trace.Span

SpanFromContext is retained for compatibility with version 1.

Deprecated: Use trace.SpanFromContext(ctx) instead.

func Start deprecated

func Start(ctx context.Context) (context.Context, trace.Span)

Start is retained for compatibility with version 1.

Deprecated: Use RecordSpan instead.

func StartWorker deprecated

func StartWorker(ctx context.Context) (context.Context, trace.Span)

StartWorker is retained for compatibility with version 1.

Deprecated: Use RecordSpan instead.

Types

type HttpSpanAttribute

type HttpSpanAttribute struct {
	Method     string
	Version    string
	Url        string
	IP         string
	StatusCode int
}

Directories

Path Synopsis
example
example_compatible_v1
internal

Jump to

Keyboard shortcuts

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