|
1 |
| -import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, setCurrentClient, timestampInSeconds } from '../../../src'; |
| 1 | +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getCurrentScope, setCurrentClient, timestampInSeconds } from '../../../src'; |
2 | 2 | import { SentrySpan } from '../../../src/tracing/sentrySpan';
|
3 | 3 | import { SPAN_STATUS_ERROR } from '../../../src/tracing/spanstatus';
|
4 | 4 | import { TRACE_FLAG_NONE, TRACE_FLAG_SAMPLED, spanToJSON } from '../../../src/utils/spanUtils';
|
@@ -95,14 +95,30 @@ describe('SentrySpan', () => {
|
95 | 95 | });
|
96 | 96 | });
|
97 | 97 |
|
98 |
| - describe('finish', () => { |
| 98 | + describe('end', () => { |
99 | 99 | test('simple', () => {
|
100 | 100 | const span = new SentrySpan({});
|
101 | 101 | expect(spanToJSON(span).timestamp).toBeUndefined();
|
102 | 102 | span.end();
|
103 | 103 | expect(spanToJSON(span).timestamp).toBeGreaterThan(1);
|
104 | 104 | });
|
105 | 105 |
|
| 106 | + test('with endTime in seconds', () => { |
| 107 | + const span = new SentrySpan({}); |
| 108 | + expect(spanToJSON(span).timestamp).toBeUndefined(); |
| 109 | + const endTime = Date.now() / 1000; |
| 110 | + span.end(endTime); |
| 111 | + expect(spanToJSON(span).timestamp).toBe(endTime); |
| 112 | + }); |
| 113 | + |
| 114 | + test('with endTime in milliseconds', () => { |
| 115 | + const span = new SentrySpan({}); |
| 116 | + expect(spanToJSON(span).timestamp).toBeUndefined(); |
| 117 | + const endTime = Date.now(); |
| 118 | + span.end(endTime); |
| 119 | + expect(spanToJSON(span).timestamp).toBe(endTime / 1000); |
| 120 | + }); |
| 121 | + |
106 | 122 | test('uses sampled config for standalone span', () => {
|
107 | 123 | const client = new TestClient(
|
108 | 124 | getDefaultTestClientOptions({
|
@@ -136,7 +152,7 @@ describe('SentrySpan', () => {
|
136 | 152 | expect(mockSend).toHaveBeenCalledTimes(1);
|
137 | 153 | });
|
138 | 154 |
|
139 |
| - test('sends the span if `beforeSendSpan` does not modify the span ', () => { |
| 155 | + test('sends the span if `beforeSendSpan` does not modify the span', () => { |
140 | 156 | const beforeSendSpan = jest.fn(span => span);
|
141 | 157 | const client = new TestClient(
|
142 | 158 | getDefaultTestClientOptions({
|
@@ -194,30 +210,54 @@ describe('SentrySpan', () => {
|
194 | 210 | );
|
195 | 211 | consoleWarnSpy.mockRestore();
|
196 | 212 | });
|
197 |
| - }); |
198 | 213 |
|
199 |
| - describe('end', () => { |
200 |
| - test('simple', () => { |
201 |
| - const span = new SentrySpan({}); |
202 |
| - expect(spanToJSON(span).timestamp).toBeUndefined(); |
203 |
| - span.end(); |
204 |
| - expect(spanToJSON(span).timestamp).toBeGreaterThan(1); |
205 |
| - }); |
| 214 | + test('build TransactionEvent for basic root span', () => { |
| 215 | + const client = new TestClient( |
| 216 | + getDefaultTestClientOptions({ |
| 217 | + dsn: 'https://username@domain/123', |
| 218 | + }), |
| 219 | + ); |
| 220 | + setCurrentClient(client); |
206 | 221 |
|
207 |
| - test('with endTime in seconds', () => { |
208 |
| - const span = new SentrySpan({}); |
209 |
| - expect(spanToJSON(span).timestamp).toBeUndefined(); |
210 |
| - const endTime = Date.now() / 1000; |
211 |
| - span.end(endTime); |
212 |
| - expect(spanToJSON(span).timestamp).toBe(endTime); |
213 |
| - }); |
| 222 | + const scope = getCurrentScope(); |
| 223 | + const captureEventSpy = jest.spyOn(scope, 'captureEvent').mockImplementation(() => 'testId'); |
214 | 224 |
|
215 |
| - test('with endTime in milliseconds', () => { |
216 |
| - const span = new SentrySpan({}); |
217 |
| - expect(spanToJSON(span).timestamp).toBeUndefined(); |
218 |
| - const endTime = Date.now(); |
219 |
| - span.end(endTime); |
220 |
| - expect(spanToJSON(span).timestamp).toBe(endTime / 1000); |
| 225 | + const span = new SentrySpan({ |
| 226 | + name: 'test', |
| 227 | + startTimestamp: 1, |
| 228 | + sampled: true, |
| 229 | + }); |
| 230 | + span.end(2); |
| 231 | + |
| 232 | + expect(captureEventSpy).toHaveBeenCalledTimes(1); |
| 233 | + expect(captureEventSpy).toHaveBeenCalledWith({ |
| 234 | + _metrics_summary: undefined, |
| 235 | + contexts: { |
| 236 | + trace: { |
| 237 | + data: { |
| 238 | + 'sentry.origin': 'manual', |
| 239 | + }, |
| 240 | + origin: 'manual', |
| 241 | + span_id: expect.stringMatching(/^[a-f0-9]{16}$/), |
| 242 | + trace_id: expect.stringMatching(/^[a-f0-9]{32}$/), |
| 243 | + }, |
| 244 | + }, |
| 245 | + sdkProcessingMetadata: { |
| 246 | + capturedSpanIsolationScope: undefined, |
| 247 | + capturedSpanScope: undefined, |
| 248 | + dynamicSamplingContext: { |
| 249 | + environment: 'production', |
| 250 | + public_key: 'username', |
| 251 | + trace_id: expect.stringMatching(/^[a-f0-9]{32}$/), |
| 252 | + transaction: 'test', |
| 253 | + }, |
| 254 | + }, |
| 255 | + spans: [], |
| 256 | + start_timestamp: 1, |
| 257 | + timestamp: 2, |
| 258 | + transaction: 'test', |
| 259 | + type: 'transaction', |
| 260 | + }); |
221 | 261 | });
|
222 | 262 | });
|
223 | 263 |
|
|
0 commit comments