-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[main] fix startTime timestamp #2183
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
IAppInsightsCore, IDiagnosticLogger, IProcessTelemetryUnloadContext, ITelemetryUnloadState, _eInternalMessageId, _throwInternal, | ||
arrForEach, dumpObj, eLoggingSeverity, getDocument, getExceptionName, getLocation, isNullOrUndefined | ||
} from "@microsoft/applicationinsights-core-js"; | ||
import { ITimerHandler, isWebWorker, scheduleTimeout } from "@nevware21/ts-utils"; | ||
import { ITimerHandler, getPerformance, isUndefined, isWebWorker, scheduleTimeout } from "@nevware21/ts-utils"; | ||
import { PageViewPerformanceManager } from "./PageViewPerformanceManager"; | ||
|
||
/** | ||
|
@@ -35,6 +35,7 @@ export class PageViewManager { | |
let queueTimer: ITimerHandler = null; | ||
let itemQueue: Array<() => boolean> = []; | ||
let pageViewPerformanceSent: boolean = false; | ||
let firstPageViewSent: boolean = false; | ||
let _logger: IDiagnosticLogger; | ||
|
||
if (core) { | ||
|
@@ -95,6 +96,24 @@ export class PageViewManager { | |
let location = getLocation(); | ||
uri = pageView.uri = location && location.href || ""; | ||
} | ||
|
||
if (!firstPageViewSent){ | ||
let perf = getPerformance(); | ||
// Access the performance timing object | ||
const navigationEntries = (perf && perf.getEntriesByType && perf.getEntriesByType("navigation")); | ||
|
||
// Edge Case the navigation Entries may return an empty array and the timeOrigin is not supported on IE | ||
if (navigationEntries && navigationEntries[0] && !isUndefined(perf.timeOrigin)) { | ||
// Get the value of loadEventStart | ||
const loadEventStart = (navigationEntries[0] as PerformanceNavigationTiming).loadEventStart; | ||
pageView.startTime = new Date(perf.timeOrigin + loadEventStart); | ||
} else { | ||
// calculate the start time manually | ||
let duration = ((customProperties || pageView.properties || {}).duration || 0); | ||
pageView.startTime = new Date(new Date().getTime() - duration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still needs to be done of ALL other cases, otherwise the reported "time" will be wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise the Portal will show the wrong "startTime" |
||
} | ||
firstPageViewSent = true; | ||
} | ||
|
||
// case 1a. if performance timing is not supported by the browser, send the page view telemetry with the duration provided by the user. If the user | ||
// do not provide the duration, set duration to undefined | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at all of the "usages" of the
sendPageViewInternal
, it looks like (once we remove this from here), that we should do this duration update in theAngularPlugin.ts Line 602
(before the_pageTracking
calls the_self.sendPageViewInternal
so that the "time" is still shifted back by theduration
otherwise the Portal will show the wrong "startTime"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe?? (testing required)
We can just keep something here like
So that if the previous code (like the line 602 above) doesn't specify any
startTime
then we keep "using" this default, this should also work for the subsequent page views, even with your code below for theif (!firstPageViewSent){