-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from hkshaw1990/perfevent_support
Monitoring platform events with zipkin-go and opentracing
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package zipkintracer | ||
|
||
import ( | ||
opentracing "github.com/opentracing/opentracing-go" | ||
otobserver "github.com/opentracing-contrib/go-observer" | ||
) | ||
|
||
// observer is a dispatcher to other observers | ||
type observer struct { | ||
observers []otobserver.Observer | ||
} | ||
|
||
// spanObserver is a dispatcher to other span observers | ||
type spanObserver struct { | ||
observers []otobserver.SpanObserver | ||
} | ||
|
||
func (o observer) OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (otobserver.SpanObserver, bool) { | ||
var spanObservers []otobserver.SpanObserver | ||
for _, obs := range o.observers { | ||
spanObs, ok := obs.OnStartSpan(sp, operationName, options) | ||
if ok { | ||
if spanObservers == nil { | ||
spanObservers = make([]otobserver.SpanObserver, 0, len(o.observers)) | ||
} | ||
spanObservers = append(spanObservers, spanObs) | ||
} | ||
} | ||
if len(spanObservers) == 0 { | ||
return nil, false | ||
} | ||
|
||
return spanObserver{observers: spanObservers}, true | ||
} | ||
|
||
func (o spanObserver) OnSetOperationName(operationName string) { | ||
for _, obs := range o.observers { | ||
obs.OnSetOperationName(operationName) | ||
} | ||
} | ||
|
||
func (o spanObserver) OnSetTag(key string, value interface{}) { | ||
for _, obs := range o.observers { | ||
obs.OnSetTag(key, value) | ||
} | ||
} | ||
|
||
func (o spanObserver) OnFinish(options opentracing.FinishOptions) { | ||
for _, obs := range o.observers { | ||
obs.OnFinish(options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters