Skip to content

Commit d1a8976

Browse files
committed
feat(stdlib): only add logs as breadcrumbs if a span is active
1 parent 44e34d2 commit d1a8976

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/stdlib/src/logger.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ export function newLogger(options) {
129129

130130
return {
131131
info: (message) => {
132+
childLogger.info({ message });
133+
134+
if (!_compasSentryExport.getActiveSpan()) {
135+
// Don't add breadcrumbs if we don't have a span. This prevents unmatched logs from showing up in a random span.
136+
return;
137+
}
138+
132139
if (!addedContextAsBreadcrumb) {
133140
// @ts-expect-error
134141
_compasSentryExport.addBreadcrumb({
@@ -150,10 +157,15 @@ export function newLogger(options) {
150157
level: "info",
151158
type: "default",
152159
});
153-
154-
childLogger.info({ message });
155160
},
156161
error: (message) => {
162+
childLogger.error({ message });
163+
164+
if (!_compasSentryExport.getActiveSpan()) {
165+
// Don't add breadcrumbs if we don't have a span. This prevents unmatched logs from showing up in a random span.
166+
return;
167+
}
168+
157169
if (!addedContextAsBreadcrumb) {
158170
// @ts-expect-error
159171
_compasSentryExport.addBreadcrumb({
@@ -175,8 +187,6 @@ export function newLogger(options) {
175187
level: "error",
176188
type: "error",
177189
});
178-
179-
childLogger.error({ message });
180190
},
181191
};
182192
}

0 commit comments

Comments
 (0)