Skip to content

Commit 551e401

Browse files
authored
Merge pull request #10617 from getsentry/fn/backport-to-v7
Backport changes to v7
2 parents 613a1aa + 42cf5e7 commit 551e401

File tree

37 files changed

+862
-40
lines changed

37 files changed

+862
-40
lines changed

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module.exports = [
115115
path: 'packages/browser/build/bundles/bundle.tracing.min.js',
116116
gzip: false,
117117
brotli: false,
118-
limit: '105 KB',
118+
limit: '112 KB',
119119
},
120120
{
121121
name: '@sentry/browser - ES6 CDN Bundle (minified & uncompressed)',
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
2+
const Sentry = require('@sentry/node');
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
transport: loggingTransport,
9+
_experiments: {
10+
metricsAggregator: true,
11+
},
12+
});
13+
14+
// Stop the process from exiting before the transaction is sent
15+
setInterval(() => {}, 1000);
16+
17+
Sentry.startSpan(
18+
{
19+
name: 'Test Transaction',
20+
op: 'transaction',
21+
},
22+
() => {
23+
Sentry.metrics.increment('root-counter', 1, {
24+
tags: {
25+
26+
},
27+
});
28+
Sentry.metrics.increment('root-counter', 1, {
29+
tags: {
30+
31+
},
32+
});
33+
34+
Sentry.startSpan(
35+
{
36+
name: 'Some other span',
37+
op: 'transaction',
38+
},
39+
() => {
40+
Sentry.metrics.increment('root-counter');
41+
Sentry.metrics.increment('root-counter');
42+
Sentry.metrics.increment('root-counter', 2);
43+
44+
Sentry.metrics.set('root-set', 'some-value');
45+
Sentry.metrics.set('root-set', 'another-value');
46+
Sentry.metrics.set('root-set', 'another-value');
47+
48+
Sentry.metrics.gauge('root-gauge', 42);
49+
Sentry.metrics.gauge('root-gauge', 20);
50+
51+
Sentry.metrics.distribution('root-distribution', 42);
52+
Sentry.metrics.distribution('root-distribution', 20);
53+
},
54+
);
55+
},
56+
);
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { createRunner } from '../../../utils/runner';
2+
3+
const EXPECTED_TRANSACTION = {
4+
transaction: 'Test Transaction',
5+
_metrics_summary: {
6+
'c:root-counter@none': [
7+
{
8+
min: 1,
9+
max: 1,
10+
count: 1,
11+
sum: 1,
12+
tags: {
13+
release: '1.0',
14+
transaction: 'Test Transaction',
15+
16+
},
17+
},
18+
{
19+
min: 1,
20+
max: 1,
21+
count: 1,
22+
sum: 1,
23+
tags: {
24+
release: '1.0',
25+
transaction: 'Test Transaction',
26+
27+
},
28+
},
29+
],
30+
},
31+
spans: expect.arrayContaining([
32+
expect.objectContaining({
33+
description: 'Some other span',
34+
op: 'transaction',
35+
_metrics_summary: {
36+
'c:root-counter@none': [
37+
{
38+
min: 1,
39+
max: 2,
40+
count: 3,
41+
sum: 4,
42+
tags: {
43+
release: '1.0',
44+
transaction: 'Test Transaction',
45+
},
46+
},
47+
],
48+
's:root-set@none': [
49+
{
50+
min: 0,
51+
max: 1,
52+
count: 3,
53+
sum: 2,
54+
tags: {
55+
release: '1.0',
56+
transaction: 'Test Transaction',
57+
},
58+
},
59+
],
60+
'g:root-gauge@none': [
61+
{
62+
min: 20,
63+
max: 42,
64+
count: 2,
65+
sum: 62,
66+
tags: {
67+
release: '1.0',
68+
transaction: 'Test Transaction',
69+
},
70+
},
71+
],
72+
'd:root-distribution@none': [
73+
{
74+
min: 20,
75+
max: 42,
76+
count: 2,
77+
sum: 62,
78+
tags: {
79+
release: '1.0',
80+
transaction: 'Test Transaction',
81+
},
82+
},
83+
],
84+
},
85+
}),
86+
]),
87+
};
88+
89+
test('Should add metric summaries to spans', done => {
90+
createRunner(__dirname, 'scenario.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
91+
});

packages/angular-ivy/scripts/prepack.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type PackageJson = {
66
type?: string;
77
nx?: string;
88
volta?: any;
9+
exports?: Record<string, string | Record<string, string>>;
910
};
1011

1112
const buildDir = path.join(process.cwd(), 'build');
@@ -18,6 +19,18 @@ const pkgJson: PackageJson = JSON.parse(fs.readFileSync(pkjJsonPath).toString())
1819
delete pkgJson.main;
1920
pkgJson.type = 'module';
2021

22+
pkgJson.exports = {
23+
'.': {
24+
es2015: './fesm2015/sentry-angular-ivy.js',
25+
esm2015: './esm2015/sentry-angular-ivy.js',
26+
fesm2015: './fesm2015/sentry-angular-ivy.js',
27+
import: './fesm2015/sentry-angular-ivy.js',
28+
require: './bundles/sentry-angular-ivy.umd.js',
29+
types: './sentry-angular-ivy.d.ts',
30+
},
31+
'./*': './*',
32+
};
33+
2134
// no need to keep around other properties that are only relevant for our reop:
2235
delete pkgJson.nx;
2336
delete pkgJson.volta;

packages/angular/src/tracing.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export class TraceService implements OnDestroy {
129129
if (!getActiveSpan()) {
130130
startBrowserTracingNavigationSpan(client, {
131131
name: strippedUrl,
132-
op: 'navigation',
133132
origin: 'auto.navigation.angular',
134133
attributes: {
135134
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',

packages/astro/src/index.server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export {
9393
continueTrace,
9494
cron,
9595
parameterize,
96+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
97+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
98+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
99+
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
96100
} from '@sentry/node';
97101

98102
// We can still leave this for the carrier init and type exports

packages/browser/src/exports.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export {
7676
parameterize,
7777
} from '@sentry/core';
7878

79+
export {
80+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
81+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
82+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
83+
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
84+
} from '@sentry/core';
85+
7986
export { WINDOW } from './helpers';
8087
export { BrowserClient } from './client';
8188
export { makeFetchTransport, makeXHRTransport } from './transports';

packages/browser/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export {
2727
// eslint-disable-next-line deprecation/deprecation
2828
Replay,
2929
replayIntegration,
30+
getReplay,
3031
} from '@sentry/replay';
3132
export type {
3233
ReplayEventType,

packages/bun/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export {
117117
onUncaughtExceptionIntegration,
118118
onUnhandledRejectionIntegration,
119119
spotlightIntegration,
120+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
121+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
122+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
123+
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
120124
} from '@sentry/node';
121125

122126
export { BunClient } from './client';

packages/core/src/metrics/aggregator.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import type {
66
Primitive,
77
} from '@sentry/types';
88
import { timestampInSeconds } from '@sentry/utils';
9-
import { DEFAULT_FLUSH_INTERVAL, MAX_WEIGHT, NAME_AND_TAG_KEY_NORMALIZATION_REGEX } from './constants';
9+
import { DEFAULT_FLUSH_INTERVAL, MAX_WEIGHT, NAME_AND_TAG_KEY_NORMALIZATION_REGEX, SET_METRIC_TYPE } from './constants';
1010
import { METRIC_MAP } from './instance';
11+
import { updateMetricSummaryOnActiveSpan } from './metric-summary';
1112
import type { MetricBucket, MetricType } from './types';
1213
import { getBucketKey, sanitizeTags } from './utils';
1314

@@ -62,7 +63,11 @@ export class MetricsAggregator implements MetricsAggregatorBase {
6263
const tags = sanitizeTags(unsanitizedTags);
6364

6465
const bucketKey = getBucketKey(metricType, name, unit, tags);
66+
6567
let bucketItem = this._buckets.get(bucketKey);
68+
// If this is a set metric, we need to calculate the delta from the previous weight.
69+
const previousWeight = bucketItem && metricType === SET_METRIC_TYPE ? bucketItem.metric.weight : 0;
70+
6671
if (bucketItem) {
6772
bucketItem.metric.add(value);
6873
// TODO(abhi): Do we need this check?
@@ -82,6 +87,10 @@ export class MetricsAggregator implements MetricsAggregatorBase {
8287
this._buckets.set(bucketKey, bucketItem);
8388
}
8489

90+
// If value is a string, it's a set metric so calculate the delta from the previous weight.
91+
const val = typeof value === 'string' ? bucketItem.metric.weight - previousWeight : value;
92+
updateMetricSummaryOnActiveSpan(metricType, name, val, unit, unsanitizedTags, bucketKey);
93+
8594
// We need to keep track of the total weight of the buckets so that we can
8695
// flush them when we exceed the max weight.
8796
this._bucketsTotalWeight += bucketItem.metric.weight;

packages/core/src/metrics/browser-aggregator.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import type {
2-
Client,
3-
ClientOptions,
4-
MeasurementUnit,
5-
MetricBucketItem,
6-
MetricsAggregator,
7-
Primitive,
8-
} from '@sentry/types';
1+
import type { Client, ClientOptions, MeasurementUnit, MetricsAggregator, Primitive } from '@sentry/types';
92
import { timestampInSeconds } from '@sentry/utils';
10-
import { DEFAULT_BROWSER_FLUSH_INTERVAL, NAME_AND_TAG_KEY_NORMALIZATION_REGEX } from './constants';
3+
import { DEFAULT_BROWSER_FLUSH_INTERVAL, NAME_AND_TAG_KEY_NORMALIZATION_REGEX, SET_METRIC_TYPE } from './constants';
114
import { METRIC_MAP } from './instance';
5+
import { updateMetricSummaryOnActiveSpan } from './metric-summary';
126
import type { MetricBucket, MetricType } from './types';
137
import { getBucketKey, sanitizeTags } from './utils';
148

@@ -46,24 +40,33 @@ export class BrowserMetricsAggregator implements MetricsAggregator {
4640
const tags = sanitizeTags(unsanitizedTags);
4741

4842
const bucketKey = getBucketKey(metricType, name, unit, tags);
49-
const bucketItem: MetricBucketItem | undefined = this._buckets.get(bucketKey);
43+
44+
let bucketItem = this._buckets.get(bucketKey);
45+
// If this is a set metric, we need to calculate the delta from the previous weight.
46+
const previousWeight = bucketItem && metricType === SET_METRIC_TYPE ? bucketItem.metric.weight : 0;
47+
5048
if (bucketItem) {
5149
bucketItem.metric.add(value);
5250
// TODO(abhi): Do we need this check?
5351
if (bucketItem.timestamp < timestamp) {
5452
bucketItem.timestamp = timestamp;
5553
}
5654
} else {
57-
this._buckets.set(bucketKey, {
55+
bucketItem = {
5856
// @ts-expect-error we don't need to narrow down the type of value here, saves bundle size.
5957
metric: new METRIC_MAP[metricType](value),
6058
timestamp,
6159
metricType,
6260
name,
6361
unit,
6462
tags,
65-
});
63+
};
64+
this._buckets.set(bucketKey, bucketItem);
6665
}
66+
67+
// If value is a string, it's a set metric so calculate the delta from the previous weight.
68+
const val = typeof value === 'string' ? bucketItem.metric.weight - previousWeight : value;
69+
updateMetricSummaryOnActiveSpan(metricType, name, val, unit, unsanitizedTags, bucketKey);
6770
}
6871

6972
/**

packages/core/src/metrics/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const NAME_AND_TAG_KEY_NORMALIZATION_REGEX = /[^a-zA-Z0-9_/.-]+/g;
2121
*
2222
* See: https://develop.sentry.dev/sdk/metrics/#normalization
2323
*/
24-
export const TAG_VALUE_NORMALIZATION_REGEX = /[^\w\d_:/@.{}[\]$-]+/g;
24+
export const TAG_VALUE_NORMALIZATION_REGEX = /[^\w\d\s_:/@.{}[\]$-]+/g;
2525

2626
/**
2727
* This does not match spec in https://develop.sentry.dev/sdk/metrics

0 commit comments

Comments
 (0)