1+ import type { TypedAttributes } from '../attributes' ;
2+ import { attributeValueToTypedAttributeValue } from '../attributes' ;
13import { getGlobalSingleton } from '../carrier' ;
24import type { Client } from '../client' ;
35import { getClient , getCurrentScope , getGlobalScope , getIsolationScope } from '../currentScopes' ;
46import { DEBUG_BUILD } from '../debug-build' ;
57import type { Scope , ScopeData } from '../scope' ;
68import type { Integration } from '../types-hoist/integration' ;
7- import type { Log , SerializedLog , SerializedLogAttributeValue } from '../types-hoist/log' ;
9+ import type { Log , SerializedLog } from '../types-hoist/log' ;
810import { mergeScopeData } from '../utils/applyScopeDataToEvent' ;
911import { consoleSandbox , debug } from '../utils/debug-logger' ;
1012import { isParameterizedString } from '../utils/is' ;
@@ -16,51 +18,6 @@ import { createLogEnvelope } from './envelope';
1618
1719const MAX_LOG_BUFFER_SIZE = 100 ;
1820
19- /**
20- * Converts a log attribute to a serialized log attribute.
21- *
22- * @param key - The key of the log attribute.
23- * @param value - The value of the log attribute.
24- * @returns The serialized log attribute.
25- */
26- export function logAttributeToSerializedLogAttribute ( value : unknown ) : SerializedLogAttributeValue {
27- switch ( typeof value ) {
28- case 'number' :
29- if ( Number . isInteger ( value ) ) {
30- return {
31- value,
32- type : 'integer' ,
33- } ;
34- }
35- return {
36- value,
37- type : 'double' ,
38- } ;
39- case 'boolean' :
40- return {
41- value,
42- type : 'boolean' ,
43- } ;
44- case 'string' :
45- return {
46- value,
47- type : 'string' ,
48- } ;
49- default : {
50- let stringValue = '' ;
51- try {
52- stringValue = JSON . stringify ( value ) ?? '' ;
53- } catch {
54- // Do nothing
55- }
56- return {
57- value : stringValue ,
58- type : 'string' ,
59- } ;
60- }
61- }
62- }
63-
6421/**
6522 * Sets a log attribute if the value exists and the attribute key is not already present.
6623 *
@@ -141,6 +98,7 @@ export function _INTERNAL_captureLog(
14198
14299 const {
143100 user : { id, email, username } ,
101+ attributes : scopeAttributes ,
144102 } = getMergedScopeData ( currentScope ) ;
145103 setLogAttribute ( processedLogAttributes , 'user.id' , id , false ) ;
146104 setLogAttribute ( processedLogAttributes , 'user.email' , email , false ) ;
@@ -203,13 +161,13 @@ export function _INTERNAL_captureLog(
203161 body : message ,
204162 trace_id : traceContext ?. trace_id ,
205163 severity_number : severityNumber ?? SEVERITY_TEXT_TO_SEVERITY_NUMBER [ level ] ,
206- attributes : Object . keys ( attributes ) . reduce (
207- ( acc , key ) => {
208- acc [ key ] = logAttributeToSerializedLogAttribute ( attributes [ key ] ) ;
164+ attributes : {
165+ ...scopeAttributes ,
166+ ...Object . keys ( attributes ) . reduce ( ( acc , key ) => {
167+ acc [ key ] = attributeValueToTypedAttributeValue ( attributes [ key ] ) ;
209168 return acc ;
210- } ,
211- { } as Record < string , SerializedLogAttributeValue > ,
212- ) ,
169+ } , { } as TypedAttributes ) ,
170+ } ,
213171 } ;
214172
215173 captureSerializedLog ( client , serializedLog ) ;
0 commit comments