Skip to content

Commit 55c6bbc

Browse files
committed
fix test & cleanup
1 parent 3d358c6 commit 55c6bbc

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

dev-packages/node-integration-tests/suites/tracing-experimental/hapi/test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ describe('hapi auto-instrumentation', () => {
4545

4646
test('CJS - should handle returned plain errors in routes.', done => {
4747
createRunner(__dirname, 'scenario.js')
48+
.expect({
49+
transaction: {
50+
transaction: 'GET /error',
51+
},
52+
})
4853
.expect({ event: EXPECTED_ERROR_EVENT })
4954
.expectError()
5055
.start(done)
@@ -53,6 +58,11 @@ describe('hapi auto-instrumentation', () => {
5358

5459
test('CJS - should handle returned Boom errors in routes.', done => {
5560
createRunner(__dirname, 'scenario.js')
61+
.expect({
62+
transaction: {
63+
transaction: 'GET /boom-error',
64+
},
65+
})
5666
.expect({ event: EXPECTED_ERROR_EVENT })
5767
.expectError()
5868
.start(done)
@@ -61,6 +71,11 @@ describe('hapi auto-instrumentation', () => {
6171

6272
test('CJS - should handle promise rejections in routes.', done => {
6373
createRunner(__dirname, 'scenario.js')
74+
.expect({
75+
transaction: {
76+
transaction: 'GET /promise-error',
77+
},
78+
})
6479
.expect({ event: EXPECTED_ERROR_EVENT })
6580
.expectError()
6681
.start(done)

dev-packages/node-integration-tests/suites/tracing-experimental/mysql/scenario-withoutCallback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ connection.connect(function (err) {
2424
}
2525
});
2626

27-
Sentry.startSpan(
27+
Sentry.startSpanManual(
2828
{
2929
op: 'transaction',
3030
name: 'Test Transaction',

packages/opentelemetry/src/spanExporter.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class SentrySpanExporter {
4646
if (getLocalParentId(span)) {
4747
const openSpanCount = this._finishedSpans.length;
4848
DEBUG_BUILD && logger.log(`SpanExporter has ${openSpanCount} unsent spans remaining`);
49+
this._cleanupOldSpans();
4950
return;
5051
}
5152

@@ -72,17 +73,7 @@ export class SentrySpanExporter {
7273
DEBUG_BUILD &&
7374
logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);
7475

75-
this._finishedSpans = remainingSpans.filter(span => {
76-
const shouldDrop = shouldCleanupSpan(span, 5 * 60);
77-
DEBUG_BUILD &&
78-
shouldDrop &&
79-
logger.log(
80-
`SpanExporter dropping span ${span.name} (${
81-
span.spanContext().spanId
82-
}) because it is pending for more than 5 minutes.`,
83-
);
84-
return !shouldDrop;
85-
});
76+
this._cleanupOldSpans(remainingSpans);
8677
}
8778

8879
/** Clear the exporter. */
@@ -98,6 +89,24 @@ export class SentrySpanExporter {
9889
this._flushTimeout = undefined;
9990
}
10091
}
92+
93+
/**
94+
* Remove any span that is older than 5min.
95+
* We do this to avoid leaking memory.
96+
*/
97+
private _cleanupOldSpans(spans = this._finishedSpans): void {
98+
this._finishedSpans = spans.filter(span => {
99+
const shouldDrop = shouldCleanupSpan(span, 5 * 60);
100+
DEBUG_BUILD &&
101+
shouldDrop &&
102+
logger.log(
103+
`SpanExporter dropping span ${span.name} (${
104+
span.spanContext().spanId
105+
}) because it is pending for more than 5 minutes.`,
106+
);
107+
return !shouldDrop;
108+
});
109+
}
101110
}
102111

103112
/**

0 commit comments

Comments
 (0)