span_context_kv_iterable.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "opentelemetry/common/attribute_value.h"
  5. #include "opentelemetry/common/key_value_iterable_view.h"
  6. #include "opentelemetry/nostd/function_ref.h"
  7. #include "opentelemetry/trace/span_context.h"
  8. #include "opentelemetry/version.h"
  9. OPENTELEMETRY_BEGIN_NAMESPACE
  10. namespace trace
  11. {
  12. /**
  13. * Supports internal iteration over a collection of SpanContext/key-value pairs.
  14. */
  15. class SpanContextKeyValueIterable
  16. {
  17. public:
  18. virtual ~SpanContextKeyValueIterable() = default;
  19. /**
  20. * Iterate over SpanContext/key-value pairs
  21. * @param callback a callback to invoke for each key-value for each SpanContext.
  22. * If the callback returns false, the iteration is aborted.
  23. * @return true if every SpanContext/key-value pair was iterated over
  24. */
  25. virtual bool ForEachKeyValue(
  26. nostd::function_ref<bool(SpanContext, const common::KeyValueIterable &)> callback)
  27. const noexcept = 0;
  28. /**
  29. * @return the number of key-value pairs
  30. */
  31. virtual size_t size() const noexcept = 0;
  32. };
  33. /**
  34. * @brief Null Span context that does not carry any information.
  35. */
  36. class NullSpanContext : public SpanContextKeyValueIterable
  37. {
  38. public:
  39. bool ForEachKeyValue(nostd::function_ref<bool(SpanContext, const common::KeyValueIterable &)>
  40. /* callback */) const noexcept override
  41. {
  42. return true;
  43. }
  44. size_t size() const noexcept override { return 0; }
  45. };
  46. } // namespace trace
  47. OPENTELEMETRY_END_NAMESPACE