-
Notifications
You must be signed in to change notification settings - Fork 533
Expand file tree
/
Copy pathread_write_log_record.cc
More file actions
213 lines (176 loc) · 5.28 KB
/
read_write_log_record.cc
File metadata and controls
213 lines (176 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#include <stdint.h>
#include <chrono>
#include <memory>
#include <string>
#include <unordered_map>
#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/logs/severity.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/variant.h"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/logs/read_write_log_record.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/trace_flags.h"
#include "opentelemetry/trace/trace_id.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace logs
{
ReadWriteLogRecord::ReadWriteLogRecord()
: severity_(opentelemetry::logs::Severity::kInvalid),
resource_(nullptr),
instrumentation_scope_(nullptr),
body_(std::string()),
observed_timestamp_(std::chrono::system_clock::now()),
event_id_(0),
event_name_("")
{}
ReadWriteLogRecord::~ReadWriteLogRecord() {}
void ReadWriteLogRecord::SetTimestamp(opentelemetry::common::SystemTimestamp timestamp) noexcept
{
timestamp_ = timestamp;
}
opentelemetry::common::SystemTimestamp ReadWriteLogRecord::GetTimestamp() const noexcept
{
return timestamp_;
}
void ReadWriteLogRecord::SetObservedTimestamp(
opentelemetry::common::SystemTimestamp timestamp) noexcept
{
observed_timestamp_ = timestamp;
}
opentelemetry::common::SystemTimestamp ReadWriteLogRecord::GetObservedTimestamp() const noexcept
{
return observed_timestamp_;
}
void ReadWriteLogRecord::SetSeverity(opentelemetry::logs::Severity severity) noexcept
{
severity_ = severity;
}
opentelemetry::logs::Severity ReadWriteLogRecord::GetSeverity() const noexcept
{
return severity_;
}
void ReadWriteLogRecord::SetBody(const opentelemetry::common::AttributeValue &message) noexcept
{
opentelemetry::sdk::common::AttributeConverter converter;
body_ = nostd::visit(converter, message);
}
const opentelemetry::sdk::common::OwnedAttributeValue &ReadWriteLogRecord::GetBody() const noexcept
{
return body_;
}
void ReadWriteLogRecord::SetEventId(int64_t id, nostd::string_view name) noexcept
{
event_id_ = id;
event_name_ = std::string{name};
}
int64_t ReadWriteLogRecord::GetEventId() const noexcept
{
return event_id_;
}
nostd::string_view ReadWriteLogRecord::GetEventName() const noexcept
{
return nostd::string_view{event_name_};
}
void ReadWriteLogRecord::SetTraceId(const opentelemetry::trace::TraceId &trace_id) noexcept
{
if (!trace_state_)
{
trace_state_ = std::unique_ptr<TraceState>(new TraceState());
}
trace_state_->trace_id = trace_id;
}
const opentelemetry::trace::TraceId &ReadWriteLogRecord::GetTraceId() const noexcept
{
if (trace_state_)
{
return trace_state_->trace_id;
}
static opentelemetry::trace::TraceId empty;
return empty;
}
void ReadWriteLogRecord::SetSpanId(const opentelemetry::trace::SpanId &span_id) noexcept
{
if (!trace_state_)
{
trace_state_ = std::unique_ptr<TraceState>(new TraceState());
}
trace_state_->span_id = span_id;
}
const opentelemetry::trace::SpanId &ReadWriteLogRecord::GetSpanId() const noexcept
{
if (trace_state_)
{
return trace_state_->span_id;
}
static opentelemetry::trace::SpanId empty;
return empty;
}
void ReadWriteLogRecord::SetTraceFlags(const opentelemetry::trace::TraceFlags &trace_flags) noexcept
{
if (!trace_state_)
{
trace_state_ = std::unique_ptr<TraceState>(new TraceState());
}
trace_state_->trace_flags = trace_flags;
}
const opentelemetry::trace::TraceFlags &ReadWriteLogRecord::GetTraceFlags() const noexcept
{
if (trace_state_)
{
return trace_state_->trace_flags;
}
static opentelemetry::trace::TraceFlags empty;
return empty;
}
void ReadWriteLogRecord::SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &value) noexcept
{
std::string safe_key(key);
opentelemetry::sdk::common::AttributeConverter converter;
attributes_map_[safe_key] = nostd::visit(converter, value);
}
const std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue> &
ReadWriteLogRecord::GetAttributes() const noexcept
{
return attributes_map_;
}
const opentelemetry::sdk::resource::Resource &ReadWriteLogRecord::GetResource() const noexcept
{
if OPENTELEMETRY_LIKELY_CONDITION (nullptr != resource_)
{
return *resource_;
}
return GetDefaultResource();
}
void ReadWriteLogRecord::SetResource(
const opentelemetry::sdk::resource::Resource &resource) noexcept
{
resource_ = &resource;
}
const opentelemetry::sdk::instrumentationscope::InstrumentationScope &
ReadWriteLogRecord::GetInstrumentationScope() const noexcept
{
if OPENTELEMETRY_LIKELY_CONDITION (nullptr != instrumentation_scope_)
{
return *instrumentation_scope_;
}
return GetDefaultInstrumentationScope();
}
void ReadWriteLogRecord::SetInstrumentationScope(
const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept
{
instrumentation_scope_ = &instrumentation_scope;
}
} // namespace logs
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE