Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions packages/core/src/tracing/idleSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti

let _autoFinishAllowed: boolean = !options.disableAutoFinish;

const _cleanupHooks: (() => void)[] = [];

const {
idleTimeout = TRACING_DEFAULTS.idleTimeout,
finalTimeout = TRACING_DEFAULTS.finalTimeout,
Expand Down Expand Up @@ -237,6 +239,8 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti
}

function onIdleSpanEnded(endTimestamp: number): void {
_cleanupHooks.forEach(cleanup => cleanup());

_finished = true;
activities.clear();

Expand Down Expand Up @@ -298,41 +302,47 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti
}
}

client.on('spanStart', startedSpan => {
// If we already finished the idle span,
// or if this is the idle span itself being started,
// or if the started span has already been closed,
// we don't care about it for activity
if (_finished || startedSpan === span || !!spanToJSON(startedSpan).timestamp) {
return;
}
_cleanupHooks.push(
client.on('spanStart', startedSpan => {
// If we already finished the idle span,
// or if this is the idle span itself being started,
// or if the started span has already been closed,
// we don't care about it for activity
if (_finished || startedSpan === span || !!spanToJSON(startedSpan).timestamp) {
return;
}

const allSpans = getSpanDescendants(span);
const allSpans = getSpanDescendants(span);

// If the span that was just started is a child of the idle span, we should track it
if (allSpans.includes(startedSpan)) {
_pushActivity(startedSpan.spanContext().spanId);
}
});
// If the span that was just started is a child of the idle span, we should track it
if (allSpans.includes(startedSpan)) {
_pushActivity(startedSpan.spanContext().spanId);
}
}),
);

client.on('spanEnd', endedSpan => {
if (_finished) {
return;
}
_cleanupHooks.push(
client.on('spanEnd', endedSpan => {
if (_finished) {
return;
}

_popActivity(endedSpan.spanContext().spanId);
});
_popActivity(endedSpan.spanContext().spanId);
}),
);

client.on('idleSpanEnableAutoFinish', spanToAllowAutoFinish => {
if (spanToAllowAutoFinish === span) {
_autoFinishAllowed = true;
_restartIdleTimeout();
_cleanupHooks.push(
client.on('idleSpanEnableAutoFinish', spanToAllowAutoFinish => {
if (spanToAllowAutoFinish === span) {
_autoFinishAllowed = true;
_restartIdleTimeout();

if (activities.size) {
_restartChildSpanTimeout();
if (activities.size) {
_restartChildSpanTimeout();
}
}
}
});
}),
);

// We only start the initial idle timeout if we are not delaying the auto finish
if (!options.disableAutoFinish) {
Expand Down
3 changes: 2 additions & 1 deletion packages/feedback/src/core/sendFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export const sendFeedback: SendFeedback = (
// After 5s, we want to clear anyhow
const timeout = setTimeout(() => reject('Unable to determine if Feedback was correctly sent.'), 5_000);

client.on('afterSendEvent', (event: Event, response: TransportMakeRequestResponse) => {
const cleanup = client.on('afterSendEvent', (event: Event, response: TransportMakeRequestResponse) => {
if (event.event_id !== eventId) {
return;
}

clearTimeout(timeout);
cleanup();

// Require valid status codes, otherwise can assume feedback was not sent successfully
if (
Expand Down
8 changes: 7 additions & 1 deletion packages/react/src/errorboundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
private readonly _openFallbackReportDialog: boolean;

private _lastEventId?: string;
private _cleanupHook?: () => void;

public constructor(props: ErrorBoundaryProps) {
super(props);
Expand All @@ -87,7 +88,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
const client = getClient();
if (client && props.showDialog) {
this._openFallbackReportDialog = false;
client.on('afterSendEvent', event => {
this._cleanupHook = client.on('afterSendEvent', event => {
if (!event.type && this._lastEventId && event.event_id === this._lastEventId) {
showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });
}
Expand Down Expand Up @@ -137,6 +138,11 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
if (onUnmount) {
onUnmount(error, componentStack, eventId);
}

if (this._cleanupHook) {
this._cleanupHook();
this._cleanupHook = undefined;
}
}

public resetErrorBoundary: () => void = () => {
Expand Down