Skip to content

Commit 68c3f57

Browse files
committed
transaction.name
1 parent 11f0a75 commit 68c3f57

File tree

5 files changed

+27
-56
lines changed

5 files changed

+27
-56
lines changed

packages/angular/test/tracing.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from '@angular/core';
22
import type { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
3-
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
3+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, spanToJSON } from '@sentry/core';
44

55
import { TraceClassDecorator, TraceDirective, TraceMethodDecorator, instrumentAngularRouting } from '../src';
66
import { getParameterizedRouteFromSnapshot } from '../src/tracing';
@@ -153,7 +153,7 @@ describe('Angular Tracing', () => {
153153
});
154154

155155
expect(transaction.updateName).toHaveBeenCalledTimes(0);
156-
expect(transaction.name).toEqual(url);
156+
expect(spanToJSON(transaction).description).toEqual(url);
157157
expect(transaction.toJSON().data).toEqual({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom' });
158158

159159
env.destroy();

packages/core/src/tracing/transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export class Transaction extends SentrySpan implements TransactionInterface {
124124
/** @inheritdoc */
125125
public updateName(name: string): this {
126126
this._name = name;
127+
this.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'custom');
127128
return this;
128129
}
129130

packages/core/test/lib/tracing/transaction.test.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,26 @@ import {
33
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
44
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
55
Transaction,
6+
spanToJSON,
67
} from '../../../src';
78

89
describe('transaction', () => {
910
describe('name', () => {
1011
/* eslint-disable deprecation/deprecation */
1112
it('works with name', () => {
1213
const transaction = new Transaction({ name: 'span name' });
13-
expect(transaction.name).toEqual('span name');
14-
});
15-
16-
it('allows to update the name via setter', () => {
17-
const transaction = new Transaction({ name: 'span name' });
18-
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
19-
expect(transaction.name).toEqual('span name');
20-
21-
transaction.name = 'new name';
22-
23-
expect(transaction.name).toEqual('new name');
24-
expect(transaction.attributes['sentry.source']).toEqual('custom');
25-
});
26-
27-
it('allows to update the name via setName', () => {
28-
const transaction = new Transaction({ name: 'span name' });
29-
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
30-
expect(transaction.name).toEqual('span name');
31-
32-
transaction.updateName('new name');
33-
34-
expect(transaction.name).toEqual('new name');
35-
expect(transaction.attributes['sentry.source']).toEqual('custom');
14+
expect(spanToJSON(transaction).description).toEqual('span name');
3615
});
3716

3817
it('allows to update the name via updateName', () => {
3918
const transaction = new Transaction({ name: 'span name' });
4019
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
41-
expect(transaction.name).toEqual('span name');
20+
expect(spanToJSON(transaction).description).toEqual('span name');
4221

4322
transaction.updateName('new name');
4423

45-
expect(transaction.name).toEqual('new name');
46-
expect(transaction.attributes['sentry.source']).toEqual('route');
24+
expect(spanToJSON(transaction).description).toEqual('new name');
25+
expect(transaction.metadata.source).toEqual('route');
4726
});
4827
/* eslint-enable deprecation/deprecation */
4928
});

packages/tracing-internal/test/browser/browsertracing.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe('BrowserTracing', () => {
175175

176176
const transaction = getActiveTransaction() as IdleTransaction;
177177
expect(transaction).toBeDefined();
178-
expect(transaction.name).toBe('a/path');
178+
expect(spanToJSON(transaction).description).toBe('a/path');
179179
expect(transaction.op).toBe('pageload');
180180
});
181181

@@ -246,8 +246,8 @@ describe('BrowserTracing', () => {
246246
});
247247
const transaction = getActiveTransaction() as IdleTransaction;
248248
expect(transaction).toBeDefined();
249-
expect(transaction.name).toBe('newName');
250-
expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom');
249+
expect(spanToJSON(transaction).description).toBe('newName');
250+
expect(transaction.metadata.source).toBe('custom');
251251

252252
expect(mockBeforeNavigation).toHaveBeenCalledTimes(1);
253253
});
@@ -268,8 +268,8 @@ describe('BrowserTracing', () => {
268268
});
269269
const transaction = getActiveTransaction() as IdleTransaction;
270270
expect(transaction).toBeDefined();
271-
expect(transaction.name).toBe('a/path');
272-
expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('url');
271+
expect(spanToJSON(transaction).description).toBe('a/path');
272+
expect(transaction.metadata.source).toBe('url');
273273

274274
expect(mockBeforeNavigation).toHaveBeenCalledTimes(1);
275275
});

packages/tracing/test/transaction.test.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
55
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
66
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
7+
spanToJSON,
78
} from '@sentry/core';
89

910
import { Transaction, addExtensionMethods } from '../src';
@@ -21,23 +22,23 @@ describe('`Transaction` class', () => {
2122
attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route' },
2223
});
2324

24-
expect(transaction.name).toEqual('dogpark');
25-
expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route');
25+
expect(spanToJSON(transaction).description).toEqual('dogpark');
26+
expect(transaction.metadata.source).toEqual('route');
2627
});
2728

2829
it("sets source to be `'custom'` in constructor if not provided", () => {
2930
const transaction = new Transaction({ name: 'dogpark' });
3031

31-
expect(transaction.name).toEqual('dogpark');
32-
expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom');
32+
expect(spanToJSON(transaction).description).toEqual('dogpark');
33+
expect(transaction.metadata.source).toBe('custom');
3334
});
3435

3536
it("sets source to `'custom'` when assigning to `name` property", () => {
3637
const transaction = new Transaction({ name: 'dogpark' });
37-
transaction.name = 'ballpit';
38+
transaction.updateName('ballpit');
3839

39-
expect(transaction.name).toEqual('ballpit');
40-
expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('custom');
40+
expect(spanToJSON(transaction).description).toEqual('ballpit');
41+
expect(transaction.metadata.source).toEqual('custom');
4142
});
4243

4344
it('sets instrumenter to be `sentry` in constructor if not provided', () => {
@@ -52,32 +53,22 @@ describe('`Transaction` class', () => {
5253
expect(transaction.instrumenter).toEqual('otel');
5354
});
5455

55-
describe('`setName` method', () => {
56+
describe('`updateName` method', () => {
5657
it("sets source to `'custom'` if no source provided", () => {
5758
const transaction = new Transaction({ name: 'dogpark' });
5859
transaction.updateName('ballpit');
5960

60-
expect(transaction.name).toEqual('ballpit');
61-
expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('custom');
61+
expect(spanToJSON(transaction).description).toEqual('ballpit');
62+
expect(transaction.metadata.source).toEqual('custom');
6263
});
6364

6465
it('uses given `source` value', () => {
6566
const transaction = new Transaction({ name: 'dogpark' });
66-
transaction.updateName('ballpit', 'route');
67-
68-
expect(transaction.name).toEqual('ballpit');
69-
expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route');
70-
});
71-
});
72-
73-
describe('`updateName` method', () => {
74-
it('does not change the source', () => {
75-
const transaction = new Transaction({ name: 'dogpark' });
76-
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
7767
transaction.updateName('ballpit');
68+
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
7869

79-
expect(transaction.name).toEqual('ballpit');
80-
expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route');
70+
expect(spanToJSON(transaction).description).toEqual('ballpit');
71+
expect(transaction.metadata.source).toEqual('route');
8172
});
8273
});
8374
});

0 commit comments

Comments
 (0)