Skip to content

Preserve module source on API errors - #5971

Merged
inancgumus merged 4 commits into
masterfrom
browser-loki-source-prototype
Jun 3, 2026
Merged

Preserve module source on API errors#5971
inancgumus merged 4 commits into
masterfrom
browser-loki-source-prototype

Conversation

@inancgumus

@inancgumus inancgumus commented May 12, 2026

Copy link
Copy Markdown
Contributor

What?

Browser API failures now log the browser module as module=browser.

  • This solution makes it ready to use even after we switch to slog for logging.
  • Browser failures that surface as iteration errors can be filtered as browser logs.
  • We don't override source as it's being used by other things, like stacktrace, console, http-debug, grafana-k6-cloud, etc. Some systems are parsing those, and we should not change them like so. So, we use module.

Why?

Users should be able to filter Cloud Logs for failures separately. A browser operation that failed during a test has already reached Cloud Logs, but it arrived without a label, so the source could not classify it as a browser op.

Note

Failing CI runs are not related to this PR.

Related PR(s)/Issue(s)

@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 18:32 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 18:35 — with GitHub Actions Inactive
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from 6f3c7e6 to f776b45 Compare May 12, 2026 18:38
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 18:44 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 18:46 — with GitHub Actions Inactive
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from f776b45 to 3a49f1d Compare May 12, 2026 18:51
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 18:57 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 18:59 — with GitHub Actions Inactive
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from 3a49f1d to 2add0fb Compare May 12, 2026 19:23
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 19:29 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 19:36 — with GitHub Actions Inactive
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from 2add0fb to c803029 Compare May 12, 2026 20:18
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 20:24 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 20:26 — with GitHub Actions Inactive
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from c803029 to c527534 Compare May 12, 2026 20:26
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 20:32 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 20:34 — with GitHub Actions Inactive
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from c527534 to f7fbade Compare May 12, 2026 21:10
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 21:16 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 21:18 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 22:01 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 12, 2026 22:03 — with GitHub Actions Inactive
@inancgumus
inancgumus marked this pull request as ready for review May 13, 2026 13:18
@inancgumus
inancgumus requested a review from a team as a code owner May 13, 2026 13:18
@inancgumus
inancgumus requested review from mstoykov and szkiba and removed request for a team May 13, 2026 13:18
@inancgumus inancgumus self-assigned this May 13, 2026
szkiba
szkiba previously approved these changes May 13, 2026

@mstoykov mstoykov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not happy wiht making eventloop and errext depend on internal/log and given the naming errWithFieldsError likely should just be under errext but it might also be better to be moved somewhere else.

Comment thread errext/format.go Outdated
Comment thread internal/js/eventloop/eventloop.go Outdated
Comment thread internal/log/error_fields.go Outdated
Comment thread internal/log/error_fields.go Outdated
@mstoykov mstoykov added this to the v2.1.0 milestone May 15, 2026
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch 2 times, most recently from 598be1a to 9657bd7 Compare May 18, 2026 20:16
@inancgumus
inancgumus requested a review from mstoykov May 18, 2026 20:17
@inancgumus

Copy link
Copy Markdown
Contributor Author

@mstoykov Please take another look. I've simplified the code.

@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 18, 2026 20:22 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 18, 2026 20:25 — with GitHub Actions Inactive
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from 9657bd7 to 0c054cd Compare May 18, 2026 21:08
@inancgumus inancgumus changed the title browser: preserve source on API errors Preserve module source on API errors May 18, 2026
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 18, 2026 21:14 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 18, 2026 21:16 — with GitHub Actions Inactive
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from 0c054cd to a327e4f Compare May 18, 2026 21:22
Some errors need to carry extra log fields (like module origin)
through the error chain. WithFields/FieldsFromErr attaches a
map[string]any to any error. Format() merges these fields
alongside hint into the returned fields map.
Unhandled promise rejections were formatted with fmt.Errorf,
which stringified the rejection value and destroyed the
original Go error chain. rejectionError keeps the cause
accessible via Unwrap so errors.As can traverse the chain.
Iteration errors now carry their attached fields to the logger.
Format() extracts any fields from the error chain, exceptions
still get source=stacktrace. This removes the need for
per-field checks in the executor.
Async rejects (promise helper) and sync throws (Panicf) now
attach module=browser via WithFields. This lets Cloud Logs
filter browser-originated errors without overriding the
existing source field used by other systems.
@inancgumus
inancgumus force-pushed the browser-loki-source-prototype branch from a327e4f to 6319394 Compare May 18, 2026 21:24
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 18, 2026 21:30 — with GitHub Actions Inactive
@inancgumus
inancgumus temporarily deployed to azure-trusted-signing May 18, 2026 21:32 — with GitHub Actions Inactive
@szkiba
szkiba self-requested a review May 19, 2026 07:04
@andrewslotin
andrewslotin requested review from andrewslotin and removed request for mstoykov June 3, 2026 17:02
@inancgumus
inancgumus dismissed mstoykov’s stale review June 3, 2026 18:08

The code has been updated per the feedback.

@inancgumus
inancgumus merged commit 575e726 into master Jun 3, 2026
49 of 52 checks passed
@inancgumus
inancgumus deleted the browser-loki-source-prototype branch June 3, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants