Skip to content

Commit 2f2c014

Browse files
committed
get it working
1 parent 6d675ed commit 2f2c014

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

packages/tracing/src/idletransaction.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ export class IdleTransactionSpanRecorder extends SpanRecorder {
2424
* @inheritDoc
2525
*/
2626
public add(span: Span): void {
27-
// tslint:disable-next-line: no-unbound-method
28-
const oldFinish: Function = span.finish;
2927
span.finish = (endTimestamp?: number) => {
30-
oldFinish(endTimestamp);
28+
span.endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampWithMs();
3129
if (this._popActivity) {
3230
this._popActivity(span.spanId);
3331
}
3432
};
3533

3634
super.add(span);
37-
if (this._pushActivity && !span.endTimestamp) {
38-
this._pushActivity(span.spanId);
35+
if (span && !span.endTimestamp) {
36+
if (this._pushActivity) {
37+
this._pushActivity(span.spanId);
38+
}
3939
}
4040
}
4141
}
@@ -71,10 +71,12 @@ export class IdleTransaction extends Transaction {
7171
if (hub) {
7272
// We set the transaction here on the scope so error events pick up the trace
7373
// context and attach it to the error.
74+
logger.log('Setting transaction on scope');
7475
hub.configureScope(scope => scope.setSpan(this));
7576
}
7677

77-
// Start heartbeat so that transactions do not run forever.
78+
// Start heartbeat so that transactions do not run forever.\
79+
logger.log('Starting heartbeat');
7880
this._pingHeartbeat();
7981
}
8082

@@ -141,7 +143,9 @@ export class IdleTransaction extends Transaction {
141143
* Finish the current active idle transaction
142144
*/
143145
private _finishIdleTransaction(endTimestamp: number): void {
144-
if (this.spanRecorder) {
146+
if (this.spanRecorder && !this._finished) {
147+
logger.log('[Tracing] finishing IdleTransaction', new Date(endTimestamp * 1000).toISOString());
148+
145149
if (this._finishCallback) {
146150
this._finishCallback(this);
147151
}
@@ -183,6 +187,8 @@ export class IdleTransaction extends Transaction {
183187
* @param spanId The span id that represents the activity
184188
*/
185189
private _pushActivity(spanId: string): void {
190+
logger.log(`[Tracing] pushActivity: ${spanId}`);
191+
logger.log('[Tracing] activies count', Object.keys(this.activities).length);
186192
this.activities[spanId] = true;
187193
}
188194

@@ -192,6 +198,7 @@ export class IdleTransaction extends Transaction {
192198
*/
193199
private _popActivity(spanId: string): void {
194200
if (this.activities[spanId]) {
201+
logger.log(`[Tracing] popActivity ${spanId}`);
195202
// tslint:disable-next-line: no-dynamic-delete
196203
delete this.activities[spanId];
197204
}

packages/tracing/src/integrations/browsertracing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class BrowserTracing implements Integration {
188188
* Initialize routing instrumentation
189189
*/
190190
private static _initRoutingInstrumentation(hub: Hub): void {
191+
BrowserTracing.log('Set up Routing instrumentation');
191192
const {
192193
beforeNavigate,
193194
idleTimeout,

packages/tracing/src/integrations/tracing/router.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Hub } from '@sentry/hub';
22
import { TransactionContext } from '@sentry/types';
3-
import { addInstrumentationHandler, getGlobalObject, timestampWithMs } from '@sentry/utils';
3+
import { addInstrumentationHandler, getGlobalObject, timestampWithMs, logger } from '@sentry/utils';
44

55
import { IdleTransaction } from '../../idletransaction';
66

@@ -158,6 +158,7 @@ export class RouterTracing implements RoutingInstrumentation {
158158
beforeFinish?: (transactionSpan: IdleTransaction) => void,
159159
transactionContext?: TransactionContext,
160160
): void {
161+
logger.log(`[Tracing] starting pageload transaction`);
161162
this._activeTransaction = this.startIdleTransaction(hub, 'pageload', transactionContext);
162163
if (this._activeTransaction && beforeFinish) {
163164
this._activeTransaction.beforeFinish(beforeFinish);
@@ -173,8 +174,10 @@ export class RouterTracing implements RoutingInstrumentation {
173174
transactionContext?: TransactionContext,
174175
): void {
175176
if (this._activeTransaction) {
177+
logger.log(`[Tracing] force ending previous transaction`);
176178
this._activeTransaction.finish(timestampWithMs());
177179
}
180+
logger.log(`[Tracing] starting navigation transaction`);
178181
this._activeTransaction = this.startIdleTransaction(hub, 'navigation', transactionContext);
179182
if (this._activeTransaction && beforeFinish) {
180183
this._activeTransaction.beforeFinish(beforeFinish);

0 commit comments

Comments
 (0)