1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 #ifdef ENABLE_LOGS_PREVIEW
8 # include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"
10 # include "opentelemetry/proto/logs/v1/logs.pb.h"
11 # include "opentelemetry/proto/resource/v1/resource.pb.h"
12 # include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h"
14 # include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
17 # include "opentelemetry/sdk/common/attribute_utils.h"
18 # include "opentelemetry/sdk/logs/recordable.h"
20 OPENTELEMETRY_BEGIN_NAMESPACE
27 * An OTLP Recordable implemenation for Logs.
29 class OtlpLogRecordable final
: public opentelemetry::sdk::logs::Recordable
32 virtual ~OtlpLogRecordable() = default;
34 proto::logs::v1::LogRecord
&log_record() noexcept
{ return log_record_
; }
35 const proto::logs::v1::LogRecord
&log_record() const noexcept
{ return log_record_
; }
37 /** Dynamically converts the resource of this log into a proto. */
38 proto::resource::v1::Resource
ProtoResource() const noexcept
;
41 * Set the timestamp for this log.
42 * @param timestamp the timestamp to set
44 void SetTimestamp(opentelemetry::common::SystemTimestamp timestamp
) noexcept override
;
47 * Set the severity for this log.
48 * @param severity the severity of the event
50 void SetSeverity(opentelemetry::logs::Severity severity
) noexcept override
;
53 * Set body field for this log.
54 * @param message the body to set
56 void SetBody(nostd::string_view message
) noexcept override
;
59 * Set Resource of this log
60 * @param Resource the resource to set
62 void SetResource(const opentelemetry::sdk::resource::Resource
&resource
) noexcept override
;
64 /** Returns the associated resource */
65 const opentelemetry::sdk::resource::Resource
&GetResource() const noexcept
;
68 * Set an attribute of a log.
69 * @param key the name of the attribute
70 * @param value the attribute value
72 void SetAttribute(nostd::string_view key
,
73 const opentelemetry::common::AttributeValue
&value
) noexcept override
;
76 * Set the trace id for this log.
77 * @param trace_id the trace id to set
79 void SetTraceId(opentelemetry::trace::TraceId trace_id
) noexcept override
;
82 * Set the span id for this log.
83 * @param span_id the span id to set
85 void SetSpanId(opentelemetry::trace::SpanId span_id
) noexcept override
;
88 * Inject trace_flags for this log.
89 * @param trace_flags the trace flags to set
91 void SetTraceFlags(opentelemetry::trace::TraceFlags trace_flags
) noexcept override
;
94 * Set instrumentation_library for this log.
95 * @param instrumentation_library the instrumentation library to set
97 void SetInstrumentationLibrary(
98 const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
99 &instrumentation_library
) noexcept override
;
101 /** Returns the associated instruementation library */
102 const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&
103 GetInstrumentationLibrary() const noexcept
;
106 proto::logs::v1::LogRecord log_record_
;
107 const opentelemetry::sdk::resource::Resource
*resource_
= nullptr;
108 // TODO shared resource
109 // const opentelemetry::sdk::resource::Resource *resource_ = nullptr;
110 const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
111 *instrumentation_library_
= nullptr;
115 } // namespace exporter
116 OPENTELEMETRY_END_NAMESPACE