Skip to content

Conversation

@tonybaroneee
Copy link

Discussion

  • This PR adds persistence of a new key in sessionStorage to track telemetry sessions.
  • The session ID is sent as an additional attribute in the OTel log entry.

Testing

  • Unit tests
  • Manual verification using local test app

API Changes

  • (None)

@tonybaroneee tonybaroneee requested a review from a team as a code owner November 19, 2025 15:04
@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

⚠️ No Changeset found

Latest commit: 33e70e6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist
Copy link

Summary of Changes

Hello @tonybaroneee, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the telemetry system by adding support for session ID tracking. It ensures that a unique identifier is generated and maintained for each user session, which is then attached to all outgoing OpenTelemetry log entries. This change will greatly improve the ability to analyze and understand user behavior and error patterns across a single session, providing more coherent and actionable telemetry data. Additionally, it includes a refactoring effort to standardize telemetry attribute keys using constants.

Highlights

  • Session ID Tracking: Introduced a new mechanism to generate and track unique session IDs for telemetry, enhancing the ability to correlate user activity within a single session.
  • Session ID Persistence: Implemented persistence of the generated session IDs in sessionStorage, ensuring that the ID remains consistent throughout a user's browser session.
  • Telemetry Log Integration: The tracked session ID is now included as an additional attribute in OpenTelemetry log entries, providing richer context for each log event.
  • Attribute Key Refactoring: Refactored existing hardcoded log attribute keys (e.g., 'app.version', 'user.id') to use a centralized LOG_ENTRY_ATTRIBUTE_KEYS constant object, improving maintainability and consistency.
  • Robust Session ID Handling: Added error handling for sessionStorage access to gracefully manage scenarios where sessionStorage might be unavailable or restricted (e.g., due to security policies).
  • Comprehensive Unit Tests: New unit tests were added to cover the generation, storage, retrieval, and error handling of session IDs within the telemetry system.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces session ID tracking for telemetry, persisting it in sessionStorage and including it in OTel log entries. The changes are well-structured, and the move to using constants for attribute keys improves code maintainability. I have provided a few suggestions to enhance the robustness of the session ID generation and to simplify the test mocks for better readability and maintainability.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 19, 2025

Size Report 1

Affected Products

  • @firebase/telemetry

    TypeBase (d24986a)Merge (2f93e34)Diff
    browser8.11 kB8.66 kB+557 B (+6.9%)
    main7.53 kB8.04 kB+511 B (+6.8%)
    module8.11 kB8.66 kB+557 B (+6.9%)
  • firebase

    TypeBase (d24986a)Merge (2f93e34)Diff
    firebase-telemetry.js88.0 kB88.2 kB+242 B (+0.3%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/nkS5R8fIVY.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 19, 2025

Size Analysis Report 1

Affected Products

  • @firebase/telemetry

    • captureError

      Size

      TypeBase (d24986a)Merge (2f93e34)Diff
      size4.89 kB5.20 kB+318 B (+6.5%)
      size-with-ext-deps64.3 kB64.6 kB+326 B (+0.5%)

      Dependency

      TypeBase (d24986a)Merge (2f93e34)Diff
      variables

      TELEMETRY_TYPE
      name
      version

      LOG_ENTRY_ATTRIBUTE_KEYS
      TELEMETRY_SESSION_ID_KEY
      TELEMETRY_TYPE
      name
      version

      + LOG_ENTRY_ATTRIBUTE_KEYS
      + TELEMETRY_SESSION_ID_KEY

    • flush

      Size

      TypeBase (d24986a)Merge (2f93e34)Diff
      size4.23 kB4.31 kB+78 B (+1.8%)
      size-with-ext-deps63.0 kB63.0 kB+81 B (+0.1%)

      Dependency

      TypeBase (d24986a)Merge (2f93e34)Diff
      variables

      TELEMETRY_TYPE
      name
      version

      LOG_ENTRY_ATTRIBUTE_KEYS
      TELEMETRY_TYPE
      name
      version

      + LOG_ENTRY_ATTRIBUTE_KEYS

    • getTelemetry

      Size

      TypeBase (d24986a)Merge (2f93e34)Diff
      size4.27 kB4.35 kB+78 B (+1.8%)
      size-with-ext-deps69.9 kB70.0 kB+81 B (+0.1%)

      Dependency

      TypeBase (d24986a)Merge (2f93e34)Diff
      variables

      TELEMETRY_TYPE
      name
      version

      LOG_ENTRY_ATTRIBUTE_KEYS
      TELEMETRY_TYPE
      name
      version

      + LOG_ENTRY_ATTRIBUTE_KEYS

    • nextOnRequestError

      Size

      TypeBase (d24986a)Merge (2f93e34)Diff
      size5.26 kB5.57 kB+318 B (+6.1%)
      size-with-ext-deps71.6 kB71.9 kB+326 B (+0.5%)

      Dependency

      TypeBase (d24986a)Merge (2f93e34)Diff
      variables

      TELEMETRY_TYPE
      name
      version

      LOG_ENTRY_ATTRIBUTE_KEYS
      TELEMETRY_SESSION_ID_KEY
      TELEMETRY_TYPE
      name
      version

      + LOG_ENTRY_ATTRIBUTE_KEYS
      + TELEMETRY_SESSION_ID_KEY

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/VWFo65z92l.html

tonybaroneee and others added 4 commits November 19, 2025 15:46
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for a telemetry session ID, which is persisted in sessionStorage and included in OTel log entries. The implementation is solid, with appropriate feature detection for browser APIs and robust error handling for sessionStorage access. The accompanying tests are comprehensive, effectively mocking browser globals and validating the new functionality. I have one suggestion to further improve the test coverage for error handling scenarios.

@tonybaroneee tonybaroneee merged commit 25ebd49 into telemetry Nov 19, 2025
45 checks passed
@tonybaroneee tonybaroneee deleted the telemetry-session-id branch November 19, 2025 19:24
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.

4 participants