-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathExtendedSdkReadWriteLogRecord.java
More file actions
166 lines (151 loc) · 4.83 KB
/
Copy pathExtendedSdkReadWriteLogRecord.java
File metadata and controls
166 lines (151 loc) · 4.83 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
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.sdk.logs;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Value;
import io.opentelemetry.api.incubator.common.ExtendedAttributeKey;
import io.opentelemetry.api.incubator.common.ExtendedAttributes;
import io.opentelemetry.api.internal.GuardedBy;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.internal.ExtendedAttributesMap;
import io.opentelemetry.sdk.logs.data.internal.ExtendedLogRecordData;
import io.opentelemetry.sdk.logs.internal.ExtendedReadWriteLogRecord;
import io.opentelemetry.sdk.resources.Resource;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe
class ExtendedSdkReadWriteLogRecord extends SdkReadWriteLogRecord
implements ExtendedReadWriteLogRecord {
private final Object lock = new Object();
@GuardedBy("lock")
@Nullable
private ExtendedAttributesMap extendedAttributes;
@SuppressWarnings("unused")
private ExtendedSdkReadWriteLogRecord(
LogLimits logLimits,
Resource resource,
InstrumentationScopeInfo instrumentationScopeInfo,
@Nullable String eventName,
long timestampEpochNanos,
long observedTimestampEpochNanos,
SpanContext spanContext,
Severity severity,
@Nullable String severityText,
@Nullable Value<?> body,
@Nullable ExtendedAttributesMap extendedAttributes) {
super(
logLimits,
resource,
instrumentationScopeInfo,
timestampEpochNanos,
observedTimestampEpochNanos,
spanContext,
severity,
severityText,
body,
null,
eventName);
this.extendedAttributes = extendedAttributes;
}
/** Create the extended log record with the given configuration. */
static ExtendedSdkReadWriteLogRecord create(
LogLimits logLimits,
Resource resource,
InstrumentationScopeInfo instrumentationScopeInfo,
@Nullable String eventName,
long timestampEpochNanos,
long observedTimestampEpochNanos,
SpanContext spanContext,
Severity severity,
@Nullable String severityText,
@Nullable Value<?> body,
@Nullable ExtendedAttributesMap extendedAttributes) {
return new ExtendedSdkReadWriteLogRecord(
logLimits,
resource,
instrumentationScopeInfo,
eventName,
timestampEpochNanos,
observedTimestampEpochNanos,
spanContext,
severity,
severityText,
body,
extendedAttributes);
}
@Override
public <T> ExtendedSdkReadWriteLogRecord setAttribute(AttributeKey<T> key, T value) {
if (key == null || key.getKey().isEmpty() || value == null) {
return this;
}
return setAttribute(ExtendedAttributeKey.fromAttributeKey(key), value);
}
@Override
public <T> ExtendedSdkReadWriteLogRecord setAttribute(ExtendedAttributeKey<T> key, T value) {
if (key == null || key.getKey().isEmpty() || value == null) {
return this;
}
synchronized (lock) {
if (extendedAttributes == null) {
extendedAttributes =
ExtendedAttributesMap.create(
logLimits.getMaxNumberOfAttributes(), logLimits.getMaxAttributeValueLength());
}
extendedAttributes.put(key, value);
}
return this;
}
private ExtendedAttributes getImmutableExtendedAttributes() {
synchronized (lock) {
if (extendedAttributes == null) {
return ExtendedAttributes.empty();
}
return extendedAttributes.immutableCopy();
}
}
@Override
public ExtendedLogRecordData toLogRecordData() {
synchronized (lock) {
return ExtendedSdkLogRecordData.create(
resource,
instrumentationScopeInfo,
eventName,
timestampEpochNanos,
observedTimestampEpochNanos,
spanContext,
severity,
severityText,
body,
getImmutableExtendedAttributes(),
extendedAttributes == null ? 0 : extendedAttributes.getTotalAddedValues());
}
}
@Override
public Attributes getAttributes() {
return getExtendedAttributes().asAttributes();
}
@Nullable
@Override
public <T> T getAttribute(AttributeKey<T> key) {
return getAttribute(ExtendedAttributeKey.fromAttributeKey(key));
}
@Nullable
@Override
public <T> T getAttribute(ExtendedAttributeKey<T> key) {
synchronized (lock) {
if (extendedAttributes == null || extendedAttributes.isEmpty()) {
return null;
}
return extendedAttributes.get(key);
}
}
@Override
public ExtendedAttributes getExtendedAttributes() {
return getImmutableExtendedAttributes();
}
}