@opentelemetry/web-common 0.205.0 → 0.207.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.
Files changed (101) hide show
  1. package/README.md +95 -0
  2. package/build/esm/DefaultIdGenerator.d.ts +5 -0
  3. package/build/esm/DefaultIdGenerator.js +32 -0
  4. package/build/esm/DefaultIdGenerator.js.map +1 -0
  5. package/build/esm/LocalStorageSessionStore.d.ts +7 -0
  6. package/build/esm/LocalStorageSessionStore.js +36 -0
  7. package/build/esm/LocalStorageSessionStore.js.map +1 -0
  8. package/build/esm/SessionManager.d.ts +45 -0
  9. package/build/esm/SessionManager.js +131 -0
  10. package/build/esm/SessionManager.js.map +1 -0
  11. package/build/esm/index.d.ts +6 -1
  12. package/build/esm/index.js +1 -1
  13. package/build/esm/index.js.map +1 -1
  14. package/build/esm/types/Session.d.ts +5 -0
  15. package/build/esm/types/Session.js +17 -0
  16. package/build/esm/types/Session.js.map +1 -0
  17. package/build/esm/types/SessionIdGenerator.d.ts +4 -0
  18. package/build/esm/types/SessionIdGenerator.js +17 -0
  19. package/build/esm/types/SessionIdGenerator.js.map +1 -0
  20. package/build/esm/types/SessionObserver.d.ts +6 -0
  21. package/build/esm/types/SessionObserver.js +17 -0
  22. package/build/esm/types/SessionObserver.js.map +1 -0
  23. package/build/esm/types/SessionPublisher.d.ts +5 -0
  24. package/build/esm/types/SessionPublisher.js +17 -0
  25. package/build/esm/types/SessionPublisher.js.map +1 -0
  26. package/build/esm/types/SessionStore.d.ts +6 -0
  27. package/build/esm/types/SessionStore.js +17 -0
  28. package/build/esm/types/SessionStore.js.map +1 -0
  29. package/build/esm/utils.d.ts +6 -0
  30. package/build/esm/utils.js +13 -0
  31. package/build/esm/utils.js.map +1 -1
  32. package/build/esm/version.d.ts +1 -1
  33. package/build/esm/version.js +1 -1
  34. package/build/esm/version.js.map +1 -1
  35. package/build/esnext/DefaultIdGenerator.d.ts +5 -0
  36. package/build/esnext/DefaultIdGenerator.js +32 -0
  37. package/build/esnext/DefaultIdGenerator.js.map +1 -0
  38. package/build/esnext/LocalStorageSessionStore.d.ts +7 -0
  39. package/build/esnext/LocalStorageSessionStore.js +36 -0
  40. package/build/esnext/LocalStorageSessionStore.js.map +1 -0
  41. package/build/esnext/SessionManager.d.ts +45 -0
  42. package/build/esnext/SessionManager.js +131 -0
  43. package/build/esnext/SessionManager.js.map +1 -0
  44. package/build/esnext/index.d.ts +6 -1
  45. package/build/esnext/index.js +1 -1
  46. package/build/esnext/index.js.map +1 -1
  47. package/build/esnext/types/Session.d.ts +5 -0
  48. package/build/esnext/types/Session.js +17 -0
  49. package/build/esnext/types/Session.js.map +1 -0
  50. package/build/esnext/types/SessionIdGenerator.d.ts +4 -0
  51. package/build/esnext/types/SessionIdGenerator.js +17 -0
  52. package/build/esnext/types/SessionIdGenerator.js.map +1 -0
  53. package/build/esnext/types/SessionObserver.d.ts +6 -0
  54. package/build/esnext/types/SessionObserver.js +17 -0
  55. package/build/esnext/types/SessionObserver.js.map +1 -0
  56. package/build/esnext/types/SessionPublisher.d.ts +5 -0
  57. package/build/esnext/types/SessionPublisher.js +17 -0
  58. package/build/esnext/types/SessionPublisher.js.map +1 -0
  59. package/build/esnext/types/SessionStore.d.ts +6 -0
  60. package/build/esnext/types/SessionStore.js +17 -0
  61. package/build/esnext/types/SessionStore.js.map +1 -0
  62. package/build/esnext/utils.d.ts +6 -0
  63. package/build/esnext/utils.js +13 -0
  64. package/build/esnext/utils.js.map +1 -1
  65. package/build/esnext/version.d.ts +1 -1
  66. package/build/esnext/version.js +1 -1
  67. package/build/esnext/version.js.map +1 -1
  68. package/build/src/DefaultIdGenerator.d.ts +5 -0
  69. package/build/src/DefaultIdGenerator.js +36 -0
  70. package/build/src/DefaultIdGenerator.js.map +1 -0
  71. package/build/src/LocalStorageSessionStore.d.ts +7 -0
  72. package/build/src/LocalStorageSessionStore.js +40 -0
  73. package/build/src/LocalStorageSessionStore.js.map +1 -0
  74. package/build/src/SessionManager.d.ts +45 -0
  75. package/build/src/SessionManager.js +135 -0
  76. package/build/src/SessionManager.js.map +1 -0
  77. package/build/src/index.d.ts +6 -1
  78. package/build/src/index.js +4 -1
  79. package/build/src/index.js.map +1 -1
  80. package/build/src/types/Session.d.ts +5 -0
  81. package/build/src/types/Session.js +18 -0
  82. package/build/src/types/Session.js.map +1 -0
  83. package/build/src/types/SessionIdGenerator.d.ts +4 -0
  84. package/build/src/types/SessionIdGenerator.js +18 -0
  85. package/build/src/types/SessionIdGenerator.js.map +1 -0
  86. package/build/src/types/SessionObserver.d.ts +6 -0
  87. package/build/src/types/SessionObserver.js +18 -0
  88. package/build/src/types/SessionObserver.js.map +1 -0
  89. package/build/src/types/SessionPublisher.d.ts +5 -0
  90. package/build/src/types/SessionPublisher.js +18 -0
  91. package/build/src/types/SessionPublisher.js.map +1 -0
  92. package/build/src/types/SessionStore.d.ts +6 -0
  93. package/build/src/types/SessionStore.js +18 -0
  94. package/build/src/types/SessionStore.js.map +1 -0
  95. package/build/src/utils.d.ts +6 -0
  96. package/build/src/utils.js +17 -1
  97. package/build/src/utils.js.map +1 -1
  98. package/build/src/version.d.ts +1 -1
  99. package/build/src/version.js +1 -1
  100. package/build/src/version.js.map +1 -1
  101. package/package.json +7 -11
