Skip to content

Prototype for sessions as entities#1

Draft
martinkuba wants to merge 3 commits intopackages-prototypefrom
entity-prototype
Draft

Prototype for sessions as entities#1
martinkuba wants to merge 3 commits intopackages-prototypefrom
entity-prototype

Conversation

@martinkuba
Copy link
Owner

@martinkuba martinkuba commented Mar 1, 2026

This is intended as a prototype of modeling browser sessions using entities based on this proposal:

OTEP: Allow multiple Resources in an SDK by jsuereth · Pull Request #4665 · open-telemetry/opentelemetry-specification.

The proposal introduces a forEntity() method on providers. I think this works when a single module (e.g. single instrumentation) is in control of the entity-bound provider.

However, the session entity should be applied to all telemetry. When any instrumentation (and user code) emits a signal, it should include the session attributes. And when a session rotates, this needs to propagate to all.

This prototype includes an EntityAwareLoggerProvider that delegates to an internal LoggerProvider and allows updating the entity via the setEntity() method. Internally, the delegate LoggerProvider is constructed by using the forEntity() method as described in the proposal.

@martinkuba martinkuba changed the title Prototype for sessions as entities: SessionAwareLoggerProvider Prototype for sessions as entities Mar 1, 2026
// Rebind on session rotation
sessionManager.addObserver({
onSessionStarted(session) {
loggerProvider.setEntity(createSessionEntity(session.id));
Copy link
Owner Author

Choose a reason for hiding this comment

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

This shows user code updating the global logger provider with a new session entity.

* route telemetry through the new entity-bound provider.
*/
setEntity(entity: Entity): void {
this._currentProvider = this.forEntity(entity);

Choose a reason for hiding this comment

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

If we are replacing the current provider I wonder if its necessary to shut it down 1st 🤔

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