Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): Add session handling implementation #5173

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

martinkuba
Copy link
Contributor

Which problem is this PR solving?

Follow up to #4972

Discussed in issue open-telemetry/opentelemetry-js-contrib#2358

Short description of the changes

This adds an implementation of session management for web. It introduces a SessionManager class that is responsible for starting, ending, and persisting sessions.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • unit tests
  • example added to examples/opentelemetry-web

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@martinkuba martinkuba requested a review from a team as a code owner November 19, 2024 04:42
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.25%. Comparing base (1370810) to head (58005d4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5173      +/-   ##
==========================================
+ Coverage   93.19%   93.25%   +0.06%     
==========================================
  Files         314      315       +1     
  Lines        8077     8144      +67     
  Branches     1622     1636      +14     
==========================================
+ Hits         7527     7595      +68     
+ Misses        550      549       -1     
Files with missing lines Coverage Δ
...rimental/packages/web-common/src/SessionManager.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

---- 🚨 Try these New Features:

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

looks good overall, just a few questions/nits. 🙂

* SessionManager is responsible for managing the active session including starting,
* resetting, and persisting.
*/
export class SessionManager implements SessionProvider, SessionPublisher {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, is there any reason for users to inherit from SessionManager? 🤔
If yes, would they be able to accomplish the same goal by using composition instead?

If everything can be done can be done with composition, I'd recommend only exporting a factory function that returns a SessionProvider & SessionPublisher - this way we can cut down on the public API quite a bit which will simplify future changes.

@@ -13,6 +13,8 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

### :rocket: (Enhancement)

* feat(web): add session handling implementation [5173](https://github.com/open-telemetry/opentelemetry-js/pull/5173)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* feat(web): add session handling implementation [5173](https://github.com/open-telemetry/opentelemetry-js/pull/5173)
* feat(web): add session handling implementation [#5173](https://github.com/open-telemetry/opentelemetry-js/pull/5173) @martinkuba


import { SessionIdGenerator } from './types/SessionIdGenerator';

export class DefaultIdGenerator implements SessionIdGenerator {
Copy link
Member

Choose a reason for hiding this comment

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

same question here - if users can use composition instead, I'd advocate against exporting the class to make future changes easier. 🙂

sessionManager = new SessionManager(config);

sessionManager.getSessionId(); // Starts session-1
await wait(600);
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, would it be possible to use sinon fake timers instead to avoid depending on actual timing for these tests? 🤔

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.

2 participants