span_processor.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright The OpenTelemetry Authors
  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 trace // import "go.opentelemetry.io/otel/sdk/trace"
  15. import (
  16. "context"
  17. "sync"
  18. )
  19. // SpanProcessor is a processing pipeline for spans in the trace signal.
  20. // SpanProcessors registered with a TracerProvider and are called at the start
  21. // and end of a Span's lifecycle, and are called in the order they are
  22. // registered.
  23. type SpanProcessor interface {
  24. // DO NOT CHANGE: any modification will not be backwards compatible and
  25. // must never be done outside of a new major release.
  26. // OnStart is called when a span is started. It is called synchronously
  27. // and should not block.
  28. OnStart(parent context.Context, s ReadWriteSpan)
  29. // DO NOT CHANGE: any modification will not be backwards compatible and
  30. // must never be done outside of a new major release.
  31. // OnEnd is called when span is finished. It is called synchronously and
  32. // hence not block.
  33. OnEnd(s ReadOnlySpan)
  34. // DO NOT CHANGE: any modification will not be backwards compatible and
  35. // must never be done outside of a new major release.
  36. // Shutdown is called when the SDK shuts down. Any cleanup or release of
  37. // resources held by the processor should be done in this call.
  38. //
  39. // Calls to OnStart, OnEnd, or ForceFlush after this has been called
  40. // should be ignored.
  41. //
  42. // All timeouts and cancellations contained in ctx must be honored, this
  43. // should not block indefinitely.
  44. Shutdown(ctx context.Context) error
  45. // DO NOT CHANGE: any modification will not be backwards compatible and
  46. // must never be done outside of a new major release.
  47. // ForceFlush exports all ended spans to the configured Exporter that have not yet
  48. // been exported. It should only be called when absolutely necessary, such as when
  49. // using a FaaS provider that may suspend the process after an invocation, but before
  50. // the Processor can export the completed spans.
  51. ForceFlush(ctx context.Context) error
  52. // DO NOT CHANGE: any modification will not be backwards compatible and
  53. // must never be done outside of a new major release.
  54. }
  55. type spanProcessorState struct {
  56. sp SpanProcessor
  57. state sync.Once
  58. }
  59. func newSpanProcessorState(sp SpanProcessor) *spanProcessorState {
  60. return &spanProcessorState{sp: sp}
  61. }
  62. type spanProcessorStates []*spanProcessorState