Skip to content

Conversation

@pkanal
Copy link
Contributor

@pkanal pkanal commented Mar 10, 2025

Which problem is this PR solving?

Closes open-telemetry/opentelemetry-browser#14
Currently, there's no standardized way to capture and monitor unhandled exceptions and promise rejections in web applications using OpenTelemetry. This makes it difficult for developers to:

  • Track runtime errors in production applications
  • Understand the frequency and types of errors occurring
  • Collect detailed error information including stack traces
  • Add custom attributes to error events

Short description of the changes

  • Captures both synchronous errors and unhandled promise rejections
  • Records error name, message, and stack trace using OpenTelemetry semantic conventions
  • Supports custom attribute callback for extending error information
  • Uses the OpenTelemetry Events API for lightweight error reporting
  • Maintains proper cleanup of event listeners

Open questions

  • This instrumentation probably shouldn't rely on the events API directly, should the instrumentation class also expose an events method like it does for tracing and logging?
  • There is also a dependency on types from the api and api-logs package, is that okay or should they be redefined?

@codecov
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.60%. Comparing base (41d0d4b) to head (f1f5b06).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    open-telemetry/opentelemetry-js-contrib#2751   +/-   ##
=======================================
  Coverage   89.60%   89.60%           
=======================================
  Files         174      174           
  Lines        8450     8450           
  Branches     1660     1660           
=======================================
  Hits         7572     7572           
  Misses        878      878           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkanal pkanal force-pushed the pkanal/browser-exception-instrumentation branch from a37abc4 to f1816f9 Compare April 22, 2025 15:34
@pkanal pkanal marked this pull request as ready for review April 22, 2025 15:37
@pkanal pkanal requested a review from a team as a code owner April 22, 2025 15:37
@github-actions github-actions bot requested a review from obecny April 22, 2025 15:37
@pkanal pkanal requested review from MSNev and martinkuba April 22, 2025 15:38
Copy link
Contributor

@overbalance overbalance left a comment

Choose a reason for hiding this comment

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

  1. I'm not sure what version new instrumentation should have. Do we start out with 0.0.1?
  2. I don't love prefixing the name with Web but I know that is a longer conversation. Should we do that now or not? Or mark this as experimental in case we decide to remove Web/Browser prefixes as instrumentations migrates to the browser repo?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can safely delete this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can safely delete this file.

Comment on lines 14 to 16
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"lint:readme": "node ../../scripts/lint-readme.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

These are now handled at the root of the repo.

Suggested change
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"lint:readme": "node ../../scripts/lint-readme.js",

@wolfgangcodes
Copy link
Contributor

Thanks for Reviewing @overbalance

  1. I'm not sure what version new instrumentation should have. Do we start out with 0.0.1?

I didn't see any guidance here. Maybe 0.1.0? I don't have strong opinions, other than it's not a 1,0, since it's still experimental to point 2 below.

  1. I don't love prefixing the name with Web but I know that is a longer conversation. Should we do that now or not? Or mark this as experimental in case we decide to remove Web/Browser prefixes as instrumentations migrates to the browser repo?

I think it's experimental by default unless flagged otherwise, but we could make this explicit. I'm in favor of merging this if the implementation is acceptable and we can discuss the browser naming conventions, prefixes and disambiguation more wholistically at Browser SIG?

@overbalance
Copy link
Contributor

@wolfgangcodes Agreed, we should merge first and discuss in the SIG meeting and on Slack.

@pichlermarc pichlermarc self-assigned this Nov 5, 2025
@pichlermarc pichlermarc self-requested a review November 5, 2025 17:46
@pichlermarc
Copy link
Member

Looks good % package-lock conflicts. 🙂
Re-requesting a review from @martinkuba as it's still marked as Changes Requested

@martinkuba martinkuba merged commit 79d7415 into open-telemetry:main Nov 8, 2025
22 checks passed
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.

Implement event-based instrumentation for web errors