observer.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // This project is licensed under the Apache License 2.0, see LICENSE.
  2. package otobserver
  3. import opentracing "github.com/opentracing/opentracing-go"
  4. // Observer can be registered with a Tracer to recieve notifications
  5. // about new Spans. Tracers are not required to support the Observer API.
  6. // The actual registration depends on the implementation, which might look
  7. // like the below e.g :
  8. // observer := myobserver.NewObserver()
  9. // tracer := client.NewTracer(..., client.WithObserver(observer))
  10. //
  11. type Observer interface {
  12. // Create and return a span observer. Called when a span starts.
  13. // If the Observer is not interested in the given span, it must return (nil, false).
  14. // E.g :
  15. // func StartSpan(opName string, opts ...opentracing.StartSpanOption) {
  16. // var sp opentracing.Span
  17. // sso := opentracing.StartSpanOptions{}
  18. // spanObserver, ok := observer.OnStartSpan(span, opName, sso);
  19. // if ok {
  20. // // we have a valid SpanObserver
  21. // }
  22. // ...
  23. // }
  24. OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (SpanObserver, bool)
  25. }
  26. // SpanObserver is created by the Observer and receives notifications about
  27. // other Span events.
  28. type SpanObserver interface {
  29. // Callback called from opentracing.Span.SetOperationName()
  30. OnSetOperationName(operationName string)
  31. // Callback called from opentracing.Span.SetTag()
  32. OnSetTag(key string, value interface{})
  33. // Callback called from opentracing.Span.Finish()
  34. OnFinish(options opentracing.FinishOptions)
  35. }