@@ -26,7 +26,7 @@ import {
2626 startOnPageInteraction ,
2727} from './on-page-interaction-stop-watch' ;
2828
29- import { isTrackedTask , getTraceId , resolveInteractionName } from './util' ;
29+ import { isTracingZone , getTraceId , resolveInteractionName } from './util' ;
3030import { interceptXhrTask } from './xhr-interceptor' ;
3131
3232// Allows us to monkey patch Zone prototype without TS compiler errors.
@@ -99,7 +99,7 @@ export class InteractionTracker {
9999 } finally {
100100 if (
101101 interceptingElement ||
102- ( shouldCountTask ( task ) && isTrackedTask ( task ) )
102+ ( shouldCountTask ( task ) && isTracingZone ( task . zone ) )
103103 ) {
104104 this . decrementTaskCount ( getTraceId ( task . zone ) ) ;
105105 }
@@ -110,14 +110,16 @@ export class InteractionTracker {
110110 private patchZoneScheduleTask ( ) {
111111 const scheduleTask = Zone . prototype . scheduleTask ;
112112 Zone . prototype . scheduleTask = < T extends Task > ( task : T ) => {
113- let taskZone = Zone . current ;
114- if ( isTrackedTask ( task ) ) {
115- taskZone = task . zone ;
113+ const currentZone = Zone . current ;
114+ if ( isTracingZone ( currentZone ) ) {
115+ // Cast first as Task and then as AsyncTask because the direct
116+ // cast from type `T` is not possible.
117+ ( ( task as Task ) as AsyncTask ) . _zone = currentZone ;
116118 }
117119 try {
118- return scheduleTask . call ( taskZone as { } , task ) as T ;
120+ return scheduleTask . call ( currentZone as { } , task ) as T ;
119121 } finally {
120- if ( shouldCountTask ( task ) && isTrackedTask ( task ) ) {
122+ if ( shouldCountTask ( task ) && isTracingZone ( task . zone ) ) {
121123 this . incrementTaskCount ( getTraceId ( task . zone ) ) ;
122124 }
123125 }
@@ -127,15 +129,15 @@ export class InteractionTracker {
127129 private patchZoneCancelTask ( ) {
128130 const cancelTask = Zone . prototype . cancelTask ;
129131 Zone . prototype . cancelTask = ( task : AsyncTask ) => {
130- let taskZone = Zone . current ;
131- if ( isTrackedTask ( task ) ) {
132- taskZone = task . zone ;
132+ const currentZone = Zone . current ;
133+ if ( isTracingZone ( currentZone ) ) {
134+ task . _zone = currentZone ;
133135 }
134136
135137 try {
136- return cancelTask . call ( taskZone as { } , task ) ;
138+ return cancelTask . call ( currentZone as { } , task ) ;
137139 } finally {
138- if ( isTrackedTask ( task ) && shouldCountTask ( task ) ) {
140+ if ( isTracingZone ( task . zone ) && shouldCountTask ( task ) ) {
139141 this . decrementTaskCount ( getTraceId ( task . zone ) ) ;
140142 }
141143 }
0 commit comments