Skip to content

Commit 3ca7f7d

Browse files
committed
avoid weak map & fix minification
1 parent f6442a5 commit 3ca7f7d

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

dev-packages/rollup-utils/plugins/bundlePlugins.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ export function makeTerserPlugin() {
121121
// These are used by instrument.ts in utils for identifying HTML elements & events
122122
'_sentryCaptured',
123123
'_sentryId',
124+
// Keeps the frozen DSC on a Sentry Span
124125
'_frozenDsc',
126+
// This keeps metrics summary on spans
127+
'_metrics_summary',
125128
// These are used to keep span & scope relationships
126129
'_sentryRootSpan',
127130
'_sentryChildSpans',

packages/core/src/metrics/metric-summary.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import type { MetricType } from './types';
1010
*/
1111
type MetricSummaryStorage = Map<string, [string, MetricSummary]>;
1212

13-
let SPAN_METRIC_SUMMARY: WeakMap<Span, MetricSummaryStorage> | undefined;
13+
const METRICS_SPAN_FIELD = '_sentryMetrics';
1414

15-
function getMetricStorageForSpan(span: Span): MetricSummaryStorage | undefined {
16-
return SPAN_METRIC_SUMMARY ? SPAN_METRIC_SUMMARY.get(span) : undefined;
17-
}
15+
type SpanWithPotentialMetrics = Span & {
16+
[METRICS_SPAN_FIELD]?: MetricSummaryStorage;
17+
};
1818

1919
/**
2020
* Fetches the metric summary if it exists for the passed span
2121
*/
2222
export function getMetricSummaryJsonForSpan(span: Span): Record<string, Array<MetricSummary>> | undefined {
23-
const storage = getMetricStorageForSpan(span);
23+
const storage = (span as SpanWithPotentialMetrics)[METRICS_SPAN_FIELD];
2424

2525
if (!storage) {
2626
return undefined;
@@ -50,7 +50,10 @@ export function updateMetricSummaryOnSpan(
5050
tags: Record<string, Primitive>,
5151
bucketKey: string,
5252
): void {
53-
const storage = getMetricStorageForSpan(span) || new Map<string, [string, MetricSummary]>();
53+
const existingStorage = (span as SpanWithPotentialMetrics)[METRICS_SPAN_FIELD];
54+
const storage =
55+
existingStorage ||
56+
((span as SpanWithPotentialMetrics)[METRICS_SPAN_FIELD] = new Map<string, [string, MetricSummary]>());
5457

5558
const exportKey = `${metricType}:${sanitizedName}@${unit}`;
5659
const bucketItem = storage.get(bucketKey);
@@ -79,10 +82,4 @@ export function updateMetricSummaryOnSpan(
7982
},
8083
]);
8184
}
82-
83-
if (!SPAN_METRIC_SUMMARY) {
84-
SPAN_METRIC_SUMMARY = new WeakMap();
85-
}
86-
87-
SPAN_METRIC_SUMMARY.set(span, storage);
8885
}

0 commit comments

Comments
 (0)