@@ -14,5 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // this is autogenerated file, see scripts/version-update.js
17
- export const VERSION = '0.205.0';
17
+ export const VERSION = '0.207.0';
18
18
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.205.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.207.0';\n"]}
@@ -0,0 +1,5 @@
1
+ import { SessionIdGenerator } from './types/SessionIdGenerator';
2
+ export declare class DefaultIdGenerator implements SessionIdGenerator {
3
+ generateSessionId: () => string;
4
+ }
5
+ //# sourceMappingURL=DefaultIdGenerator.d.ts.map
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export class DefaultIdGenerator {
17
+ generateSessionId = getIdGenerator(16);
18
+ }
19
+ const SHARED_CHAR_CODES_ARRAY = Array(32);
20
+ function getIdGenerator(bytes) {
21
+ return function generateId() {
22
+ for (let i = 0; i < bytes * 2; i++) {
23
+ SHARED_CHAR_CODES_ARRAY[i] = Math.floor(Math.random() * 16) + 48;
24
+ // valid hex characters in the range 48-57 and 97-102
25
+ if (SHARED_CHAR_CODES_ARRAY[i] >= 58) {
26
+ SHARED_CHAR_CODES_ARRAY[i] += 39;
27
+ }
28
+ }
29
+ return String.fromCharCode.apply(null, SHARED_CHAR_CODES_ARRAY.slice(0, bytes * 2));
30
+ };
31
+ }
32
+ //# sourceMappingURL=DefaultIdGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultIdGenerator.js","sourceRoot":"","sources":["../../src/DefaultIdGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,OAAO,kBAAkB;IAC7B,iBAAiB,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC;CACxC;AAED,MAAM,uBAAuB,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;AAC1C,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,SAAS,UAAU;QACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YAClC,uBAAuB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;YACjE,qDAAqD;YACrD,IAAI,uBAAuB,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE;gBACpC,uBAAuB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAClC;SACF;QACD,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,CAC9B,IAAI,EACJ,uBAAuB,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAC5C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SessionIdGenerator } from './types/SessionIdGenerator';\n\nexport class DefaultIdGenerator implements SessionIdGenerator {\n generateSessionId = getIdGenerator(16);\n}\n\nconst SHARED_CHAR_CODES_ARRAY = Array(32);\nfunction getIdGenerator(bytes: number): () => string {\n return function generateId() {\n for (let i = 0; i < bytes * 2; i++) {\n SHARED_CHAR_CODES_ARRAY[i] = Math.floor(Math.random() * 16) + 48;\n // valid hex characters in the range 48-57 and 97-102\n if (SHARED_CHAR_CODES_ARRAY[i] >= 58) {\n SHARED_CHAR_CODES_ARRAY[i] += 39;\n }\n }\n return String.fromCharCode.apply(\n null,\n SHARED_CHAR_CODES_ARRAY.slice(0, bytes * 2)\n );\n };\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import { Session } from './types/Session';
2
+ import { SessionStore } from './types/SessionStore';
3
+ export declare class LocalStorageSessionStore implements SessionStore {
4
+ save(session: Session): Promise<void>;
5
+ get(): Promise<Session | null>;
6
+ }
7
+ //# sourceMappingURL=LocalStorageSessionStore.d.ts.map
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ const SESSION_STORAGE_KEY = 'opentelemetry-session';
17
+ export class LocalStorageSessionStore {
18
+ save(session) {
19
+ if (typeof localStorage === 'undefined') {
20
+ return Promise.resolve();
21
+ }
22
+ localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(session));
23
+ return Promise.resolve();
24
+ }
25
+ get() {
26
+ if (typeof localStorage === 'undefined') {
27
+ return Promise.resolve(null);
28
+ }
29
+ const sessionData = localStorage.getItem(SESSION_STORAGE_KEY);
30
+ if (sessionData) {
31
+ return Promise.resolve(JSON.parse(sessionData));
32
+ }
33
+ return Promise.resolve(null);
34
+ }
35
+ }
36
+ //# sourceMappingURL=LocalStorageSessionStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalStorageSessionStore.js","sourceRoot":"","sources":["../../src/LocalStorageSessionStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAEpD,MAAM,OAAO,wBAAwB;IACnC,IAAI,CAAC,OAAgB;QACnB,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;YACvC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC1B;QAED,YAAY,CAAC,OAAO,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAEnE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,GAAG;QACD,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;YACvC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC9B;QAED,MAAM,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAC9D,IAAI,WAAW,EAAE;YACf,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAY,CAAC,CAAC;SAC5D;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Session } from './types/Session';\nimport { SessionStore } from './types/SessionStore';\n\nconst SESSION_STORAGE_KEY = 'opentelemetry-session';\n\nexport class LocalStorageSessionStore implements SessionStore {\n save(session: Session): Promise<void> {\n if (typeof localStorage === 'undefined') {\n return Promise.resolve();\n }\n\n localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(session));\n\n return Promise.resolve();\n }\n\n get(): Promise<Session | null> {\n if (typeof localStorage === 'undefined') {\n return Promise.resolve(null);\n }\n\n const sessionData = localStorage.getItem(SESSION_STORAGE_KEY);\n if (sessionData) {\n return Promise.resolve(JSON.parse(sessionData) as Session);\n }\n return Promise.resolve(null);\n }\n}\n"]}
@@ -0,0 +1,45 @@
1
+ import { SessionIdGenerator } from './types/SessionIdGenerator';
2
+ import { Session } from './types/Session';
3
+ import { SessionProvider } from './types/SessionProvider';
4
+ import { SessionObserver } from './types/SessionObserver';
5
+ import { SessionStore } from './types/SessionStore';
6
+ import { SessionPublisher } from './types/SessionPublisher';
7
+ export interface SessionManagerConfig {
8
+ /** Class responsible for generating a session ID */
9
+ sessionIdGenerator: SessionIdGenerator;
10
+ /** Class responsible for storing session data over multiple page loads. */
11
+ sessionStore: SessionStore;
12
+ /** Maximum duration of a session in seconds */
13
+ maxDuration?: number;
14
+ /** Maximum time without a user activity after which a session should be expired, in seconds */
15
+ inactivityTimeout?: number;
16
+ }
17
+ /**
18
+ * SessionManager is responsible for managing the active session including starting,
19
+ * resetting, and persisting.
20
+ */
21
+ export declare class SessionManager implements SessionProvider, SessionPublisher {
22
+ private _session;
23
+ private _idGenerator;
24
+ private _store;
25
+ private _observers;
26
+ private _maxDuration?;
27
+ private _maxDurationTimeoutId?;
28
+ private _inactivityTimeout?;
29
+ private _inactivityTimeoutId?;
30
+ private _lastActivityTimestamp;
31
+ private _inactivityResetDelay;
32
+ constructor(config: SessionManagerConfig);
33
+ start(): Promise<void>;
34
+ addObserver(observer: SessionObserver): void;
35
+ getSessionId(): string | null;
36
+ getSession(): Session;
37
+ shutdown(): void;
38
+ private startSession;
39
+ private endSession;
40
+ private resetSession;
41
+ private resetTimers;
42
+ private resetInactivityTimer;
43
+ private resetMaxDurationTimer;
44
+ }
45
+ //# sourceMappingURL=SessionManager.d.ts.map
@@ -0,0 +1,131 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * SessionManager is responsible for managing the active session including starting,
18
+ * resetting, and persisting.
19
+ */
20
+ export class SessionManager {
21
+ _session;
22
+ _idGenerator;
23
+ _store;
24
+ _observers;
25
+ _maxDuration;
26
+ _maxDurationTimeoutId;
27
+ _inactivityTimeout;
28
+ _inactivityTimeoutId;
29
+ _lastActivityTimestamp = 0;
30
+ _inactivityResetDelay = 5000; // minimum time in ms between activities before timer is reset
31
+ constructor(config) {
32
+ this._idGenerator = config.sessionIdGenerator;
33
+ this._store = config.sessionStore;
34
+ this._maxDuration = config.maxDuration;
35
+ this._inactivityTimeout = config.inactivityTimeout;
36
+ this._observers = [];
37
+ }
38
+ async start() {
39
+ this._session = await this._store.get();
40
+ if (!this._session) {
41
+ this._session = await this.startSession();
42
+ }
43
+ this.resetTimers();
44
+ }
45
+ addObserver(observer) {
46
+ this._observers.push(observer);
47
+ }
48
+ getSessionId() {
49
+ return this.getSession().id;
50
+ }
51
+ getSession() {
52
+ if (!this._session) {
53
+ this._session = this.startSession();
54
+ this.resetTimers();
55
+ }
56
+ if (this._inactivityTimeout) {
57
+ if (Date.now() - this._lastActivityTimestamp >
58
+ this._inactivityResetDelay) {
59
+ this.resetInactivityTimer();
60
+ this._lastActivityTimestamp = Date.now();
61
+ }
62
+ }
63
+ return this._session;
64
+ }
65
+ shutdown() {
66
+ if (this._inactivityTimeoutId) {
67
+ clearTimeout(this._inactivityTimeoutId);
68
+ }
69
+ if (this._maxDurationTimeoutId) {
70
+ clearTimeout(this._maxDurationTimeoutId);
71
+ }
72
+ }
73
+ startSession() {
74
+ const sessionId = this._idGenerator.generateSessionId();
75
+ const session = {
76
+ id: sessionId,
77
+ startTimestamp: Date.now(),
78
+ };
79
+ // this is async call, but we don't wait for it
80
+ void this._store.save(session);
81
+ for (const observer of this._observers) {
82
+ observer.onSessionStarted(session, this._session ?? undefined);
83
+ }
84
+ this._session = session;
85
+ return session;
86
+ }
87
+ endSession() {
88
+ if (this._session) {
89
+ for (const observer of this._observers) {
90
+ observer.onSessionEnded(this._session);
91
+ }
92
+ }
93
+ if (this._inactivityTimeoutId) {
94
+ clearTimeout(this._inactivityTimeoutId);
95
+ this._inactivityTimeoutId = undefined;
96
+ }
97
+ }
98
+ resetSession() {
99
+ this.endSession();
100
+ this.startSession();
101
+ this.resetTimers();
102
+ }
103
+ resetTimers() {
104
+ this.resetInactivityTimer();
105
+ this.resetMaxDurationTimer();
106
+ }
107
+ resetInactivityTimer() {
108
+ if (!this._inactivityTimeout) {
109
+ return;
110
+ }
111
+ if (this._inactivityTimeoutId) {
112
+ clearTimeout(this._inactivityTimeoutId);
113
+ }
114
+ this._inactivityTimeoutId = setTimeout(() => {
115
+ this.resetSession();
116
+ }, this._inactivityTimeout * 1000);
117
+ }
118
+ resetMaxDurationTimer() {
119
+ if (!this._maxDuration || !this._session) {
120
+ return;
121
+ }
122
+ if (this._maxDurationTimeoutId) {
123
+ clearTimeout(this._maxDurationTimeoutId);
124
+ }
125
+ const timeoutIn = this._maxDuration * 1000 - (Date.now() - this._session?.startTimestamp);
126
+ this._maxDurationTimeoutId = setTimeout(() => {
127
+ this.resetSession();
128
+ }, timeoutIn);
129
+ }
130
+ }
131
+ //# sourceMappingURL=SessionManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../src/SessionManager.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SessionIdGenerator } from './types/SessionIdGenerator';\nimport { Session } from './types/Session';\nimport { SessionProvider } from './types/SessionProvider';\nimport { SessionObserver } from './types/SessionObserver';\nimport { SessionStore } from './types/SessionStore';\nimport { 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,3 +1,8 @@
1
1
  export type { SessionProvider } from './types/SessionProvider';
