Compare commits

...

15 Commits

Author SHA1 Message Date
93cb40a39b Merge pull request #28 from unistack-org/fixup
add ability to pass opentracing.Tracer
2023-01-17 09:23:12 +03:00
38d841d5b6 add ability to pass opentracing.Tracer
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-01-17 09:21:48 +03:00
b7b6d50dc6 add ability to pass opentracing.Tracer
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-01-17 08:43:04 +03:00
1566ccf0d8 Merge pull request #27 from unistack-org/fixes
implement tracer.Tracer interface
2023-01-16 23:43:40 +03:00
2abea05b41 update
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-01-16 23:41:56 +03:00
a5c1f0a9a7 Merge pull request #26 from unistack-org/dependabot/go_modules/go.unistack.org/micro/v3-3.10.0
Bump go.unistack.org/micro/v3 from 3.9.18 to 3.10.0
2023-01-09 05:15:34 +03:00
dependabot[bot]
3d56f83bd2 Bump go.unistack.org/micro/v3 from 3.9.18 to 3.10.0
Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.9.18 to 3.10.0.
- [Release notes](https://github.com/unistack-org/micro/releases)
- [Commits](https://github.com/unistack-org/micro/compare/v3.9.18...v3.10.0)

---
updated-dependencies:
- dependency-name: go.unistack.org/micro/v3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-09 02:14:12 +00:00
9b7a48f410 Merge pull request #25 from unistack-org/dependabot/go_modules/go.unistack.org/micro/v3-3.9.18
Bump go.unistack.org/micro/v3 from 3.9.17 to 3.9.18
2022-12-28 05:06:53 +03:00
dependabot[bot]
418124c029 Bump go.unistack.org/micro/v3 from 3.9.17 to 3.9.18
Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.9.17 to 3.9.18.
- [Release notes](https://github.com/unistack-org/micro/releases)
- [Commits](https://github.com/unistack-org/micro/compare/v3.9.17...v3.9.18)

---
updated-dependencies:
- dependency-name: go.unistack.org/micro/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-28 02:05:24 +00:00
a0526b1790 Merge pull request #24 from unistack-org/dependabot/go_modules/go.unistack.org/micro/v3-3.9.17
Bump go.unistack.org/micro/v3 from 3.9.15 to 3.9.17
2022-12-26 05:14:42 +03:00
dependabot[bot]
ea7f1e66e7 Bump go.unistack.org/micro/v3 from 3.9.15 to 3.9.17
Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.9.15 to 3.9.17.
- [Release notes](https://github.com/unistack-org/micro/releases)
- [Commits](https://github.com/unistack-org/micro/compare/v3.9.15...v3.9.17)

---
updated-dependencies:
- dependency-name: go.unistack.org/micro/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-26 02:13:26 +00:00
690f9e1471 Merge pull request #23 from unistack-org/dependabot/go_modules/go.unistack.org/micro/v3-3.9.15
Bump go.unistack.org/micro/v3 from 3.9.14 to 3.9.15
2022-11-29 05:09:06 +03:00
dependabot[bot]
c4fcb7319c Bump go.unistack.org/micro/v3 from 3.9.14 to 3.9.15
Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.9.14 to 3.9.15.
- [Release notes](https://github.com/unistack-org/micro/releases)
- [Commits](https://github.com/unistack-org/micro/compare/v3.9.14...v3.9.15)

---
updated-dependencies:
- dependency-name: go.unistack.org/micro/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-29 02:07:50 +00:00
2f03982b7b Merge pull request #22 from unistack-org/dependabot/go_modules/go.unistack.org/micro/v3-3.9.14
Bump go.unistack.org/micro/v3 from 3.9.13 to 3.9.14
2022-11-28 05:13:17 +03:00
dependabot[bot]
051fcd556f Bump go.unistack.org/micro/v3 from 3.9.13 to 3.9.14
Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.9.13 to 3.9.14.
- [Release notes](https://github.com/unistack-org/micro/releases)
- [Commits](https://github.com/unistack-org/micro/compare/v3.9.13...v3.9.14)

---
updated-dependencies:
- dependency-name: go.unistack.org/micro/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-28 02:11:50 +00:00
5 changed files with 73 additions and 12 deletions

2
go.mod
View File

@@ -4,6 +4,6 @@ go 1.16
require ( require (
github.com/opentracing/opentracing-go v1.2.0 github.com/opentracing/opentracing-go v1.2.0
go.unistack.org/micro/v3 v3.9.13 go.unistack.org/micro/v3 v3.10.1
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
) )

4
go.sum
View File

@@ -73,8 +73,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.unistack.org/micro-proto/v3 v3.3.1/go.mod h1:cwRyv8uInM2I7EbU7O8Fx2Ls3N90Uw9UCCcq4olOdfE= go.unistack.org/micro-proto/v3 v3.3.1/go.mod h1:cwRyv8uInM2I7EbU7O8Fx2Ls3N90Uw9UCCcq4olOdfE=
go.unistack.org/micro/v3 v3.9.13 h1:x1/H4rDgvz2JWXx6UvFiWDyRLxg2Kpp6V1kjzpLlyvo= go.unistack.org/micro/v3 v3.10.1 h1:MbtPj7ueTw4x6lL2Ok2ez70ORyGXBWhxizO5fQsnAA4=
go.unistack.org/micro/v3 v3.9.13/go.mod h1:gI4RkJKHLPW7KV6h4+ZBOZD997MRvFRXMPQIHpozikI= go.unistack.org/micro/v3 v3.10.1/go.mod h1:gI4RkJKHLPW7KV6h4+ZBOZD997MRvFRXMPQIHpozikI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=

View File

@@ -1,10 +1,11 @@
// Package opentracing provides wrappers for OpenTracing
package opentracing package opentracing
import ( import (
"context" "context"
"errors"
opentracing "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
"go.unistack.org/micro/v3/metadata" "go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v3/tracer" "go.unistack.org/micro/v3/tracer"
) )
@@ -12,7 +13,8 @@ import (
var _ tracer.Tracer = &opentracingTracer{} var _ tracer.Tracer = &opentracingTracer{}
type opentracingTracer struct { type opentracingTracer struct {
opts tracer.Options opts tracer.Options
tracer opentracing.Tracer
} }
func (ot *opentracingTracer) Name() string { func (ot *opentracingTracer) Name() string {
@@ -20,11 +22,58 @@ func (ot *opentracingTracer) Name() string {
} }
func (ot *opentracingTracer) Init(opts ...tracer.Option) error { func (ot *opentracingTracer) Init(opts ...tracer.Option) error {
for _, o := range opts {
o(&ot.opts)
}
if tr, ok := ot.opts.Context.Value(tracerKey{}).(opentracing.Tracer); ok {
ot.tracer = tr
} else {
return errors.New("Tracer option missing")
}
return nil return nil
} }
func (ot *opentracingTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) { func (ot *opentracingTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) {
return nil, nil ctx, span, _ := startSpanFromIncomingContext(ctx, ot.tracer, name)
return ctx, &opentracingSpan{span: span}
}
type opentracingSpan struct {
span opentracing.Span
labels []interface{}
}
func (os *opentracingSpan) Tracer() tracer.Tracer {
return &opentracingTracer{tracer: os.span.Tracer()}
}
func (os *opentracingSpan) Finish(opts ...tracer.SpanOption) {
if len(os.labels) > 0 {
os.span.LogKV(os.labels...)
}
os.span.Finish()
}
func (os *opentracingSpan) AddEvent(name string, opts ...tracer.EventOption) {
os.span.LogFields(log.Event(name))
}
func (os *opentracingSpan) Context() context.Context {
return tracer.NewSpanContext(context.Background(), os)
}
func (os *opentracingSpan) SetName(name string) {
os.span = os.span.SetOperationName(name)
}
func (os *opentracingSpan) SetLabels(labels ...interface{}) {
os.labels = labels
}
func (os *opentracingSpan) AddLabels(labels ...interface{}) {
os.labels = append(os.labels, labels...)
} }
func NewTracer(opts ...tracer.Option) *opentracingTracer { func NewTracer(opts ...tracer.Option) *opentracingTracer {
@@ -36,9 +85,9 @@ func spanFromContext(ctx context.Context) opentracing.Span {
return opentracing.SpanFromContext(ctx) return opentracing.SpanFromContext(ctx)
} }
// StartSpanFromOutgoingContext returns a new span with the given operation name and options. If a span // startSpanFromOutgoingContext returns a new span with the given operation name and options. If a span
// is found in the context, it will be used as the parent of the resulting span. // is found in the context, it will be used as the parent of the resulting span.
func StartSpanFromOutgoingContext(ctx context.Context, tracer opentracing.Tracer, name string, opts ...opentracing.StartSpanOption) (context.Context, opentracing.Span, error) { func startSpanFromOutgoingContext(ctx context.Context, tracer opentracing.Tracer, name string, opts ...opentracing.StartSpanOption) (context.Context, opentracing.Span, error) {
var parentCtx opentracing.SpanContext var parentCtx opentracing.SpanContext
md, ok := metadata.FromIncomingContext(ctx) md, ok := metadata.FromIncomingContext(ctx)
@@ -67,9 +116,9 @@ func StartSpanFromOutgoingContext(ctx context.Context, tracer opentracing.Tracer
return ctx, sp, nil return ctx, sp, nil
} }
// StartSpanFromIncomingContext returns a new span with the given operation name and options. If a span // startSpanFromIncomingContext returns a new span with the given operation name and options. If a span
// is found in the context, it will be used as the parent of the resulting span. // is found in the context, it will be used as the parent of the resulting span.
func StartSpanFromIncomingContext(ctx context.Context, tracer opentracing.Tracer, name string, opts ...opentracing.StartSpanOption) (context.Context, opentracing.Span, error) { func startSpanFromIncomingContext(ctx context.Context, tracer opentracing.Tracer, name string, opts ...opentracing.StartSpanOption) (context.Context, opentracing.Span, error) {
var parentCtx opentracing.SpanContext var parentCtx opentracing.SpanContext
// Find parent span. // Find parent span.

View File

@@ -26,7 +26,7 @@ func TestStartSpanFromIncomingContext(t *testing.T) {
for i := 0; i < 8000; i++ { for i := 0; i < 8000; i++ {
go func() { go func() {
defer g.Done() defer g.Done()
_, sp, err := StartSpanFromIncomingContext(ctx, tracer, "test") _, sp, err := startSpanFromIncomingContext(ctx, tracer, "test")
if err != nil { if err != nil {
cherr <- err cherr <- err
} }

12
options.go Normal file
View File

@@ -0,0 +1,12 @@
package opentracing
import (
"github.com/opentracing/opentracing-go"
"go.unistack.org/micro/v3/tracer"
)
type tracerKey struct{}
func Tracer(ot opentracing.Tracer) tracer.Option {
return tracer.SetOption(tracerKey{}, ot)
}