Skip to content

Commit a56fc29

Browse files
authored
feat(core): Deprecate span tags, data, context & setters (#10053)
Also deprecate direct access to `span.attributes` (instead use `spanToJSON(span)`). There are a few usages that we still need to figure out how we will replace them...!
1 parent a157d98 commit a56fc29

File tree

36 files changed

+234
-114
lines changed

36 files changed

+234
-114
lines changed

MIGRATION.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ In v8, the Span class is heavily reworked. The following properties & methods ar
100100
* `span.description`: Use `spanToJSON(span).description` instead.
101101
* `transaction.setMetadata()`: Use attributes instead, or set data on the scope.
102102
* `transaction.metadata`: Use attributes instead, or set data on the scope.
103+
* `span.tags`: Set tags on the surrounding scope instead, or use attributes.
104+
* `span.data`: Use `spanToJSON(span).data` instead.
105+
* `span.setTag()`: Use `span.setAttribute()` instead or set tags on the surrounding scope.
106+
* `span.setData()`: Use `span.setAttribute()` instead.
107+
* `transaction.setContext()`: Set context on the surrounding scope instead.
103108

104109
## Deprecate `pushScope` & `popScope` in favor of `withScope`
105110

dev-packages/browser-integration-tests/suites/public-api/startTransaction/basic_usage/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ sentryTest('should report finished spans as children of the root transaction', a
3131
const span_1 = transaction.spans?.[0];
3232
expect(span_1?.op).toBe('span_1');
3333
expect(span_1?.parentSpanId).toEqual(rootSpanId);
34+
// eslint-disable-next-line deprecation/deprecation
3435
expect(span_1?.data).toMatchObject({ foo: 'bar', baz: [1, 2, 3] });
3536

3637
const span_3 = transaction.spans?.[1];

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/transactions.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ test('Should send a transaction for instrumented server actions', async ({ page
130130
await page.getByText('Run Action').click();
131131

132132
expect(await serverComponentTransactionPromise).toBeDefined();
133-
expect((await serverComponentTransactionPromise).contexts?.trace?.data?.['server_action_form_data']).toEqual(
134-
expect.objectContaining({ 'some-text-value': 'some-default-value' }),
135-
);
133+
expect(
134+
(await serverComponentTransactionPromise).contexts?.trace?.data?.['server_action_form_data.some-text-value'],
135+
).toEqual('some-default-value');
136136
expect((await serverComponentTransactionPromise).contexts?.trace?.data?.['server_action_result']).toEqual({
137137
city: 'Vienna',
138138
});

dev-packages/node-integration-tests/suites/tracing-new/auto-instrument/mysql/withoutCallback/scenario.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ const query = connection.query('SELECT 1 + 1 AS solution');
3232
const query2 = connection.query('SELECT NOW()', ['1', '2']);
3333

3434
query.on('end', () => {
35-
transaction.setTag('result_done', 'yes');
35+
transaction.setAttribute('result_done', 'yes');
3636

3737
query2.on('end', () => {
38-
transaction.setTag('result_done2', 'yes');
38+
transaction.setAttribute('result_done2', 'yes');
3939

4040
// Wait a bit to ensure the queries completed
4141
setTimeout(() => {

dev-packages/node-integration-tests/suites/tracing-new/auto-instrument/mysql/withoutCallback/test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ test('should auto-instrument `mysql` package when using query without callback',
77
expect(envelope).toHaveLength(3);
88

99
assertSentryTransaction(envelope[2], {
10-
transaction: 'Test Transaction',
11-
tags: {
12-
result_done: 'yes',
13-
result_done2: 'yes',
10+
contexts: {
11+
trace: {
12+
data: {
13+
result_done: 'yes',
14+
result_done2: 'yes',
15+
},
16+
},
1417
},
18+
transaction: 'Test Transaction',
1519
spans: [
1620
{
1721
description: 'SELECT 1 + 1 AS solution',

docs/v8-new-performance-apis.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ below to see which things used to exist, and how they can/should be mapped going
5050
| `status` | use utility method TODO |
5151
| `sampled` | `spanIsSampled(span)` |
5252
| `startTimestamp` | `startTime` - note that this has a different format! |
53-
| `tags` | `spanGetAttributes(span)`, or set tags on the scope |
54-
| `data` | `spanGetAttributes(span)` |
53+
| `tags` | use attributes, or set tags on the scope |
54+
| `data` | `spanToJSON(span).data` |
5555
| `transaction` | ??? Removed |
5656
| `instrumenter` | Removed |
5757
| `finish()` | `end()` |
@@ -72,13 +72,13 @@ In addition, a transaction has this API:
7272

7373
| Old name | Replace with |
7474
| --------------------------- | ------------------------------------------------ |
75-
| `name` | `spanGetName(span)` (TODO) |
75+
| `name` | `spanToJSON(span).description` |
7676
| `trimEnd` | Removed |
7777
| `parentSampled` | `spanIsSampled(span)` & `spanContext().isRemote` |
78-
| `metadata` | `spanGetMetadata(span)` |
78+
| `metadata` | Use attributes instead or set on scope |
7979
| `setContext()` | Set context on scope instead |
8080
| `setMeasurement()` | ??? TODO |
81-
| `setMetadata()` | `spanSetMetadata(span, metadata)` |
81+
| `setMetadata()` | Use attributes instead or set on scope |
8282
| `getDynamicSamplingContext` | ??? TODO |
8383

8484
### Attributes vs. Data vs. Tags vs. Context

packages/browser/src/profiling/hubextensions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
156156
// Always call onProfileHandler to ensure stopProfiling is called and the timeout is cleared.
157157
void onProfileHandler().then(
158158
() => {
159+
// TODO: Can we rewrite this to use attributes?
160+
// eslint-disable-next-line deprecation/deprecation
159161
transaction.setContext('profile', { profile_id: profileId, start_timestamp: startTimestamp });
160162
originalEnd();
161163
},

packages/bun/src/integrations/bunserver.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
captureException,
55
continueTrace,
66
convertIntegrationFnToClass,
7+
getCurrentScope,
78
runWithAsyncContext,
89
startSpan,
910
} from '@sentry/core';
@@ -90,9 +91,10 @@ function instrumentBunServeOptions(serveOptions: Parameters<typeof Bun.serve>[0]
9091
>);
9192
if (response && response.status) {
9293
span?.setHttpStatus(response.status);
93-
span?.setData('http.response.status_code', response.status);
94+
span?.setAttribute('http.response.status_code', response.status);
9495
if (span instanceof Transaction) {
95-
span.setContext('response', {
96+
const scope = getCurrentScope();
97+
scope.setContext('response', {
9698
headers: response.headers.toJSON(),
9799
status_code: response.status,
98100
});

packages/bun/test/integrations/bunserver.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('Bun Serve Integration', () => {
2626
test('generates a transaction around a request', async () => {
2727
client.on('finishTransaction', transaction => {
2828
expect(transaction.status).toBe('ok');
29+
// eslint-disable-next-line deprecation/deprecation
2930
expect(transaction.tags).toEqual({
3031
'http.status_code': '200',
3132
});
@@ -48,6 +49,7 @@ describe('Bun Serve Integration', () => {
4849
test('generates a post transaction', async () => {
4950
client.on('finishTransaction', transaction => {
5051
expect(transaction.status).toBe('ok');
52+
// eslint-disable-next-line deprecation/deprecation
5153
expect(transaction.tags).toEqual({
5254
'http.status_code': '200',
5355
});

packages/core/src/tracing/idletransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class IdleTransaction extends Transaction {
146146
this.activities = {};
147147

148148
if (this.op === 'ui.action.click') {
149-
this.setTag(FINISH_REASON_TAG, this._finishReason);
149+
this.setAttribute(FINISH_REASON_TAG, this._finishReason);
150150
}
151151

152152
if (this.spanRecorder) {

0 commit comments

Comments
 (0)