Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/integration-tests/src/tests/errors/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,14 @@ test.describe('errors', () => {
),
).toBeTruthy()
})

test('module error', async ({ recordPage }) => {
await recordPage.goTo('/errors/views/module-error.ejs')
await recordPage.waitForTimeoutAndFlushData(1000)
const errorSpans = recordPage.receivedSpans.filter((span) => span.name === 'unhandledrejection')

expect(errorSpans).toHaveLength(0)
// As error message is generic [object Module], it is being dropped
// expect(errorSpans[0].tags['error.message']).toBe('[object Module]')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Errors test</title>
<%- renderAgent({}) %>
<script id="scenario">
const loadModule = () => {
setTimeout(function() {
const module = import('./module.js').then(module => {
throw module
})
});
}
loadModule()
</script>
</head>
<body>
<h1>Module error</h1>
<pre id="scenarioDisplay"></pre>
<script>scenarioDisplay.innerHTML = scenario.innerHTML;</script>
</body>
</html>
20 changes: 20 additions & 0 deletions packages/integration-tests/src/tests/errors/views/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
*
* Copyright 2020-2025 Splunk Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
const variable = 1

export default variable
12 changes: 11 additions & 1 deletion packages/web/src/SplunkErrorInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ function stringifyValue(value: unknown) {
return '(undefined)'
}

return value.toString()
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#null-prototype_objects
// Check for null-prototype objects
if (value.toString) {
return value.toString()
}

try {
return Object.prototype.toString.call(value)
} catch {
return '(unknown)'
}
}

function parseErrorStack(stack: string): string {
Expand Down
Loading