2
- export { createSessionSpanProcessor, createSessionLogRecordProcessor, } from './utils';
2
+ export { createSessionSpanProcessor, createSessionLogRecordProcessor, createSessionManager, createDefaultSessionIdGenerator, createLocalStorageSessionStore, } from './utils';
3
+ export type { Session } from './types/Session';
4
+ export type { SessionIdGenerator } from './types/SessionIdGenerator';
5
+ export type { SessionPublisher } from './types/SessionPublisher';
6
+ export type { SessionObserver } from './types/SessionObserver';
7
+ export type { SessionStore } from './types/SessionStore';
3
8
  //# sourceMappingURL=index.d.ts.map
@@ -13,5 +13,5 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { createSessionSpanProcessor, createSessionLogRecordProcessor, } from './utils';
16
+ export { createSessionSpanProcessor, createSessionLogRecordProcessor, createSessionManager, createDefaultSessionIdGenerator, createLocalStorageSessionStore, } from './utils';
17
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type { SessionProvider } from './types/SessionProvider';\nexport {\n createSessionSpanProcessor,\n createSessionLogRecordProcessor,\n} from './utils';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,oBAAoB,EACpB,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type { SessionProvider } from './types/SessionProvider';\nexport {\n createSessionSpanProcessor,\n createSessionLogRecordProcessor,\n createSessionManager,\n createDefaultSessionIdGenerator,\n createLocalStorageSessionStore,\n} from './utils';\nexport type { Session } from './types/Session';\nexport type { SessionIdGenerator } from './types/SessionIdGenerator';\nexport type { SessionPublisher } from './types/SessionPublisher';\nexport type { SessionObserver } from './types/SessionObserver';\nexport type { SessionStore } from './types/SessionStore';\n"]}
@@ -0,0 +1,5 @@
1
+ export interface Session {
2
+ id: string;
3
+ startTimestamp: number;
4
+ }
5
+ //# sourceMappingURL=Session.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=Session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Session.js","sourceRoot":"","sources":["../../../src/types/Session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface Session {\n id: string;\n startTimestamp: number; // epoch milliseconds\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export interface SessionIdGenerator {
2
+ generateSessionId(): string;
3
+ }
4
+ //# sourceMappingURL=SessionIdGenerator.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=SessionIdGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionIdGenerator.js","sourceRoot":"","sources":["../../../src/types/SessionIdGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface SessionIdGenerator {\n generateSessionId(): string;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { Session } from './Session';
2
+ export interface SessionObserver {
3
+ onSessionStarted(newSession: Session, previousSession?: Session): void;
4
+ onSessionEnded(session: Session): void;
5
+ }
6
+ //# sourceMappingURL=SessionObserver.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=SessionObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionObserver.js","sourceRoot":"","sources":["../../../src/types/SessionObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Session } from './Session';\n\nexport interface SessionObserver {\n onSessionStarted(newSession: Session, previousSession?: Session): void;\n onSessionEnded(session: Session): void;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { SessionObserver } from './SessionObserver';
2
+ export interface SessionPublisher {
3
+ addObserver(observer: SessionObserver): void;
4
+ }
5
+ //# sourceMappingURL=SessionPublisher.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=SessionPublisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionPublisher.js","sourceRoot":"","sources":["../../../src/types/SessionPublisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SessionObserver } from './SessionObserver';\n\nexport interface SessionPublisher {\n addObserver(observer: SessionObserver): void;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { Session } from './Session';
2
+ export interface SessionStore {
3
+ save(session: Session): Promise<void>;
4
+ get(): Promise<Session | null>;
5
+ }
6
+ //# sourceMappingURL=SessionStore.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=SessionStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionStore.js","sourceRoot":"","sources":["../../../src/types/SessionStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Session } from './Session';\n\nexport interface SessionStore {\n save(session: Session): Promise<void>;\n get(): Promise<Session | null>;\n}\n"]}
@@ -1,6 +1,12 @@
1
1
  import { SessionProvider } from './types/SessionProvider';
