Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.";

Expand Down Expand Up @@ -977,6 +978,7 @@ function processBeforeSend(
if (processedSpan) {
processedSpans.push(processedSpan);
} else {
showSpanDropWarning();
client.recordDroppedEvent('before_send', 'span');
}
}
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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[] = [];
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/utils/spanUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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 { consoleSandbox } from '../utils-hoist/logger';
import { addNonEnumerableProperty, dropUndefinedKeys } from '../utils-hoist/object';
import { timestampInSeconds } from '../utils-hoist/time';
import { generateSentryTraceHeader } from '../utils-hoist/tracing';
Expand All @@ -26,6 +27,9 @@ import { _getSpanForScope } from './spanOnScope';
export const TRACE_FLAG_NONE = 0x0;
export const TRACE_FLAG_SAMPLED = 0x1;

// todo(v9): Remove this once we've stopped dropping spans via `beforeSendSpan`
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.
Expand Down Expand Up @@ -280,3 +284,20 @@ 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 (!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;
}
}
Loading