event_id.h 797 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include <algorithm>
  5. #include "opentelemetry/nostd/string_view.h"
  6. #include "opentelemetry/nostd/unique_ptr.h"
  7. #include "opentelemetry/version.h"
  8. OPENTELEMETRY_BEGIN_NAMESPACE
  9. namespace logs
  10. {
  11. /**
  12. * EventId class which acts the Id of the event with an optional name.
  13. */
  14. class EventId
  15. {
  16. public:
  17. EventId(int64_t id, nostd::string_view name) noexcept
  18. : id_{id}, name_{nostd::unique_ptr<char[]>{new char[name.length() + 1]}}
  19. {
  20. std::copy(name.begin(), name.end(), name_.get());
  21. name_.get()[name.length()] = 0;
  22. }
  23. EventId(int64_t id) noexcept : id_{id}, name_{nullptr} {}
  24. public:
  25. int64_t id_;
  26. nostd::unique_ptr<char[]> name_;
  27. };
  28. } // namespace logs
  29. OPENTELEMETRY_END_NAMESPACE