Skip to content

fix(observability): stamp HTTP logs with request-issue time (SDK-6164) - #67

Merged
shubhamkd merged 1 commit into
nightwatchjs:mainfrom
kamal-kaur04:fix/SDK-6164-http-log-request-time
Nov 2, 2026
Merged

shubhamkd merged 1 commit into
nightwatchjs:mainfrom
kamal-kaur04:fix/SDK-6164-http-log-request-time

Conversation

@kamal-kaur04

Copy link
Copy Markdown
Contributor

Summary

HTTP logs render out of order in the Test Observability Logs tab. createHttpLogEvent stamps each LogCreated / HTTP event with httpResponse[0], the moment the response landed. The backend orders log events by timestamp, so a request that takes 5s carries a timestamp 5s after it was issued and sorts after every log line the test wrote while it was still in flight.

Nightwatch pushes each httpOutput entry as [isoTimestamp, message, params] when the line is logged: logRequest() runs before the request is sent, logResponse() from onRequestComplete. So httpResponse[0] is request-issue time plus the whole round trip.

// src/testObservability.js — createHttpLogEvent
-            timestamp: httpResponse[0],
+            timestamp: httpRequest[0],

duration_ms is computed from both entries independently, so it still spans request → response and no metric changes. This also matches createScreenshotLogEvent, which already stamps with the command's start time.

Out of scope: a per-process sequence tiebreaker for logs sharing the same millisecond. It is inert until the backend sorts on (timestamp, sequence), so it will follow separately once that lands.

No version bump in this PR; the release is left to the maintainers.

Diff: 2 files, +89 −1, of which 85 lines are the new test file test/src/test-observability/createHttpLogEvent.js.

Verification

Unit tests (npm test)

4 new cases, all passing:

  • the log is stamped with the request-issued time, not the response time;
  • duration_ms still spans the full request → response;
  • a slow request followed by a fast one keeps issue order after sorting by timestamp;
  • output pairs that are not a Request/Response pair are ignored.

Full suite (Node 20, credentials unset): 163 passing, 1 failing. The failing test (getBuildName → "returns empty for empty options") fails identically on main — it asserts the checkout directory name. eslint clean.

Linked ticket: BrowserStack SDK-6164

🤖 Generated with Claude Code

SDK-6164: HTTP logs rendered out of order in the Test Observability Logs
tab. createHttpLogEvent stamped the LogCreated event with httpResponse[0],
the instant the response landed. Nightwatch pushes each httpOutput entry as
[isoTimestamp, message, params] when the line is logged, so httpResponse[0]
is request-issue time plus the whole round trip. A slow request therefore
carried a later timestamp than logs emitted while it was still in flight and
sorted after them.

Stamp with httpRequest[0] instead. duration_ms is computed from both entries
independently, so it still spans request -> response and no metric changes.
This also matches createScreenshotLogEvent, which already stamps with the
command's startTime.

Adds test/src/test-observability/createHttpLogEvent.js (4 cases).
@shubhamkd
shubhamkd merged commit 35c474a into nightwatchjs:main Nov 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants