attribute_value.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include <cstdint>
  5. #include "opentelemetry/nostd/span.h"
  6. #include "opentelemetry/nostd/string_view.h"
  7. #include "opentelemetry/nostd/variant.h"
  8. #include "opentelemetry/version.h"
  9. OPENTELEMETRY_BEGIN_NAMESPACE
  10. namespace common
  11. {
  12. /// OpenTelemetry signals can be enriched by adding attributes. The
  13. /// \c AttributeValue type is defined as a variant of all attribute value
  14. /// types the OpenTelemetry C++ API supports.
  15. ///
  16. /// The following attribute value types are supported by the OpenTelemetry
  17. /// specification:
  18. /// - Primitive types: string, boolean, double precision floating point
  19. /// (IEEE 754-1985) or signed 64 bit integer.
  20. /// - Homogenous arrays of primitive type values.
  21. ///
  22. /// \warning
  23. /// \parblock The OpenTelemetry C++ API currently supports several attribute
  24. /// value types that are not covered by the OpenTelemetry specification:
  25. /// - \c uint64_t
  26. /// - \c nostd::span<const uint64_t>
  27. /// - \c nostd::span<uint8_t>
  28. ///
  29. /// Those types are reserved for future use and currently should not be
  30. /// used. There are no guarantees around how those values are handled by
  31. /// exporters.
  32. /// \endparblock
  33. using AttributeValue =
  34. nostd::variant<bool,
  35. int32_t,
  36. int64_t,
  37. uint32_t,
  38. double,
  39. const char *,
  40. nostd::string_view,
  41. nostd::span<const bool>,
  42. nostd::span<const int32_t>,
  43. nostd::span<const int64_t>,
  44. nostd::span<const uint32_t>,
  45. nostd::span<const double>,
  46. nostd::span<const nostd::string_view>,
  47. // Not currently supported by the specification, but reserved for future use.
  48. // Added to provide support for all primitive C++ types.
  49. uint64_t,
  50. // Not currently supported by the specification, but reserved for future use.
  51. // Added to provide support for all primitive C++ types.
  52. nostd::span<const uint64_t>,
  53. // Not currently supported by the specification, but reserved for future use.
  54. // See https://github.com/open-telemetry/opentelemetry-specification/issues/780
  55. nostd::span<const uint8_t>>;
  56. enum AttributeType
  57. {
  58. kTypeBool,
  59. kTypeInt,
  60. kTypeInt64,
  61. kTypeUInt,
  62. kTypeDouble,
  63. kTypeCString,
  64. kTypeString,
  65. kTypeSpanBool,
  66. kTypeSpanInt,
  67. kTypeSpanInt64,
  68. kTypeSpanUInt,
  69. kTypeSpanDouble,
  70. kTypeSpanString,
  71. kTypeUInt64,
  72. kTypeSpanUInt64,
  73. kTypeSpanByte
  74. };
  75. } // namespace common
  76. OPENTELEMETRY_END_NAMESPACE