Skip to content

Commit adf801f

Browse files
committed
fix(node): Always use custom scope when calling Sentry.logger.*
1 parent ebb8eed commit adf801f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/node-core/src/logs/capture.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export type CaptureLogArgs = CaptureLogArgWithTemplate | CaptureLogArgWithoutTem
3434
export function captureLog(level: LogSeverityLevel, ...args: CaptureLogArgs): void {
3535
const [messageOrMessageTemplate, paramsOrAttributes, maybeAttributesOrMetadata, maybeMetadata] = args;
3636
if (Array.isArray(paramsOrAttributes)) {
37-
const attributes = { ...(maybeAttributesOrMetadata as Log['attributes']) };
37+
// type-casting here because from the type definitions we know that `maybeAttributesOrMetadata` is an attributes object (or undefined)
38+
const attributes = { ...(maybeAttributesOrMetadata as Log['attributes'] | undefined) };
3839
attributes['sentry.message.template'] = messageOrMessageTemplate;
3940
paramsOrAttributes.forEach((param, index) => {
4041
attributes[`sentry.message.parameter.${index}`] = param;
@@ -44,7 +45,8 @@ export function captureLog(level: LogSeverityLevel, ...args: CaptureLogArgs): vo
4445
} else {
4546
_INTERNAL_captureLog(
4647
{ level, message: messageOrMessageTemplate, attributes: paramsOrAttributes },
47-
maybeMetadata?.scope,
48+
// type-casting here because from the type definitions we know that `maybeAttributesOrMetadata` is a metadata object (or undefined)
49+
(maybeAttributesOrMetadata as CaptureLogMetadata | undefined)?.scope ?? maybeMetadata?.scope,
4850
);
4951
}
5052
}

0 commit comments

Comments
 (0)