Skip to content

Commit 6d0c6bd

Browse files
committed
adjust after scope attribute changes
1 parent fd10893 commit 6d0c6bd

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
166166
'sentry.message.template': { value: 'Mixed: {} {} {} {}', type: 'string' },
167167
'sentry.message.parameter.0': { value: 'prefix', type: 'string' },
168168
'sentry.message.parameter.1': { value: '{"obj":true}', type: 'string' },
169-
'sentry.message.parameter.2': { value: '[4,5,6]', type: 'string' },
169+
'sentry.message.parameter.2': { value: [4, 5, 6], type: 'integer[]' },
170170
'sentry.message.parameter.3': { value: 'suffix', type: 'string' },
171171
},
172172
},
@@ -235,7 +235,7 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
235235
'sentry.message.template': { value: 'hello {} {} {}', type: 'string' },
236236
'sentry.message.parameter.0': { value: true, type: 'boolean' },
237237
'sentry.message.parameter.1': { value: 'null', type: 'string' },
238-
'sentry.message.parameter.2': { value: '', type: 'string' },
238+
'sentry.message.parameter.2': { value: 'undefined', type: 'string' },
239239
},
240240
},
241241
],

packages/core/src/attributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type RawAttributes<T> = T & ValidatedAttributes<T>;
66
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77
export type RawAttribute<T> = T extends { value: any } | { unit: any } ? AttributeObject : T;
88

9-
export type Attributes = Record<string, TypedAttributeValue>;
9+
export type TypedAttributes = Record<string, TypedAttributeValue>;
1010

1111
export type AttributeValueType = string | number | boolean | Array<string> | Array<number> | Array<boolean>;
1212

packages/core/src/logs/internal.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TypedAttributes } from '../attributes';
1+
import type { TypedAttributeValue } from '../attributes';
22
import { attributeValueToTypedAttributeValue } from '../attributes';
33
import { getGlobalSingleton } from '../carrier';
44
import type { Client } from '../client';
@@ -141,7 +141,7 @@ export function _INTERNAL_captureLog(
141141
// Add the parent span ID to the log attributes for trace context
142142
setLogAttribute(processedLogAttributes, 'sentry.trace.parent_span_id', span?.spanContext().spanId);
143143

144-
const processedLog = { ...beforeLog, attributes: processedLogAttributes };
144+
const processedLog = { ...beforeLog, attributes: { ...scopeAttributes, ...processedLogAttributes } };
145145

146146
client.emit('beforeCaptureLog', processedLog);
147147

@@ -161,14 +161,13 @@ export function _INTERNAL_captureLog(
161161
body: message,
162162
trace_id: traceContext?.trace_id,
163163
severity_number: severityNumber ?? SEVERITY_TEXT_TO_SEVERITY_NUMBER[level],
164-
attributes: {
165-
// TODO: This is too late to apply scope attributes because we already invoked beforeSendLog earlier.
166-
...scopeAttributes,
167-
...Object.keys(attributes).reduce((acc, key) => {
164+
attributes: Object.keys(attributes).reduce(
165+
(acc, key) => {
168166
acc[key] = attributeValueToTypedAttributeValue(attributes[key]);
169167
return acc;
170-
}, {} as TypedAttributes),
171-
},
168+
},
169+
{} as Record<string, TypedAttributeValue>,
170+
),
172171
};
173172

174173
captureSerializedLog(client, serializedLog);

packages/core/test/lib/logs/internal.test.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ describe('_INTERNAL_captureLog', () => {
178178
scope.setClient(client);
179179

180180
scope.setAttribute('scope_1', 'attribute_value');
181-
scope.setAttribute('scope_2', { value: 143.5, type: 'double', unit: 'bytes' });
181+
scope.setAttribute('scope_2', { value: 38, unit: 'gigabytes' });
182182
scope.setAttributes({
183183
scope_3: true,
184184
scope_4: [1, 2, 3],
185-
scope_5: { value: [true, false, true], type: 'boolean[]', unit: 's' },
185+
scope_5: { value: [true, false, true], unit: 's' },
186186
});
187187

188188
_INTERNAL_captureLog(
@@ -210,9 +210,9 @@ describe('_INTERNAL_captureLog', () => {
210210
value: 'attribute_value',
211211
},
212212
scope_2: {
213-
type: 'double',
214-
unit: 'bytes',
215-
value: 143.5,
213+
type: 'integer',
214+
unit: 'gigabytes',
215+
value: 38,
216216
},
217217
scope_3: {
218218
type: 'boolean',
@@ -318,7 +318,7 @@ describe('_INTERNAL_captureLog', () => {
318318
scope.setClient(client);
319319

320320
scope.setAttribute('scope_1', 'attribute_value');
321-
scope.setAttribute('scope_2', { value: 143.5, type: 'double', unit: 'bytes' });
321+
scope.setAttribute('scope_2', { value: 38, unit: 'gigabytes' });
322322

323323
_INTERNAL_captureLog(
324324
{
@@ -334,9 +334,9 @@ describe('_INTERNAL_captureLog', () => {
334334
message: 'original message',
335335
attributes: {
336336
original: true,
337-
// scope attributes should already be applied prior to beforeSendLog
337+
// attributes here still have the same form as originally set on the scope or log
338338
scope_1: 'attribute_value',
339-
scope_2: { value: 143.5, type: 'double', unit: 'bytes' },
339+
scope_2: { value: 38, unit: 'gigabytes' },
340340
},
341341
});
342342

@@ -354,6 +354,16 @@ describe('_INTERNAL_captureLog', () => {
354354
value: true,
355355
type: 'boolean',
356356
},
357+
// during serialization, they're converted to the typed attribute format
358+
scope_1: {
359+
value: 'attribute_value',
360+
type: 'string',
361+
},
362+
scope_2: {
363+
value: 38,
364+
unit: 'gigabytes',
365+
type: 'integer',
366+
},
357367
},
358368
}),
359369
);

0 commit comments

Comments
 (0)