Skip to content

Commit 52339f2

Browse files
committed
adjust after scope attribute changes
1 parent a458fe7 commit 52339f2

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
@@ -2,7 +2,7 @@ export type RawAttributes<T> = T & ValidatedAttributes<T>;
22
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33
export type RawAttribute<T> = T extends { value: any } | { unit: any } ? AttributeWithUnit : T;
44

5-
export type Attributes = Record<string, TypedAttributeValue>;
5+
export type TypedAttributes = Record<string, TypedAttributeValue>;
66

77
export type AttributeValueType = string | number | boolean | Array<string> | Array<number> | Array<boolean>;
88

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';
@@ -139,7 +139,7 @@ export function _INTERNAL_captureLog(
139139
// Add the parent span ID to the log attributes for trace context
140140
setLogAttribute(processedLogAttributes, 'sentry.trace.parent_span_id', span?.spanContext().spanId);
141141

142-
const processedLog = { ...beforeLog, attributes: processedLogAttributes };
142+
const processedLog = { ...beforeLog, attributes: { ...scopeAttributes, ...processedLogAttributes } };
143143

144144
client.emit('beforeCaptureLog', processedLog);
145145

@@ -159,14 +159,13 @@ export function _INTERNAL_captureLog(
159159
body: message,
160160
trace_id: traceContext?.trace_id,
161161
severity_number: severityNumber ?? SEVERITY_TEXT_TO_SEVERITY_NUMBER[level],
162-
attributes: {
163-
// TODO: This is too late to apply scope attributes because we already invoked beforeSendLog earlier.
164-
...scopeAttributes,
165-
...Object.keys(attributes).reduce((acc, key) => {
162+
attributes: Object.keys(attributes).reduce(
163+
(acc, key) => {
166164
acc[key] = attributeValueToTypedAttributeValue(attributes[key]);
167165
return acc;
168-
}, {} as TypedAttributes),
169-
},
166+
},
167+
{} as Record<string, TypedAttributeValue>,
168+
),
170169
};
171170

172171
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',
@@ -315,7 +315,7 @@ describe('_INTERNAL_captureLog', () => {
315315
scope.setClient(client);
316316

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

320320
_INTERNAL_captureLog(
321321
{
@@ -331,9 +331,9 @@ describe('_INTERNAL_captureLog', () => {
331331
message: 'original message',
332332
attributes: {
333333
original: true,
334-
// scope attributes should already be applied prior to beforeSendLog
334+
// attributes here still have the same form as originally set on the scope or log
335335
scope_1: 'attribute_value',
336-
scope_2: { value: 143.5, type: 'double', unit: 'bytes' },
336+
scope_2: { value: 38, unit: 'gigabytes' },
337337
},
338338
});
339339

@@ -351,6 +351,16 @@ describe('_INTERNAL_captureLog', () => {
351351
value: true,
352352
type: 'boolean',
353353
},
354+
// during serialization, they're converted to the typed attribute format
355+
scope_1: {
356+
value: 'attribute_value',
357+
type: 'string',
358+
},
359+
scope_2: {
360+
value: 38,
361+
unit: 'gigabytes',
362+
type: 'integer',
363+
},
354364
},
355365
}),
356366
);

0 commit comments

Comments
 (0)