Skip to content

Simple tool to generate opentracing decorators

Notifications You must be signed in to change notification settings

mkabischev/tracegen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tracegen

Generates interface decorators with opentracing support.

Installation

go get github.com/gojuno/tracegen

Example

type Cache interface {
	Set(ctx context.Context, key, value []byte) error
	Get(ctx context.Context, key []byte) (value []byte, err error)
}
tracegen -i Cache -o example/cache_trace.go example

Will generate:

type CacheTracer struct {
	next   Cache
	prefix string
}

func NewCacheTracer(next Cache, prefix string) *CacheTracer {
	return &CacheTracer{
		next:   next,
		prefix: prefix,
	}
}

func (t *CacheTracer) Get(ctx context.Context, key []byte) (value []byte, err error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, t.prefix+".Cache.Get")
	defer span.Finish()

	return t.next.Get(ctx, key)
}

func (t *CacheTracer) Set(ctx context.Context, key []byte, value []byte) error {
	span, ctx := opentracing.StartSpanFromContext(ctx, t.prefix+".Cache.Set")
	defer span.Finish()

	return t.next.Set(ctx, key, value)
}

About

Simple tool to generate opentracing decorators

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%