From 05126835998cb443b6d47994bf213c63ee5517f2 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 22 Nov 2024 13:12:33 +0100 Subject: [PATCH 1/5] log warnings when returning null in beforeSendSpan --- packages/core/src/baseclient.ts | 2 ++ packages/core/src/envelope.ts | 10 ++++++++-- packages/core/src/utils/spanUtils.ts | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index 840992c4ea79..2387523d46ee 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -52,6 +52,7 @@ import { dropUndefinedKeys } from './utils-hoist/object'; import { SyncPromise, rejectedSyncPromise, resolvedSyncPromise } from './utils-hoist/syncpromise'; import { parseSampleRate } from './utils/parseSampleRate'; import { prepareEvent } from './utils/prepareEvent'; +import { showSpanDropWarning } from './utils/spanUtils'; const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured."; @@ -977,6 +978,7 @@ function processBeforeSend( if (processedSpan) { processedSpans.push(processedSpan); } else { + showSpanDropWarning(); client.recordDroppedEvent('before_send', 'span'); } } diff --git a/packages/core/src/envelope.ts b/packages/core/src/envelope.ts index ddeb2ce21997..8ecdeb0d604f 100644 --- a/packages/core/src/envelope.ts +++ b/packages/core/src/envelope.ts @@ -24,7 +24,7 @@ import { createSpanEnvelopeItem, getSdkMetadataForEnvelopeHeader, } from './utils-hoist/envelope'; -import { spanToJSON } from './utils/spanUtils'; +import { showSpanDropWarning, spanToJSON } from './utils/spanUtils'; /** * Apply SdkInfo (name, version, packages, integrations) to the corresponding event key. @@ -122,7 +122,13 @@ export function createSpanEnvelope(spans: [SentrySpan, ...SentrySpan[]], client? const beforeSendSpan = client && client.getOptions().beforeSendSpan; const convertToSpanJSON = beforeSendSpan - ? (span: SentrySpan) => beforeSendSpan(spanToJSON(span) as SpanJSON) + ? (span: SentrySpan) => { + const spanJson = beforeSendSpan(spanToJSON(span) as SpanJSON); + if (!spanJson) { + showSpanDropWarning(); + } + return spanJson; + } : (span: SentrySpan) => spanToJSON(span); const items: SpanItem[] = []; diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index 5f0c443919a3..5f6752f07ec4 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -21,11 +21,18 @@ import { addNonEnumerableProperty, dropUndefinedKeys } from '../utils-hoist/obje import { timestampInSeconds } from '../utils-hoist/time'; import { generateSentryTraceHeader } from '../utils-hoist/tracing'; import { _getSpanForScope } from './spanOnScope'; +import { logger } from '../utils-hoist/logger'; +import { DEBUG_BUILD } from '../debug-build'; // These are aligned with OpenTelemetry trace flags export const TRACE_FLAG_NONE = 0x0; export const TRACE_FLAG_SAMPLED = 0x1; +// todo(v9): Remove this once we've stopped dropping spans via `beforeSendSpan` +const SPAN_DROP_WARNING = + 'Dropping spans via `beforeSendSpan` will be removed in SDK v9.0.0. The callback will only support modifying span attributes.'; +let hasShownSpanDropWarning = false; + /** * Convert a span to a trace context, which can be sent as the `trace` context in an event. * By default, this will only include trace_id, span_id & parent_span_id. @@ -280,3 +287,15 @@ export function updateMetricSummaryOnActiveSpan( updateMetricSummaryOnSpan(span, metricType, sanitizedName, value, unit, tags, bucketKey); } } + +/** + * Logs a warning once if `beforeSendSpan` is used to drop spans. + * + * todo(v9): Remove this once we've stopped dropping spans via `beforeSendSpan`. + */ +export function showSpanDropWarning(): void { + if (DEBUG_BUILD && !hasShownSpanDropWarning) { + logger.warn(SPAN_DROP_WARNING); + hasShownSpanDropWarning = true; + } +} From acf9a43726305e80c340aeffabdaa7670af01ac5 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 22 Nov 2024 13:18:02 +0100 Subject: [PATCH 2/5] biome --- packages/core/src/utils/spanUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index 5f6752f07ec4..cf6471bfa861 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -12,17 +12,17 @@ import type { import { getAsyncContextStrategy } from '../asyncContext'; import { getMainCarrier } from '../carrier'; import { getCurrentScope } from '../currentScopes'; +import { DEBUG_BUILD } from '../debug-build'; import { getMetricSummaryJsonForSpan, updateMetricSummaryOnSpan } from '../metrics/metric-summary'; import type { MetricType } from '../metrics/types'; import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes'; import type { SentrySpan } from '../tracing/sentrySpan'; import { SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus'; +import { logger } from '../utils-hoist/logger'; import { addNonEnumerableProperty, dropUndefinedKeys } from '../utils-hoist/object'; import { timestampInSeconds } from '../utils-hoist/time'; import { generateSentryTraceHeader } from '../utils-hoist/tracing'; import { _getSpanForScope } from './spanOnScope'; -import { logger } from '../utils-hoist/logger'; -import { DEBUG_BUILD } from '../debug-build'; // These are aligned with OpenTelemetry trace flags export const TRACE_FLAG_NONE = 0x0; From 16a04969a9eceab3a76b99070624e720ad957bfb Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 22 Nov 2024 14:15:36 +0100 Subject: [PATCH 3/5] log in non debug mode --- packages/core/src/utils/spanUtils.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index cf6471bfa861..cad0eb7a05b9 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -12,13 +12,12 @@ import type { import { getAsyncContextStrategy } from '../asyncContext'; import { getMainCarrier } from '../carrier'; import { getCurrentScope } from '../currentScopes'; -import { DEBUG_BUILD } from '../debug-build'; import { getMetricSummaryJsonForSpan, updateMetricSummaryOnSpan } from '../metrics/metric-summary'; import type { MetricType } from '../metrics/types'; import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes'; import type { SentrySpan } from '../tracing/sentrySpan'; import { SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus'; -import { logger } from '../utils-hoist/logger'; +import { consoleSandbox } from '../utils-hoist/logger'; import { addNonEnumerableProperty, dropUndefinedKeys } from '../utils-hoist/object'; import { timestampInSeconds } from '../utils-hoist/time'; import { generateSentryTraceHeader } from '../utils-hoist/tracing'; @@ -29,8 +28,6 @@ export const TRACE_FLAG_NONE = 0x0; export const TRACE_FLAG_SAMPLED = 0x1; // todo(v9): Remove this once we've stopped dropping spans via `beforeSendSpan` -const SPAN_DROP_WARNING = - 'Dropping spans via `beforeSendSpan` will be removed in SDK v9.0.0. The callback will only support modifying span attributes.'; let hasShownSpanDropWarning = false; /** @@ -294,8 +291,13 @@ export function updateMetricSummaryOnActiveSpan( * todo(v9): Remove this once we've stopped dropping spans via `beforeSendSpan`. */ export function showSpanDropWarning(): void { - if (DEBUG_BUILD && !hasShownSpanDropWarning) { - logger.warn(SPAN_DROP_WARNING); + if (!hasShownSpanDropWarning) { + consoleSandbox(() => { + // eslint-disable-next-line no-console + console.warn( + '[Sentry] Dropping spans via `beforeSendSpan` will be removed in SDK v9.0.0. The callback will only support modifying span attributes.', + ); + }); hasShownSpanDropWarning = true; } } From 9a368765bbe99811f2515841fea598182c5bf8e4 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 22 Nov 2024 14:49:09 +0100 Subject: [PATCH 4/5] Update packages/core/src/utils/spanUtils.ts Co-authored-by: Luca Forstner --- packages/core/src/utils/spanUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index cad0eb7a05b9..d9232b1f48bc 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -295,7 +295,7 @@ export function showSpanDropWarning(): void { consoleSandbox(() => { // eslint-disable-next-line no-console console.warn( - '[Sentry] Dropping spans via `beforeSendSpan` will be removed in SDK v9.0.0. The callback will only support modifying span attributes.', + '[Sentry] Deprecation warning: Returning null from `beforeSendSpan` will be disallowed from SDK version 9.0.0 onwards. The callback will only support mutating spans. To drop certain spans, configure the respective integrations directly.', ); }); hasShownSpanDropWarning = true; From b008762606360ec8c5eeb3044628383ac10814e2 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 22 Nov 2024 16:01:10 +0100 Subject: [PATCH 5/5] bump size limit --- .size-limit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.size-limit.js b/.size-limit.js index b28892aecb89..e97e15f6cd4e 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -187,7 +187,7 @@ module.exports = [ path: createCDNPath('bundle.tracing.min.js'), gzip: false, brotli: false, - limit: '113 KB', + limit: '120 KB', }, { name: 'CDN Bundle (incl. Tracing, Replay) - uncompressed',