log_record.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/timestamp.h"
  6. #include "opentelemetry/version.h"
  7. OPENTELEMETRY_BEGIN_NAMESPACE
  8. namespace trace
  9. {
  10. class SpanId;
  11. class TraceId;
  12. class TraceFlags;
  13. } // namespace trace
  14. namespace logs
  15. {
  16. enum class Severity : uint8_t;
  17. /**
  18. * Maintains a representation of a log in a format that can be processed by a recorder.
  19. *
  20. * This class is thread-compatible.
  21. */
  22. class LogRecord
  23. {
  24. public:
  25. virtual ~LogRecord() = default;
  26. /**
  27. * Set the timestamp for this log.
  28. * @param timestamp the timestamp to set
  29. */
  30. virtual void SetTimestamp(common::SystemTimestamp timestamp) noexcept = 0;
  31. /**
  32. * Set the observed timestamp for this log.
  33. * @param timestamp the timestamp to set
  34. */
  35. virtual void SetObservedTimestamp(common::SystemTimestamp timestamp) noexcept = 0;
  36. /**
  37. * Set the severity for this log.
  38. * @param severity the severity of the event
  39. */
  40. virtual void SetSeverity(logs::Severity severity) noexcept = 0;
  41. /**
  42. * Set body field for this log.
  43. * @param message the body to set
  44. */
  45. virtual void SetBody(const common::AttributeValue &message) noexcept = 0;
  46. /**
  47. * Set an attribute of a log.
  48. * @param key the name of the attribute
  49. * @param value the attribute value
  50. */
  51. virtual void SetAttribute(nostd::string_view key,
  52. const common::AttributeValue &value) noexcept = 0;
  53. /**
  54. * Set the Event Id.
  55. * @param id The event id to set
  56. * @param name Optional event name to set
  57. */
  58. // TODO: mark this as pure virtual once all exporters have been updated
  59. virtual void SetEventId(int64_t id, nostd::string_view name = {}) noexcept = 0;
  60. /**
  61. * Set the trace id for this log.
  62. * @param trace_id the trace id to set
  63. */
  64. virtual void SetTraceId(const trace::TraceId &trace_id) noexcept = 0;
  65. /**
  66. * Set the span id for this log.
  67. * @param span_id the span id to set
  68. */
  69. virtual void SetSpanId(const trace::SpanId &span_id) noexcept = 0;
  70. /**
  71. * Inject trace_flags for this log.
  72. * @param trace_flags the trace flags to set
  73. */
  74. virtual void SetTraceFlags(const trace::TraceFlags &trace_flags) noexcept = 0;
  75. };
  76. } // namespace logs
  77. OPENTELEMETRY_END_NAMESPACE