contrib_observer.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2017 Uber Technologies, Inc.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. package jaeger
  21. import (
  22. opentracing "github.com/opentracing/opentracing-go"
  23. )
  24. // ContribObserver can be registered with the Tracer to receive notifications
  25. // about new Spans. Modelled after github.com/opentracing-contrib/go-observer.
  26. type ContribObserver interface {
  27. // Create and return a span observer. Called when a span starts.
  28. // If the Observer is not interested in the given span, it must return (nil, false).
  29. // E.g :
  30. // func StartSpan(opName string, opts ...opentracing.StartSpanOption) {
  31. // var sp opentracing.Span
  32. // sso := opentracing.StartSpanOptions{}
  33. // if spanObserver, ok := Observer.OnStartSpan(span, opName, sso); ok {
  34. // // we have a valid SpanObserver
  35. // }
  36. // ...
  37. // }
  38. OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (ContribSpanObserver, bool)
  39. }
  40. // ContribSpanObserver is created by the Observer and receives notifications
  41. // about other Span events. This interface is meant to match
  42. // github.com/opentracing-contrib/go-observer, via duck typing, without
  43. // directly importing the go-observer package.
  44. type ContribSpanObserver interface {
  45. OnSetOperationName(operationName string)
  46. OnSetTag(key string, value interface{})
  47. OnFinish(options opentracing.FinishOptions)
  48. }
  49. // wrapper observer for the old observers (see observer.go)
  50. type oldObserver struct {
  51. obs Observer
  52. }
  53. func (o *oldObserver) OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (ContribSpanObserver, bool) {
  54. spanObserver := o.obs.OnStartSpan(operationName, options)
  55. return spanObserver, spanObserver != nil
  56. }