2
2
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
3
3
  import { LogRecordProcessor } from '@opentelemetry/sdk-logs';
4
+ import { SessionManager, SessionManagerConfig } from './SessionManager';
5
+ import { SessionIdGenerator } from './types/SessionIdGenerator';
6
+ import { SessionStore } from './types/SessionStore';
4
7
  export declare function createSessionSpanProcessor(sessionProvider: SessionProvider): SpanProcessor;
5
8
  export declare function createSessionLogRecordProcessor(sessionProvider: SessionProvider): LogRecordProcessor;
9
+ export declare function createSessionManager(config: SessionManagerConfig): SessionManager;
10
+ export declare function createDefaultSessionIdGenerator(): SessionIdGenerator;
11
+ export declare function createLocalStorageSessionStore(): SessionStore;
6
12
  //# sourceMappingURL=utils.d.ts.map
@@ -15,10 +15,23 @@
15
15
  */
16
16
  import { SessionSpanProcessor } from './SessionSpanProcessor';
17
17
  import { SessionLogRecordProcessor } from './SessionLogRecordProcessor';
18
+ import { SessionManager } from './SessionManager';
19
+ import { DefaultIdGenerator } from './DefaultIdGenerator';
20
+ import { LocalStorageSessionStore } from './LocalStorageSessionStore';
18
21
  export function createSessionSpanProcessor(sessionProvider) {
19
22
  return new SessionSpanProcessor(sessionProvider);
20
23
  }
