Skip to content

Commit 75bff04

Browse files
committed
use Object.fromEntries instead of reduce
1 parent 11bccd6 commit 75bff04

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

packages/core/src/logs/internal.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,30 +155,25 @@ export function _INTERNAL_captureLog(
155155

156156
const { level, message, attributes: logAttributes = {}, severityNumber } = log;
157157

158+
const serializedScopeAttributes = Object.fromEntries(
159+
Object.entries(scopeAttributes)
160+
.map(([key, value]) => [key, attributeValueToTypedAttributeValue(value)])
161+
.filter(([_, value]) => value != null),
162+
);
163+
164+
const serializedLogAttributes = Object.fromEntries(
165+
Object.entries(logAttributes).map(([key, value]) => [key, attributeValueToTypedAttributeValue(value, true)]),
166+
);
167+
158168
const serializedLog: SerializedLog = {
159169
timestamp: timestampInSeconds(),
160170
level,
161171
body: message,
162172
trace_id: traceContext?.trace_id,
163173
severity_number: severityNumber ?? SEVERITY_TEXT_TO_SEVERITY_NUMBER[level],
164174
attributes: {
165-
...Object.keys(scopeAttributes).reduce(
166-
(acc, key) => {
167-
const attributeValue = attributeValueToTypedAttributeValue(scopeAttributes[key]);
168-
if (attributeValue) {
169-
acc[key] = attributeValue;
170-
}
171-
return acc;
172-
},
173-
{} as Record<string, TypedAttributeValue>,
174-
),
175-
...Object.keys(logAttributes).reduce(
176-
(acc, key) => {
177-
acc[key] = attributeValueToTypedAttributeValue(logAttributes[key], true);
178-
return acc;
179-
},
180-
{} as Record<string, TypedAttributeValue>,
181-
),
175+
...serializedScopeAttributes,
176+
...serializedLogAttributes,
182177
},
183178
};
184179

0 commit comments

Comments
 (0)