contrib_observer.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2017 Uber Technologies, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package jaeger
  15. import (
  16. opentracing "github.com/opentracing/opentracing-go"
  17. )
  18. // ContribObserver can be registered with the Tracer to receive notifications
  19. // about new Spans. Modelled after github.com/opentracing-contrib/go-observer.
  20. type ContribObserver interface {
  21. // Create and return a span observer. Called when a span starts.
  22. // If the Observer is not interested in the given span, it must return (nil, false).
  23. // E.g :
  24. // func StartSpan(opName string, opts ...opentracing.StartSpanOption) {
  25. // var sp opentracing.Span
  26. // sso := opentracing.StartSpanOptions{}
  27. // if spanObserver, ok := Observer.OnStartSpan(span, opName, sso); ok {
  28. // // we have a valid SpanObserver
  29. // }
  30. // ...
  31. // }
  32. OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (ContribSpanObserver, bool)
  33. }
  34. // ContribSpanObserver is created by the Observer and receives notifications
  35. // about other Span events. This interface is meant to match
  36. // github.com/opentracing-contrib/go-observer, via duck typing, without
  37. // directly importing the go-observer package.
  38. type ContribSpanObserver interface {
  39. OnSetOperationName(operationName string)
  40. OnSetTag(key string, value interface{})
  41. OnFinish(options opentracing.FinishOptions)
  42. }
  43. // wrapper observer for the old observers (see observer.go)
  44. type oldObserver struct {
  45. obs Observer
  46. }
  47. func (o *oldObserver) OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (ContribSpanObserver, bool) {
  48. spanObserver := o.obs.OnStartSpan(operationName, options)
  49. return spanObserver, spanObserver != nil
  50. }