21
24
  export function createSessionLogRecordProcessor(sessionProvider) {
22
25
  return new SessionLogRecordProcessor(sessionProvider);
23
26
  }
27
+ export function createSessionManager(config) {
28
+ const manager = new SessionManager(config);
29
+ return manager;
30
+ }
31
+ export function createDefaultSessionIdGenerator() {
32
+ return new DefaultIdGenerator();
33
+ }
34
+ export function createLocalStorageSessionStore() {
35
+ return new LocalStorageSessionStore();
36
+ }
24
37
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,UAAU,0BAA0B,CACxC,eAAgC;IAEhC,OAAO,IAAI,oBAAoB,CAAC,eAAe,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,eAAgC;IAEhC,OAAO,IAAI,yBAAyB,CAAC,eAAe,CAAC,CAAC;AACxD,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SessionProvider } from './types/SessionProvider';\nimport { SpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport { SessionSpanProcessor } from './SessionSpanProcessor';\nimport { LogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { SessionLogRecordProcessor } from './SessionLogRecordProcessor';\n\nexport function createSessionSpanProcessor(\n sessionProvider: SessionProvider\n): SpanProcessor {\n return new SessionSpanProcessor(sessionProvider);\n}\n\nexport function createSessionLogRecordProcessor(\n sessionProvider: SessionProvider\n): LogRecordProcessor {\n return new SessionLogRecordProcessor(sessionProvider);\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAwB,MAAM,kBAAkB,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,UAAU,0BAA0B,CACxC,eAAgC;IAEhC,OAAO,IAAI,oBAAoB,CAAC,eAAe,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,eAAgC;IAEhC,OAAO,IAAI,yBAAyB,CAAC,eAAe,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,MAA4B;IAE5B,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,+BAA+B;IAC7C,OAAO,IAAI,kBAAkB,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,OAAO,IAAI,wBAAwB,EAAE,CAAC;AACxC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SessionProvider } from './types/SessionProvider';\nimport { SpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport { SessionSpanProcessor } from './SessionSpanProcessor';\nimport { LogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { SessionLogRecordProcessor } from './SessionLogRecordProcessor';\nimport { SessionManager, SessionManagerConfig } from './SessionManager';\nimport { SessionIdGenerator } from './types/SessionIdGenerator';\nimport { DefaultIdGenerator } from './DefaultIdGenerator';\nimport { SessionStore } from './types/SessionStore';\nimport { LocalStorageSessionStore } from './LocalStorageSessionStore';\n\nexport function createSessionSpanProcessor(\n sessionProvider: SessionProvider\n): SpanProcessor {\n return new SessionSpanProcessor(sessionProvider);\n}\n\nexport function createSessionLogRecordProcessor(\n sessionProvider: SessionProvider\n): LogRecordProcessor {\n return new SessionLogRecordProcessor(sessionProvider);\n}\n\nexport function createSessionManager(\n config: SessionManagerConfig\n): SessionManager {\n const manager = new SessionManager(config);\n return manager;\n}\n\nexport function createDefaultSessionIdGenerator(): SessionIdGenerator {\n return new DefaultIdGenerator();\n}\n\nexport function createLocalStorageSessionStore(): SessionStore {\n return new LocalStorageSessionStore();\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.205.0";
1
+ export declare const VERSION = "0.207.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -14,5 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // this is autogenerated file, see scripts/version-update.js
17
- export const VERSION = '0.205.0';
17
+ export const VERSION = '0.207.0';
18
18
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.205.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.207.0';\n"]}
@@ -0,0 +1,5 @@
1
+ import { SessionIdGenerator } from './types/SessionIdGenerator';
2
+ export declare class DefaultIdGenerator implements SessionIdGenerator {
3
+ generateSessionId: () => string;
4
+ }
5
+ //# sourceMappingURL=DefaultIdGenerator.d.ts.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.DefaultIdGenerator = void 0;
19
+ class DefaultIdGenerator {
20
+ generateSessionId = getIdGenerator(16);
21
+ }
22
+ exports.DefaultIdGenerator = DefaultIdGenerator;
23
+ const SHARED_CHAR_CODES_ARRAY = Array(32);
24
+ function getIdGenerator(bytes) {
25
+ return function generateId() {
26
+ for (let i = 0; i < bytes * 2; i++) {
27
+ SHARED_CHAR_CODES_ARRAY[i] = Math.floor(Math.random() * 16) + 48;
28
+ // valid hex characters in the range 48-57 and 97-102
29
+ if (SHARED_CHAR_CODES_ARRAY[i] >= 58) {
30
+ SHARED_CHAR_CODES_ARRAY[i] += 39;
31
+ }
32
+ }
33
+ return String.fromCharCode.apply(null, SHARED_CHAR_CODES_ARRAY.slice(0, bytes * 2));
34
+ };
35
+ }
36
+ //# sourceMappingURL=DefaultIdGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultIdGenerator.js","sourceRoot":"","sources":["../../src/DefaultIdGenerator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,MAAa,kBAAkB;IAC7B,iBAAiB,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC;CACxC;AAFD,gDAEC;AAED,MAAM,uBAAuB,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;AAC1C,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,SAAS,UAAU;QACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YAClC,uBAAuB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;YACjE,qDAAqD;YACrD,IAAI,uBAAuB,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE;gBACpC,uBAAuB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAClC;SACF;QACD,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,CAC9B,IAAI,EACJ,uBAAuB,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAC5C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SessionIdGenerator } from './types/SessionIdGenerator';\n\nexport class DefaultIdGenerator implements SessionIdGenerator {\n generateSessionId = getIdGenerator(16);\n}\n\nconst SHARED_CHAR_CODES_ARRAY = Array(32);\nfunction getIdGenerator(bytes: number): () => string {\n return function generateId() {\n for (let i = 0; i < bytes * 2; i++) {\n SHARED_CHAR_CODES_ARRAY[i] = Math.floor(Math.random() * 16) + 48;\n // valid hex characters in the range 48-57 and 97-102\n if (SHARED_CHAR_CODES_ARRAY[i] >= 58) {\n SHARED_CHAR_CODES_ARRAY[i] += 39;\n }\n }\n return String.fromCharCode.apply(\n null,\n SHARED_CHAR_CODES_ARRAY.slice(0, bytes * 2)\n );\n };\n}\n"]}