Skip to content

Commit af9e4dc

Browse files
committed
remove unneeded transaction
1 parent ab9a24b commit af9e4dc

File tree

3 files changed

+12
-183
lines changed

3 files changed

+12
-183
lines changed
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Hub } from '@sentry/core';
22
import { Transaction } from '@sentry/core';
3-
import type { ClientOptions, Hub as HubInterface, Scope, TransactionContext } from '@sentry/types';
4-
import { uuid4 } from '@sentry/utils';
3+
import type { ClientOptions, Hub as HubInterface, TransactionContext } from '@sentry/types';
54

65
/**
76
* This is a fork of core's tracing/hubextensions.ts _startTransaction,
@@ -13,7 +12,7 @@ export function startTransaction(hub: HubInterface, transactionContext: Transact
1312
const options: Partial<ClientOptions> = (client && client.getOptions()) || {};
1413

1514
// eslint-disable-next-line deprecation/deprecation
16-
const transaction = new OpenTelemetryTransaction(transactionContext, hub as Hub);
15+
const transaction = new Transaction(transactionContext, hub as Hub);
1716
// Since we do not do sampling here, we assume that this is _always_ sampled
1817
// Any sampling decision happens in OpenTelemetry's sampler
1918
transaction.initSpanRecorder(options._experiments && (options._experiments.maxSpans as number));
@@ -23,29 +22,3 @@ export function startTransaction(hub: HubInterface, transactionContext: Transact
2322
}
2423
return transaction;
2524
}
26-
27-
/**
28-
* This is a fork of the base Transaction with OTEL specific stuff added.
29-
*/
30-
export class OpenTelemetryTransaction extends Transaction {
31-
/**
32-
* Finish the transaction, but apply the given scope instead of the current one.
33-
*/
34-
public finishWithScope(endTimestamp?: number, scope?: Scope): string | undefined {
35-
const event = this._finishTransaction(endTimestamp);
36-
37-
if (!event) {
38-
return undefined;
39-
}
40-
41-
// eslint-disable-next-line deprecation/deprecation
42-
const client = this._hub.getClient();
43-
44-
if (!client) {
45-
return undefined;
46-
}
47-
48-
const eventId = uuid4();
49-
return client.captureEvent(event, { event_id: eventId }, scope);
50-
}
51-
}

packages/opentelemetry/src/spanExporter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { ExportResult } from '@opentelemetry/core';
33
import { ExportResultCode } from '@opentelemetry/core';
44
import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
55
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
6+
import type {
7+
Transaction} from '@sentry/core';
68
import {
79
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
810
flush,
@@ -13,9 +15,8 @@ import {
1315
} from '@sentry/core';
1416
import type { Scope, Span as SentrySpan, SpanOrigin, TransactionSource } from '@sentry/types';
1517
import { logger } from '@sentry/utils';
16-
17-
import type { OpenTelemetryTransaction } from './custom/transaction';
1818
import { startTransaction } from './custom/transaction';
19+
1920
import { DEBUG_BUILD } from './debug-build';
2021
import { InternalSentrySemanticAttributes } from './semanticAttributes';
2122
import { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds';
@@ -161,7 +162,7 @@ function parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; sour
161162
return { origin, op, source };
162163
}
163164

164-
function createTransactionForOtelSpan(span: ReadableSpan): OpenTelemetryTransaction {
165+
function createTransactionForOtelSpan(span: ReadableSpan): Transaction {
165166
const scope = getSpanScope(span);
166167
// eslint-disable-next-line deprecation/deprecation
167168
const hub = getSpanHub(span) || getCurrentHub();
@@ -196,7 +197,7 @@ function createTransactionForOtelSpan(span: ReadableSpan): OpenTelemetryTransact
196197
origin,
197198
tags,
198199
sampled: true,
199-
}) as OpenTelemetryTransaction;
200+
});
200201

201202
return transaction;
202203
}

packages/opentelemetry/test/custom/transaction.test.ts

Lines changed: 5 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,13 @@
1-
import { getCurrentHub, setCurrentClient, spanToJSON } from '@sentry/core';
2-
import { OpenTelemetryScope } from '../../src/custom/scope';
3-
import { OpenTelemetryTransaction, startTransaction } from '../../src/custom/transaction';
1+
import { Transaction, getCurrentHub, setCurrentClient, spanToJSON } from '@sentry/core';
2+
import { startTransaction } from '../../src/custom/transaction';
43
import { TestClient, getDefaultTestClientOptions } from '../helpers/TestClient';
54

