@opentelemetry/web-common 0.215.0 → 0.217.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
  * Copyright The OpenTelemetry Authors
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
+ const MAX_DURATION_MS = 2147483647; // max setTimeout value in milliseconds (~24.8 days)
5
6
  /**
6
7
  * SessionManager is responsible for managing the active session including starting,
7
8
  * resetting, and persisting.
@@ -100,9 +101,10 @@ export class SessionManager {
100
101
  if (this._inactivityTimeoutId) {
101
102
  clearTimeout(this._inactivityTimeoutId);
102
103
  }
104
+ const timeoutIn = Math.min(this._inactivityTimeout * 1000, MAX_DURATION_MS);
103
105
  this._inactivityTimeoutId = setTimeout(() => {
104
106
  this.resetSession();
105
- }, this._inactivityTimeout * 1000);
107
+ }, timeoutIn);
106
108
  }
107
109
  resetMaxDurationTimer() {
108
110
  if (!this._maxDuration || !this._session) {
@@ -111,7 +113,8 @@ export class SessionManager {
111
113
  if (this._maxDurationTimeoutId) {
112
114
  clearTimeout(this._maxDurationTimeoutId);
113
115
  }
114
- const timeoutIn = this._maxDuration * 1000 - (Date.now() - this._session?.startTimestamp);
116
+ const timeoutIn = Math.max(0, // a backgrounded tab can cause a negative timeout value, so we use 0 to trigger session reset immediately on resume of the tab
117
+ Math.min(this._maxDuration * 1000 - (Date.now() - this._session.startTimestamp), MAX_DURATION_MS));
115
118
  this._maxDurationTimeoutId = setTimeout(() => {
116
119
  this.resetSession();
117
120
  }, timeoutIn);
@@ -1 +1 @@
1
- {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../src/SessionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH;;;GAGG;AACH,MAAM,OAAO,cAAc;IACjB,QAAQ,CAA6B;IACrC,YAAY,CAAqB;IACjC,MAAM,CAAe;IACrB,UAAU,CAAoB;IAE9B,YAAY,CAAU;IACtB,qBAAqB,CAAiC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W,EAAE,CAAC;IACrB,CAAC;IAEO,WAAW;QACjB,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,qBAAqB,EAAE,CAAC;IAC/B,CAAC;IAEO,oBAAoB;QAC1B,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5B,OAAO;SACR;QAED,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC7B,YAAY,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;SACzC;QAED,IAAI,CAAC,oBAAoB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC1C,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IACrC,CAAC;IAEO,qBAAqB;QAC3B,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YACxC,OAAO;SACR;QAED,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC9B,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;SAC1C;QAED,MAAM,SAAS,GACb,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAE1E,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SessionIdGenerator } from './types/SessionIdGenerator';\nimport type { Session } from './types/Session';\nimport type { SessionProvider } from './types/SessionProvider';\nimport type { SessionObserver } from './types/SessionObserver';\nimport type { SessionStore } from './types/SessionStore';\nimport type { SessionPublisher } from './types/SessionPublisher';\n\nexport interface SessionManagerConfig {\n /** Class responsible for generating a session ID */\n sessionIdGenerator: SessionIdGenerator;\n /** Class responsible for storing session data over multiple page loads. */\n sessionStore: SessionStore;\n /** Maximum duration of a session in seconds */\n maxDuration?: number;\n /** Maximum time without a user activity after which a session should be expired, in seconds */\n inactivityTimeout?: number;\n}\n\n/**\n * SessionManager is responsible for managing the active session including starting,\n * resetting, and persisting.\n */\nexport class SessionManager implements SessionProvider, SessionPublisher {\n private _session: Session | null | undefined;\n private _idGenerator: SessionIdGenerator;\n private _store: SessionStore;\n private _observers: SessionObserver[];\n\n private _maxDuration?: number;\n private _maxDurationTimeoutId?: ReturnType<typeof setTimeout>;\n\n private _inactivityTimeout?: number;\n private _inactivityTimeoutId?: ReturnType<typeof setTimeout>;\n private _lastActivityTimestamp: number = 0;\n private _inactivityResetDelay: number = 5000; // minimum time in ms between activities before timer is reset\n\n constructor(config: SessionManagerConfig) {\n this._idGenerator = config.sessionIdGenerator;\n this._store = config.sessionStore;\n this._maxDuration = config.maxDuration;\n this._inactivityTimeout = config.inactivityTimeout;\n this._observers = [];\n }\n\n async start(): Promise<void> {\n this._session = await this._store.get();\n if (!this._session) {\n this._session = await this.startSession();\n }\n this.resetTimers();\n }\n\n addObserver(observer: SessionObserver): void {\n this._observers.push(observer);\n }\n\n getSessionId(): string | null {\n return this.getSession().id;\n }\n\n getSession(): Session {\n if (!this._session) {\n this._session = this.startSession();\n this.resetTimers();\n }\n\n if (this._inactivityTimeout) {\n if (\n Date.now() - this._lastActivityTimestamp >\n this._inactivityResetDelay\n ) {\n this.resetInactivityTimer();\n this._lastActivityTimestamp = Date.now();\n }\n }\n\n return this._session;\n }\n\n shutdown(): void {\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n }\n\n private startSession(): Session {\n const sessionId = this._idGenerator.generateSessionId();\n\n const session: Session = {\n id: sessionId,\n startTimestamp: Date.now(),\n };\n\n // this is async call, but we don't wait for it\n void this._store.save(session);\n\n for (const observer of this._observers) {\n observer.onSessionStarted(session, this._session ?? undefined);\n }\n\n this._session = session;\n\n return session;\n }\n\n private endSession(): void {\n if (this._session) {\n for (const observer of this._observers) {\n observer.onSessionEnded(this._session);\n }\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n this._inactivityTimeoutId = undefined;\n }\n }\n\n private resetSession(): void {\n this.endSession();\n this.startSession();\n this.resetTimers();\n }\n\n private resetTimers() {\n this.resetInactivityTimer();\n this.resetMaxDurationTimer();\n }\n\n private resetInactivityTimer() {\n if (!this._inactivityTimeout) {\n return;\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n this._inactivityTimeoutId = setTimeout(() => {\n this.resetSession();\n }, this._inactivityTimeout * 1000);\n }\n\n private resetMaxDurationTimer() {\n if (!this._maxDuration || !this._session) {\n return;\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n\n const timeoutIn =\n this._maxDuration * 1000 - (Date.now() - this._session?.startTimestamp);\n\n this._maxDurationTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n}\n"]}
1
+ {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../src/SessionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,MAAM,eAAe,GAAG,UAAU,CAAC,CAAC,oDAAoD;AAYxF;;;GAGG;AACH,MAAM,OAAO,cAAc;IACjB,QAAQ,CAA6B;IACrC,YAAY,CAAqB;IACjC,MAAM,CAAe;IACrB,UAAU,CAAoB;IAE9B,YAAY,CAAU;IACtB,qBAAqB,CAAiC;IAEtD,kBAAkB,CAAU;IAC5B,oBAAoB,CAAiC;IACrD,sBAAsB,GAAW,CAAC,CAAC;IACnC,qBAAqB,GAAW,IAAI,CAAC,CAAC,8DAA8D;IAE5G,YAAY,MAA4B;QACtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,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E;YAC5B,OAAO;SACR;QAED,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC7B,YAAY,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;SACzC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,GAAG,IAAI,EAAE,eAAe,CAAC,CAAC;QAC5E,IAAI,CAAC,oBAAoB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC1C,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC;IAEO,qBAAqB;QAC3B,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YACxC,OAAO;SACR;QAED,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC9B,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;SAC1C;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CACxB,CAAC,EAAE,+HAA+H;QAClI,IAAI,CAAC,GAAG,CACN,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EACtE,eAAe,CAChB,CACF,CAAC;QAEF,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SessionIdGenerator } from './types/SessionIdGenerator';\nimport type { Session } from './types/Session';\nimport type { SessionProvider } from './types/SessionProvider';\nimport type { SessionObserver } from './types/SessionObserver';\nimport type { SessionStore } from './types/SessionStore';\nimport type { SessionPublisher } from './types/SessionPublisher';\n\nconst MAX_DURATION_MS = 2147483647; // max setTimeout value in milliseconds (~24.8 days)\nexport interface SessionManagerConfig {\n /** Class responsible for generating a session ID */\n sessionIdGenerator: SessionIdGenerator;\n /** Class responsible for storing session data over multiple page loads. */\n sessionStore: SessionStore;\n /** Maximum duration of a session in seconds */\n maxDuration?: number;\n /** Maximum time without a user activity after which a session should be expired, in seconds */\n inactivityTimeout?: number;\n}\n\n/**\n * SessionManager is responsible for managing the active session including starting,\n * resetting, and persisting.\n */\nexport class SessionManager implements SessionProvider, SessionPublisher {\n private _session: Session | null | undefined;\n private _idGenerator: SessionIdGenerator;\n private _store: SessionStore;\n private _observers: SessionObserver[];\n\n private _maxDuration?: number;\n private _maxDurationTimeoutId?: ReturnType<typeof setTimeout>;\n\n private _inactivityTimeout?: number;\n private _inactivityTimeoutId?: ReturnType<typeof setTimeout>;\n private _lastActivityTimestamp: number = 0;\n private _inactivityResetDelay: number = 5000; // minimum time in ms between activities before timer is reset\n\n constructor(config: SessionManagerConfig) {\n this._idGenerator = config.sessionIdGenerator;\n this._store = config.sessionStore;\n this._maxDuration = config.maxDuration;\n this._inactivityTimeout = config.inactivityTimeout;\n this._observers = [];\n }\n\n async start(): Promise<void> {\n this._session = await this._store.get();\n if (!this._session) {\n this._session = await this.startSession();\n }\n this.resetTimers();\n }\n\n addObserver(observer: SessionObserver): void {\n this._observers.push(observer);\n }\n\n getSessionId(): string | null {\n return this.getSession().id;\n }\n\n getSession(): Session {\n if (!this._session) {\n this._session = this.startSession();\n this.resetTimers();\n }\n\n if (this._inactivityTimeout) {\n if (\n Date.now() - this._lastActivityTimestamp >\n this._inactivityResetDelay\n ) {\n this.resetInactivityTimer();\n this._lastActivityTimestamp = Date.now();\n }\n }\n\n return this._session;\n }\n\n shutdown(): void {\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n }\n\n private startSession(): Session {\n const sessionId = this._idGenerator.generateSessionId();\n\n const session: Session = {\n id: sessionId,\n startTimestamp: Date.now(),\n };\n\n // this is async call, but we don't wait for it\n void this._store.save(session);\n\n for (const observer of this._observers) {\n observer.onSessionStarted(session, this._session ?? undefined);\n }\n\n this._session = session;\n\n return session;\n }\n\n private endSession(): void {\n if (this._session) {\n for (const observer of this._observers) {\n observer.onSessionEnded(this._session);\n }\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n this._inactivityTimeoutId = undefined;\n }\n }\n\n private resetSession(): void {\n this.endSession();\n this.startSession();\n this.resetTimers();\n }\n\n private resetTimers() {\n this.resetInactivityTimer();\n this.resetMaxDurationTimer();\n }\n\n private resetInactivityTimer() {\n if (!this._inactivityTimeout) {\n return;\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n const timeoutIn = Math.min(this._inactivityTimeout * 1000, MAX_DURATION_MS);\n this._inactivityTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n\n private resetMaxDurationTimer() {\n if (!this._maxDuration || !this._session) {\n return;\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n\n const timeoutIn = Math.max(\n 0, // a backgrounded tab can cause a negative timeout value, so we use 0 to trigger session reset immediately on resume of the tab\n Math.min(\n this._maxDuration * 1000 - (Date.now() - this._session.startTimestamp),\n MAX_DURATION_MS\n )\n );\n\n this._maxDurationTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.215.0";
1
+ export declare const VERSION = "0.217.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -3,5 +3,5 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  // this is autogenerated file, see scripts/version-update.js
6
- export const VERSION = '0.215.0';
6
+ export const VERSION = '0.217.0';
7
7
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.215.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.217.0';\n"]}
@@ -2,6 +2,7 @@
2
2
  * Copyright The OpenTelemetry Authors
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
+ const MAX_DURATION_MS = 2147483647; // max setTimeout value in milliseconds (~24.8 days)
5
6
  /**
6
7
  * SessionManager is responsible for managing the active session including starting,
7
8
  * resetting, and persisting.
@@ -100,9 +101,10 @@ export class SessionManager {
100
101
  if (this._inactivityTimeoutId) {
101
102
  clearTimeout(this._inactivityTimeoutId);
102
103
  }
104
+ const timeoutIn = Math.min(this._inactivityTimeout * 1000, MAX_DURATION_MS);
103
105
  this._inactivityTimeoutId = setTimeout(() => {
104
106
  this.resetSession();
105
- }, this._inactivityTimeout * 1000);
107
+ }, timeoutIn);
106
108
  }
107
109
  resetMaxDurationTimer() {
108
110
  if (!this._maxDuration || !this._session) {
@@ -111,7 +113,8 @@ export class SessionManager {
111
113
  if (this._maxDurationTimeoutId) {
112
114
  clearTimeout(this._maxDurationTimeoutId);
113
115
  }
114
- const timeoutIn = this._maxDuration * 1000 - (Date.now() - this._session?.startTimestamp);
116
+ const timeoutIn = Math.max(0, // a backgrounded tab can cause a negative timeout value, so we use 0 to trigger session reset immediately on resume of the tab
117
+ Math.min(this._maxDuration * 1000 - (Date.now() - this._session.startTimestamp), MAX_DURATION_MS));
115
118
  this._maxDurationTimeoutId = setTimeout(() => {
116
119
  this.resetSession();
117
120
  }, timeoutIn);
@@ -1 +1 @@
1
- {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../src/SessionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH;;;GAGG;AACH,MAAM,OAAO,cAAc;IACjB,QAAQ,CAA6B;IACrC,YAAY,CAAqB;IACjC,MAAM,CAAe;IACrB,UAAU,CAAoB;IAE9B,YAAY,CAAU;IACtB,qBAAqB,CAAiC;IAEtD,kBAAkB,CAAU;IAC5B,oBAAoB,CAAiC;IACrD,sBAAsB,GAAW,CAAC,CAAC;IACnC,qBAAqB,GAAW,IAAI,CAAC,CAAC,8DAA8D;IAE5G,YAAY,MAA4B;QACtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,kBAAkB,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;QAClC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;SAC3C;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAED,WAAW,CAAC,QAAyB;QACnC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;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AC,GAAG,EAAE;YAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SessionIdGenerator } from './types/SessionIdGenerator';\nimport type { Session } from './types/Session';\nimport type { SessionProvider } from './types/SessionProvider';\nimport type { SessionObserver } from './types/SessionObserver';\nimport type { SessionStore } from './types/SessionStore';\nimport type { SessionPublisher } from './types/SessionPublisher';\n\nexport interface SessionManagerConfig {\n /** Class responsible for generating a session ID */\n sessionIdGenerator: SessionIdGenerator;\n /** Class responsible for storing session data over multiple page loads. */\n sessionStore: SessionStore;\n /** Maximum duration of a session in seconds */\n maxDuration?: number;\n /** Maximum time without a user activity after which a session should be expired, in seconds */\n inactivityTimeout?: number;\n}\n\n/**\n * SessionManager is responsible for managing the active session including starting,\n * resetting, and persisting.\n */\nexport class SessionManager implements SessionProvider, SessionPublisher {\n private _session: Session | null | undefined;\n private _idGenerator: SessionIdGenerator;\n private _store: SessionStore;\n private _observers: SessionObserver[];\n\n private _maxDuration?: number;\n private _maxDurationTimeoutId?: ReturnType<typeof setTimeout>;\n\n private _inactivityTimeout?: number;\n private _inactivityTimeoutId?: ReturnType<typeof setTimeout>;\n private _lastActivityTimestamp: number = 0;\n private _inactivityResetDelay: number = 5000; // minimum time in ms between activities before timer is reset\n\n constructor(config: SessionManagerConfig) {\n this._idGenerator = config.sessionIdGenerator;\n this._store = config.sessionStore;\n this._maxDuration = config.maxDuration;\n this._inactivityTimeout = config.inactivityTimeout;\n this._observers = [];\n }\n\n async start(): Promise<void> {\n this._session = await this._store.get();\n if (!this._session) {\n this._session = await this.startSession();\n }\n this.resetTimers();\n }\n\n addObserver(observer: SessionObserver): void {\n this._observers.push(observer);\n }\n\n getSessionId(): string | null {\n return this.getSession().id;\n }\n\n getSession(): Session {\n if (!this._session) {\n this._session = this.startSession();\n this.resetTimers();\n }\n\n if (this._inactivityTimeout) {\n if (\n Date.now() - this._lastActivityTimestamp >\n this._inactivityResetDelay\n ) {\n this.resetInactivityTimer();\n this._lastActivityTimestamp = Date.now();\n }\n }\n\n return this._session;\n }\n\n shutdown(): void {\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n }\n\n private startSession(): Session {\n const sessionId = this._idGenerator.generateSessionId();\n\n const session: Session = {\n id: sessionId,\n startTimestamp: Date.now(),\n };\n\n // this is async call, but we don't wait for it\n void this._store.save(session);\n\n for (const observer of this._observers) {\n observer.onSessionStarted(session, this._session ?? undefined);\n }\n\n this._session = session;\n\n return session;\n }\n\n private endSession(): void {\n if (this._session) {\n for (const observer of this._observers) {\n observer.onSessionEnded(this._session);\n }\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n this._inactivityTimeoutId = undefined;\n }\n }\n\n private resetSession(): void {\n this.endSession();\n this.startSession();\n this.resetTimers();\n }\n\n private resetTimers() {\n this.resetInactivityTimer();\n this.resetMaxDurationTimer();\n }\n\n private resetInactivityTimer() {\n if (!this._inactivityTimeout) {\n return;\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n this._inactivityTimeoutId = setTimeout(() => {\n this.resetSession();\n }, this._inactivityTimeout * 1000);\n }\n\n private resetMaxDurationTimer() {\n if (!this._maxDuration || !this._session) {\n return;\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n\n const timeoutIn =\n this._maxDuration * 1000 - (Date.now() - this._session?.startTimestamp);\n\n this._maxDurationTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n}\n"]}
1
+ {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../src/SessionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,MAAM,e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AE;YAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SessionIdGenerator } from './types/SessionIdGenerator';\nimport type { Session } from './types/Session';\nimport type { SessionProvider } from './types/SessionProvider';\nimport type { SessionObserver } from './types/SessionObserver';\nimport type { SessionStore } from './types/SessionStore';\nimport type { SessionPublisher } from './types/SessionPublisher';\n\nconst MAX_DURATION_MS = 2147483647; // max setTimeout value in milliseconds (~24.8 days)\nexport interface SessionManagerConfig {\n /** Class responsible for generating a session ID */\n sessionIdGenerator: SessionIdGenerator;\n /** Class responsible for storing session data over multiple page loads. */\n sessionStore: SessionStore;\n /** Maximum duration of a session in seconds */\n maxDuration?: number;\n /** Maximum time without a user activity after which a session should be expired, in seconds */\n inactivityTimeout?: number;\n}\n\n/**\n * SessionManager is responsible for managing the active session including starting,\n * resetting, and persisting.\n */\nexport class SessionManager implements SessionProvider, SessionPublisher {\n private _session: Session | null | undefined;\n private _idGenerator: SessionIdGenerator;\n private _store: SessionStore;\n private _observers: SessionObserver[];\n\n private _maxDuration?: number;\n private _maxDurationTimeoutId?: ReturnType<typeof setTimeout>;\n\n private _inactivityTimeout?: number;\n private _inactivityTimeoutId?: ReturnType<typeof setTimeout>;\n private _lastActivityTimestamp: number = 0;\n private _inactivityResetDelay: number = 5000; // minimum time in ms between activities before timer is reset\n\n constructor(config: SessionManagerConfig) {\n this._idGenerator = config.sessionIdGenerator;\n this._store = config.sessionStore;\n this._maxDuration = config.maxDuration;\n this._inactivityTimeout = config.inactivityTimeout;\n this._observers = [];\n }\n\n async start(): Promise<void> {\n this._session = await this._store.get();\n if (!this._session) {\n this._session = await this.startSession();\n }\n this.resetTimers();\n }\n\n addObserver(observer: SessionObserver): void {\n this._observers.push(observer);\n }\n\n getSessionId(): string | null {\n return this.getSession().id;\n }\n\n getSession(): Session {\n if (!this._session) {\n this._session = this.startSession();\n this.resetTimers();\n }\n\n if (this._inactivityTimeout) {\n if (\n Date.now() - this._lastActivityTimestamp >\n this._inactivityResetDelay\n ) {\n this.resetInactivityTimer();\n this._lastActivityTimestamp = Date.now();\n }\n }\n\n return this._session;\n }\n\n shutdown(): void {\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n }\n\n private startSession(): Session {\n const sessionId = this._idGenerator.generateSessionId();\n\n const session: Session = {\n id: sessionId,\n startTimestamp: Date.now(),\n };\n\n // this is async call, but we don't wait for it\n void this._store.save(session);\n\n for (const observer of this._observers) {\n observer.onSessionStarted(session, this._session ?? undefined);\n }\n\n this._session = session;\n\n return session;\n }\n\n private endSession(): void {\n if (this._session) {\n for (const observer of this._observers) {\n observer.onSessionEnded(this._session);\n }\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n this._inactivityTimeoutId = undefined;\n }\n }\n\n private resetSession(): void {\n this.endSession();\n this.startSession();\n this.resetTimers();\n }\n\n private resetTimers() {\n this.resetInactivityTimer();\n this.resetMaxDurationTimer();\n }\n\n private resetInactivityTimer() {\n if (!this._inactivityTimeout) {\n return;\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n const timeoutIn = Math.min(this._inactivityTimeout * 1000, MAX_DURATION_MS);\n this._inactivityTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n\n private resetMaxDurationTimer() {\n if (!this._maxDuration || !this._session) {\n return;\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n\n const timeoutIn = Math.max(\n 0, // a backgrounded tab can cause a negative timeout value, so we use 0 to trigger session reset immediately on resume of the tab\n Math.min(\n this._maxDuration * 1000 - (Date.now() - this._session.startTimestamp),\n MAX_DURATION_MS\n )\n );\n\n this._maxDurationTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.215.0";
1
+ export declare const VERSION = "0.217.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -3,5 +3,5 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  // this is autogenerated file, see scripts/version-update.js
6
- export const VERSION = '0.215.0';
6
+ export const VERSION = '0.217.0';
7
7
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.215.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.217.0';\n"]}
@@ -5,6 +5,7 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SessionManager = void 0;
8
+ const MAX_DURATION_MS = 2147483647; // max setTimeout value in milliseconds (~24.8 days)
8
9
  /**
9
10
  * SessionManager is responsible for managing the active session including starting,
10
11
  * resetting, and persisting.
@@ -103,9 +104,10 @@ class SessionManager {
103
104
  if (this._inactivityTimeoutId) {
104
105
  clearTimeout(this._inactivityTimeoutId);
105
106
  }
107
+ const timeoutIn = Math.min(this._inactivityTimeout * 1000, MAX_DURATION_MS);
106
108
  this._inactivityTimeoutId = setTimeout(() => {
107
109
  this.resetSession();
108
- }, this._inactivityTimeout * 1000);
110
+ }, timeoutIn);
109
111
  }
110
112
  resetMaxDurationTimer() {
111
113
  if (!this._maxDuration || !this._session) {
@@ -114,7 +116,8 @@ class SessionManager {
114
116
  if (this._maxDurationTimeoutId) {
115
117
  clearTimeout(this._maxDurationTimeoutId);
116
118
  }
117
- const timeoutIn = this._maxDuration * 1000 - (Date.now() - this._session?.startTimestamp);
119
+ const timeoutIn = Math.max(0, // a backgrounded tab can cause a negative timeout value, so we use 0 to trigger session reset immediately on resume of the tab
120
+ Math.min(this._maxDuration * 1000 - (Date.now() - this._session.startTimestamp), MAX_DURATION_MS));
118
121
  this._maxDurationTimeoutId = setTimeout(() => {
119
122
  this.resetSession();
120
123
  }, timeoutIn);
@@ -1 +1 @@
1
- {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../src/SessionManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoBH;;;GAGG;AACH,MAAa,cAAc;IACjB,QAAQ,CAA6B;IACrC,YAAY,CAAqB;IACjC,MAAM,CAAe;IACrB,UAAU,CAAoB;IAE9B,YAAY,CAAU;IACtB,qBAAqB,CAAiC;IAEtD,kBAAkB,CAAU;IAC5B,oBAAoB,CAAiC;IACrD,sBAAsB,GAAW,CAAC,CAAC;IACnC,qBAAqB,GAAW,IAAI,CAAC,CAAC,8DAA8D;IAE5G,YAAY,MAA4B;QACtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,kBAAkB,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;QAClC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,QAAQ,GAAG,M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AAqB;QAC3B,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YACxC,OAAO;SACR;QAED,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC9B,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;SAC1C;QAED,MAAM,SAAS,GACb,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAE1E,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC;CACF;AA7ID,wCA6IC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SessionIdGenerator } from './types/SessionIdGenerator';\nimport type { Session } from './types/Session';\nimport type { SessionProvider } from './types/SessionProvider';\nimport type { SessionObserver } from './types/SessionObserver';\nimport type { SessionStore } from './types/SessionStore';\nimport type { SessionPublisher } from './types/SessionPublisher';\n\nexport interface SessionManagerConfig {\n /** Class responsible for generating a session ID */\n sessionIdGenerator: SessionIdGenerator;\n /** Class responsible for storing session data over multiple page loads. */\n sessionStore: SessionStore;\n /** Maximum duration of a session in seconds */\n maxDuration?: number;\n /** Maximum time without a user activity after which a session should be expired, in seconds */\n inactivityTimeout?: number;\n}\n\n/**\n * SessionManager is responsible for managing the active session including starting,\n * resetting, and persisting.\n */\nexport class SessionManager implements SessionProvider, SessionPublisher {\n private _session: Session | null | undefined;\n private _idGenerator: SessionIdGenerator;\n private _store: SessionStore;\n private _observers: SessionObserver[];\n\n private _maxDuration?: number;\n private _maxDurationTimeoutId?: ReturnType<typeof setTimeout>;\n\n private _inactivityTimeout?: number;\n private _inactivityTimeoutId?: ReturnType<typeof setTimeout>;\n private _lastActivityTimestamp: number = 0;\n private _inactivityResetDelay: number = 5000; // minimum time in ms between activities before timer is reset\n\n constructor(config: SessionManagerConfig) {\n this._idGenerator = config.sessionIdGenerator;\n this._store = config.sessionStore;\n this._maxDuration = config.maxDuration;\n this._inactivityTimeout = config.inactivityTimeout;\n this._observers = [];\n }\n\n async start(): Promise<void> {\n this._session = await this._store.get();\n if (!this._session) {\n this._session = await this.startSession();\n }\n this.resetTimers();\n }\n\n addObserver(observer: SessionObserver): void {\n this._observers.push(observer);\n }\n\n getSessionId(): string | null {\n return this.getSession().id;\n }\n\n getSession(): Session {\n if (!this._session) {\n this._session = this.startSession();\n this.resetTimers();\n }\n\n if (this._inactivityTimeout) {\n if (\n Date.now() - this._lastActivityTimestamp >\n this._inactivityResetDelay\n ) {\n this.resetInactivityTimer();\n this._lastActivityTimestamp = Date.now();\n }\n }\n\n return this._session;\n }\n\n shutdown(): void {\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n }\n\n private startSession(): Session {\n const sessionId = this._idGenerator.generateSessionId();\n\n const session: Session = {\n id: sessionId,\n startTimestamp: Date.now(),\n };\n\n // this is async call, but we don't wait for it\n void this._store.save(session);\n\n for (const observer of this._observers) {\n observer.onSessionStarted(session, this._session ?? undefined);\n }\n\n this._session = session;\n\n return session;\n }\n\n private endSession(): void {\n if (this._session) {\n for (const observer of this._observers) {\n observer.onSessionEnded(this._session);\n }\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n this._inactivityTimeoutId = undefined;\n }\n }\n\n private resetSession(): void {\n this.endSession();\n this.startSession();\n this.resetTimers();\n }\n\n private resetTimers() {\n this.resetInactivityTimer();\n this.resetMaxDurationTimer();\n }\n\n private resetInactivityTimer() {\n if (!this._inactivityTimeout) {\n return;\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n this._inactivityTimeoutId = setTimeout(() => {\n this.resetSession();\n }, this._inactivityTimeout * 1000);\n }\n\n private resetMaxDurationTimer() {\n if (!this._maxDuration || !this._session) {\n return;\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n\n const timeoutIn =\n this._maxDuration * 1000 - (Date.now() - this._session?.startTimestamp);\n\n this._maxDurationTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n}\n"]}
1
+ {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../src/SessionManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,MAAM,eAAe,GAAG,UAAU,CAAC,CAAC,oDAAoD;AAYxF;;;GAGG;AACH,MAAa,cAAc;IACjB,QAAQ,CAA6B;IACrC,YAAY,CAAqB;IACjC,MAAM,CAAe;IACrB,UAAU,CAAoB;IAE9B,YAAY,CAAU;IACtB,qBAAqB,CAAiC;IAEtD,kBAAkB,CAAU;IAC5B,oBAAoB,CAAiC;IACrD,sBAAsB,GAAW,CAAC,CAAC;IACnC,qBAAqB,GAAW,IAAI,CAAC,CAAC,8DAA8D;IAE5G,YAAY,MAA4B;QACtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,kBAAkB,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;QAClC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;SAC3C;QACD,IAAI,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;QAED,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC9B,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;SAC1C;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CACxB,CAAC,EAAE,+HAA+H;QAClI,IAAI,CAAC,GAAG,CACN,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EACtE,eAAe,CAChB,CACF,CAAC;QAEF,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC;CACF;AAnJD,wCAmJC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SessionIdGenerator } from './types/SessionIdGenerator';\nimport type { Session } from './types/Session';\nimport type { SessionProvider } from './types/SessionProvider';\nimport type { SessionObserver } from './types/SessionObserver';\nimport type { SessionStore } from './types/SessionStore';\nimport type { SessionPublisher } from './types/SessionPublisher';\n\nconst MAX_DURATION_MS = 2147483647; // max setTimeout value in milliseconds (~24.8 days)\nexport interface SessionManagerConfig {\n /** Class responsible for generating a session ID */\n sessionIdGenerator: SessionIdGenerator;\n /** Class responsible for storing session data over multiple page loads. */\n sessionStore: SessionStore;\n /** Maximum duration of a session in seconds */\n maxDuration?: number;\n /** Maximum time without a user activity after which a session should be expired, in seconds */\n inactivityTimeout?: number;\n}\n\n/**\n * SessionManager is responsible for managing the active session including starting,\n * resetting, and persisting.\n */\nexport class SessionManager implements SessionProvider, SessionPublisher {\n private _session: Session | null | undefined;\n private _idGenerator: SessionIdGenerator;\n private _store: SessionStore;\n private _observers: SessionObserver[];\n\n private _maxDuration?: number;\n private _maxDurationTimeoutId?: ReturnType<typeof setTimeout>;\n\n private _inactivityTimeout?: number;\n private _inactivityTimeoutId?: ReturnType<typeof setTimeout>;\n private _lastActivityTimestamp: number = 0;\n private _inactivityResetDelay: number = 5000; // minimum time in ms between activities before timer is reset\n\n constructor(config: SessionManagerConfig) {\n this._idGenerator = config.sessionIdGenerator;\n this._store = config.sessionStore;\n this._maxDuration = config.maxDuration;\n this._inactivityTimeout = config.inactivityTimeout;\n this._observers = [];\n }\n\n async start(): Promise<void> {\n this._session = await this._store.get();\n if (!this._session) {\n this._session = await this.startSession();\n }\n this.resetTimers();\n }\n\n addObserver(observer: SessionObserver): void {\n this._observers.push(observer);\n }\n\n getSessionId(): string | null {\n return this.getSession().id;\n }\n\n getSession(): Session {\n if (!this._session) {\n this._session = this.startSession();\n this.resetTimers();\n }\n\n if (this._inactivityTimeout) {\n if (\n Date.now() - this._lastActivityTimestamp >\n this._inactivityResetDelay\n ) {\n this.resetInactivityTimer();\n this._lastActivityTimestamp = Date.now();\n }\n }\n\n return this._session;\n }\n\n shutdown(): void {\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n }\n\n private startSession(): Session {\n const sessionId = this._idGenerator.generateSessionId();\n\n const session: Session = {\n id: sessionId,\n startTimestamp: Date.now(),\n };\n\n // this is async call, but we don't wait for it\n void this._store.save(session);\n\n for (const observer of this._observers) {\n observer.onSessionStarted(session, this._session ?? undefined);\n }\n\n this._session = session;\n\n return session;\n }\n\n private endSession(): void {\n if (this._session) {\n for (const observer of this._observers) {\n observer.onSessionEnded(this._session);\n }\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n this._inactivityTimeoutId = undefined;\n }\n }\n\n private resetSession(): void {\n this.endSession();\n this.startSession();\n this.resetTimers();\n }\n\n private resetTimers() {\n this.resetInactivityTimer();\n this.resetMaxDurationTimer();\n }\n\n private resetInactivityTimer() {\n if (!this._inactivityTimeout) {\n return;\n }\n\n if (this._inactivityTimeoutId) {\n clearTimeout(this._inactivityTimeoutId);\n }\n\n const timeoutIn = Math.min(this._inactivityTimeout * 1000, MAX_DURATION_MS);\n this._inactivityTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n\n private resetMaxDurationTimer() {\n if (!this._maxDuration || !this._session) {\n return;\n }\n\n if (this._maxDurationTimeoutId) {\n clearTimeout(this._maxDurationTimeoutId);\n }\n\n const timeoutIn = Math.max(\n 0, // a backgrounded tab can cause a negative timeout value, so we use 0 to trigger session reset immediately on resume of the tab\n Math.min(\n this._maxDuration * 1000 - (Date.now() - this._session.startTimestamp),\n MAX_DURATION_MS\n )\n );\n\n this._maxDurationTimeoutId = setTimeout(() => {\n this.resetSession();\n }, timeoutIn);\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.215.0";
1
+ export declare const VERSION = "0.217.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -6,5 +6,5 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.VERSION = void 0;
8
8
  // this is autogenerated file, see scripts/version-update.js
9
- exports.VERSION = '0.215.0';
9
+ exports.VERSION = '0.217.0';
10
10
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.215.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.217.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/web-common",
3
- "version": "0.215.0",
3
+ "version": "0.217.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -63,14 +63,14 @@
63
63
  "@opentelemetry/api": ">=1.4.0 <1.10.0"
64
64
  },
65
65
  "dependencies": {
66
- "@opentelemetry/sdk-logs": "0.215.0",
67
- "@opentelemetry/sdk-trace-base": "2.7.0",
66
+ "@opentelemetry/sdk-logs": "0.217.0",
67
+ "@opentelemetry/sdk-trace-base": "2.7.1",
68
68
  "@opentelemetry/semantic-conventions": "^1.29.0"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@babel/core": "7.27.1",
72
72
  "@opentelemetry/api": "1.9.1",
73
- "@opentelemetry/api-logs": "0.215.0",
73
+ "@opentelemetry/api-logs": "0.217.0",
74
74
  "@types/mocha": "10.0.10",
75
75
  "@types/node": "18.19.130",
76
76
  "@types/sinon": "17.0.4",
@@ -91,5 +91,5 @@
91
91
  "webpack": "5.104.1",
92
92
  "webpack-cli": "7.0.2"
93
93
  },
94
- "gitHead": "a0476eef3cb973bfcc0c2e41f868dd7b484c2ed8"
94
+ "gitHead": "74cde1b674508ccc0ed2601ac43a80ff2d35114c"
95
95
  }