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 *
@@ -139,6 +96,7 @@ export function _INTERNAL_captureLog(
13996
14097 const {
14198 user : { id, email, username } ,
99+ attributes : scopeAttributes ,
142100 } = getMergedScopeData ( currentScope ) ;
143101 setLogAttribute ( processedLogAttributes , 'user.id' , id , false ) ;
144102 setLogAttribute ( processedLogAttributes , 'user.email' , email , false ) ;
@@ -201,13 +159,13 @@ export function _INTERNAL_captureLog(
201159 body : message ,
202160 trace_id : traceContext ?. trace_id ,
203161 severity_number : severityNumber ?? SEVERITY_TEXT_TO_SEVERITY_NUMBER [ level ] ,
204- attributes : Object . keys ( attributes ) . reduce (
205- ( acc , key ) => {
206- acc [ key ] = logAttributeToSerializedLogAttribute ( attributes [ key ] ) ;
162+ attributes : {
163+ ...scopeAttributes ,
164+ ...Object . keys ( attributes ) . reduce ( ( acc , key ) => {
165+ acc [ key ] = attributeValueToTypedAttributeValue ( attributes [ key ] ) ;
207166 return acc ;
208- } ,
209- { } as Record < string , SerializedLogAttributeValue > ,
210- ) ,
167+ } , { } as TypedAttributes ) ,
168+ } ,
211169 } ;
212170
213171 captureSerializedLog ( client , serializedLog ) ;
0 commit comments