6-
describe('NodeExperimentalTransaction', () => {
7-
afterEach(() => {
8-
jest.resetAllMocks();
9-
});
10-
11-
it('works with finishWithScope without arguments', () => {
12-
const client = new TestClient(getDefaultTestClientOptions());
13-
14-
const mockSend = jest.spyOn(client, 'captureEvent').mockImplementation(() => 'mocked');
15-
16-
// eslint-disable-next-line deprecation/deprecation
17-
const hub = getCurrentHub();
18-
setCurrentClient(client);
19-
client.init();
20-
21-
// eslint-disable-next-line deprecation/deprecation
22-
const transaction = new OpenTelemetryTransaction({ name: 'test', sampled: true }, hub);
23-
24-
const res = transaction.finishWithScope();
25-
26-
expect(mockSend).toBeCalledTimes(1);
27-
expect(mockSend).toBeCalledWith(
28-
expect.objectContaining({
29-
contexts: {
30-
trace: {
31-
data: {
32-
'sentry.origin': 'manual',
33-
},
34-
span_id: expect.any(String),
35-
trace_id: expect.any(String),
36-
origin: 'manual',
37-
},
38-
},
39-
spans: [],
40-
start_timestamp: expect.any(Number),
41-
tags: {},
42-
timestamp: expect.any(Number),
43-
transaction: 'test',
44-
type: 'transaction',
45-
sdkProcessingMetadata: {
46-
source: 'custom',
47-
spanMetadata: {},
48-
dynamicSamplingContext: {
49-
environment: 'production',
50-
trace_id: expect.any(String),
51-
transaction: 'test',
52-
sampled: 'true',
53-
},
54-
},
55-
transaction_info: { source: 'custom' },
56-
}),
57-
{ event_id: expect.any(String) },
58-
undefined,
59-
);
60-
expect(res).toBe('mocked');
61-
});
62-
63-
it('works with finishWithScope with endTime', () => {
64-
const client = new TestClient(getDefaultTestClientOptions());
65-
66-
const mockSend = jest.spyOn(client, 'captureEvent').mockImplementation(() => 'mocked');
67-
68-
// eslint-disable-next-line deprecation/deprecation
69-
const hub = getCurrentHub();
70-
setCurrentClient(client);
71-
client.init();
72-
73-
// eslint-disable-next-line deprecation/deprecation
74-
const transaction = new OpenTelemetryTransaction({ name: 'test', startTimestamp: 123456, sampled: true }, hub);
75-
76-
const res = transaction.finishWithScope(1234567);
77-
78-
expect(mockSend).toBeCalledTimes(1);
79-
expect(mockSend).toBeCalledWith(
80-
expect.objectContaining({
81-
start_timestamp: 123456,
82-
timestamp: 1234567,
83-
}),
84-
{ event_id: expect.any(String) },
85-
undefined,
86-
);
87-
expect(res).toBe('mocked');
88-
});
89-
90-
it('works with finishWithScope with endTime & scope', () => {
91-
const client = new TestClient(getDefaultTestClientOptions());
92-
93-
const mockSend = jest.spyOn(client, 'captureEvent').mockImplementation(() => 'mocked');
94-
95-
// eslint-disable-next-line deprecation/deprecation
96-
const hub = getCurrentHub();
97-
setCurrentClient(client);
98-
client.init();
99-
100-
// eslint-disable-next-line deprecation/deprecation
101-
const transaction = new OpenTelemetryTransaction({ name: 'test', startTimestamp: 123456, sampled: true }, hub);
102-
103-
const scope = new OpenTelemetryScope();
104-
scope.setTags({
105-
tag1: 'yes',
106-
tag2: 'no',
107-
});
108-
scope.setContext('os', { name: 'Custom OS' });
109-
110-
const res = transaction.finishWithScope(1234567, scope);
111-
112-
expect(mockSend).toBeCalledTimes(1);
113-
expect(mockSend).toBeCalledWith(
114-
expect.objectContaining({
115-
contexts: {
116-
trace: {
117-
data: {
118-
'sentry.origin': 'manual',
119-
},
120-
span_id: expect.any(String),
121-
trace_id: expect.any(String),
122-
origin: 'manual',
123-
},
124-
},
125-
spans: [],
126-
start_timestamp: 123456,
127-
tags: {},
128-
timestamp: 1234567,
129-
transaction: 'test',
130-
type: 'transaction',
131-
sdkProcessingMetadata: {
132-
source: 'custom',
133-
spanMetadata: {},
134-
dynamicSamplingContext: {
135-
environment: 'production',
136-
trace_id: expect.any(String),
137-
transaction: 'test',
138-
sampled: 'true',
139-
},
140-
},
141-
transaction_info: { source: 'custom' },
142-
}),
143-
{ event_id: expect.any(String) },
144-
scope,
145-
);
146-
expect(res).toBe('mocked');
147-
});
148-
});
149-
1505
describe('startTranscation', () => {
1516
afterEach(() => {
1527
jest.resetAllMocks();
1538
});
1549

155-
it('creates a NodeExperimentalTransaction', () => {
10+
it('creates a Transaction', () => {
15611
const client = new TestClient(getDefaultTestClientOptions());
15712
// eslint-disable-next-line deprecation/deprecation
15813
const hub = getCurrentHub();
@@ -161,7 +16,7 @@ describe('startTranscation', () => {
16116

16217
const transaction = startTransaction(hub, { name: 'test' });
16318

164-
expect(transaction).toBeInstanceOf(OpenTelemetryTransaction);
19+
expect(transaction).toBeInstanceOf(Transaction);
16520
expect(transaction['_sampled']).toBe(undefined);
16621
// eslint-disable-next-line deprecation/deprecation
16722
expect(transaction.spanRecorder).toBeDefined();
@@ -197,7 +52,7 @@ describe('startTranscation', () => {
19752
traceId: 'trace1',
19853
});
19954

200-
expect(transaction).toBeInstanceOf(OpenTelemetryTransaction);
55+
expect(transaction).toBeInstanceOf(Transaction);
20156
// eslint-disable-next-line deprecation/deprecation
20257
expect(transaction.metadata).toEqual({
20358
source: 'custom',

0 commit comments

Comments
 (0)