@posthog/core 1.27.0 → 1.27.2
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.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -38
- package/dist/index.mjs +2 -1
- package/dist/logs/logs-utils.d.ts +26 -0
- package/dist/logs/logs-utils.d.ts.map +1 -0
- package/dist/logs/logs-utils.js +181 -0
- package/dist/logs/logs-utils.mjs +132 -0
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +4 -3
- package/dist/posthog-core-stateless.mjs +5 -4
- package/package.json +4 -1
- package/src/index.ts +8 -0
- package/src/logs/logs-utils.spec.ts +264 -0
- package/src/logs/logs-utils.ts +198 -0
- package/src/posthog-core-stateless.ts +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { getFeatureFlagValue } from './featureFlagUtils';
|
|
|
2
2
|
export { gzipCompress, isNativeAsyncGzipReadError } from './gzip';
|
|
3
3
|
export * from './utils';
|
|
4
4
|
export * as ErrorTracking from './error-tracking';
|
|
5
|
+
export { buildOtlpLogRecord, buildOtlpLogsPayload, getOtlpSeverityNumber, getOtlpSeverityText, toOtlpAnyValue, toOtlpKeyValueList, } from './logs/logs-utils';
|
|
5
6
|
export { uuidv7 } from './vendor/uuidv7';
|
|
6
7
|
export * from './posthog-core';
|
|
7
8
|
export * from './posthog-core-stateless';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAA;AACjE,cAAc,SAAS,CAAA;AACvB,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAA;AACjE,cAAc,SAAS,CAAA;AACvB,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACjD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,9 @@ var __webpack_modules__ = {
|
|
|
9
9
|
"./gzip": function(module) {
|
|
10
10
|
module.exports = require("./gzip.js");
|
|
11
11
|
},
|
|
12
|
+
"./logs/logs-utils": function(module) {
|
|
13
|
+
module.exports = require("./logs/logs-utils.js");
|
|
14
|
+
},
|
|
12
15
|
"./posthog-core-stateless": function(module) {
|
|
13
16
|
module.exports = require("./posthog-core-stateless.js");
|
|
14
17
|
},
|
|
@@ -76,116 +79,165 @@ var __webpack_exports__ = {};
|
|
|
76
79
|
__webpack_require__.r(__webpack_exports__);
|
|
77
80
|
__webpack_require__.d(__webpack_exports__, {
|
|
78
81
|
ErrorTracking: ()=>_error_tracking__WEBPACK_IMPORTED_MODULE_3__,
|
|
82
|
+
buildOtlpLogRecord: ()=>_logs_logs_utils__WEBPACK_IMPORTED_MODULE_4__.buildOtlpLogRecord,
|
|
83
|
+
buildOtlpLogsPayload: ()=>_logs_logs_utils__WEBPACK_IMPORTED_MODULE_4__.buildOtlpLogsPayload,
|
|
79
84
|
getFeatureFlagValue: ()=>_featureFlagUtils__WEBPACK_IMPORTED_MODULE_0__.getFeatureFlagValue,
|
|
80
|
-
getLengthFromRules: ()=>
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
getLengthFromRules: ()=>_surveys_validation__WEBPACK_IMPORTED_MODULE_10__.getLengthFromRules,
|
|
86
|
+
getOtlpSeverityNumber: ()=>_logs_logs_utils__WEBPACK_IMPORTED_MODULE_4__.getOtlpSeverityNumber,
|
|
87
|
+
getOtlpSeverityText: ()=>_logs_logs_utils__WEBPACK_IMPORTED_MODULE_4__.getOtlpSeverityText,
|
|
88
|
+
getRequirementsHint: ()=>_surveys_validation__WEBPACK_IMPORTED_MODULE_10__.getRequirementsHint,
|
|
89
|
+
getValidationError: ()=>_surveys_validation__WEBPACK_IMPORTED_MODULE_10__.getValidationError,
|
|
83
90
|
gzipCompress: ()=>_gzip__WEBPACK_IMPORTED_MODULE_1__.gzipCompress,
|
|
84
91
|
isNativeAsyncGzipReadError: ()=>_gzip__WEBPACK_IMPORTED_MODULE_1__.isNativeAsyncGzipReadError,
|
|
85
|
-
|
|
92
|
+
toOtlpAnyValue: ()=>_logs_logs_utils__WEBPACK_IMPORTED_MODULE_4__.toOtlpAnyValue,
|
|
93
|
+
toOtlpKeyValueList: ()=>_logs_logs_utils__WEBPACK_IMPORTED_MODULE_4__.toOtlpKeyValueList,
|
|
94
|
+
uuidv7: ()=>_vendor_uuidv7__WEBPACK_IMPORTED_MODULE_5__.uuidv7
|
|
86
95
|
});
|
|
87
96
|
var _featureFlagUtils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./featureFlagUtils");
|
|
88
97
|
var _gzip__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./gzip");
|
|
89
98
|
var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./utils?637c");
|
|
90
99
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
91
100
|
for(var __WEBPACK_IMPORT_KEY__ in _utils__WEBPACK_IMPORTED_MODULE_2__)if ([
|
|
101
|
+
"toOtlpKeyValueList",
|
|
102
|
+
"getOtlpSeverityText",
|
|
103
|
+
"isNativeAsyncGzipReadError",
|
|
104
|
+
"getFeatureFlagValue",
|
|
105
|
+
"uuidv7",
|
|
106
|
+
"getValidationError",
|
|
92
107
|
"ErrorTracking",
|
|
93
108
|
"gzipCompress",
|
|
94
109
|
"default",
|
|
95
110
|
"getRequirementsHint",
|
|
96
|
-
"
|
|
111
|
+
"getOtlpSeverityNumber",
|
|
97
112
|
"getLengthFromRules",
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
113
|
+
"buildOtlpLogsPayload",
|
|
114
|
+
"buildOtlpLogRecord",
|
|
115
|
+
"toOtlpAnyValue"
|
|
101
116
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
102
117
|
return _utils__WEBPACK_IMPORTED_MODULE_2__[key];
|
|
103
118
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
104
119
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
105
120
|
var _error_tracking__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./error-tracking");
|
|
106
|
-
var
|
|
107
|
-
var
|
|
121
|
+
var _logs_logs_utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./logs/logs-utils");
|
|
122
|
+
var _vendor_uuidv7__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./vendor/uuidv7");
|
|
123
|
+
var _posthog_core__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("./posthog-core");
|
|
108
124
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
109
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
125
|
+
for(var __WEBPACK_IMPORT_KEY__ in _posthog_core__WEBPACK_IMPORTED_MODULE_6__)if ([
|
|
126
|
+
"toOtlpKeyValueList",
|
|
127
|
+
"getOtlpSeverityText",
|
|
128
|
+
"isNativeAsyncGzipReadError",
|
|
129
|
+
"getFeatureFlagValue",
|
|
130
|
+
"uuidv7",
|
|
131
|
+
"getValidationError",
|
|
110
132
|
"ErrorTracking",
|
|
111
133
|
"gzipCompress",
|
|
112
134
|
"default",
|
|
113
135
|
"getRequirementsHint",
|
|
114
|
-
"
|
|
136
|
+
"getOtlpSeverityNumber",
|
|
115
137
|
"getLengthFromRules",
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
138
|
+
"buildOtlpLogsPayload",
|
|
139
|
+
"buildOtlpLogRecord",
|
|
140
|
+
"toOtlpAnyValue"
|
|
119
141
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
120
|
-
return
|
|
142
|
+
return _posthog_core__WEBPACK_IMPORTED_MODULE_6__[key];
|
|
121
143
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
122
144
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
123
|
-
var
|
|
145
|
+
var _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__("./posthog-core-stateless");
|
|
124
146
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
125
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
147
|
+
for(var __WEBPACK_IMPORT_KEY__ in _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_7__)if ([
|
|
148
|
+
"toOtlpKeyValueList",
|
|
149
|
+
"getOtlpSeverityText",
|
|
150
|
+
"isNativeAsyncGzipReadError",
|
|
151
|
+
"getFeatureFlagValue",
|
|
152
|
+
"uuidv7",
|
|
153
|
+
"getValidationError",
|
|
126
154
|
"ErrorTracking",
|
|
127
155
|
"gzipCompress",
|
|
128
156
|
"default",
|
|
129
157
|
"getRequirementsHint",
|
|
130
|
-
"
|
|
158
|
+
"getOtlpSeverityNumber",
|
|
131
159
|
"getLengthFromRules",
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
"
|
|
160
|
+
"buildOtlpLogsPayload",
|
|
161
|
+
"buildOtlpLogRecord",
|
|
162
|
+
"toOtlpAnyValue"
|
|
135
163
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
136
|
-
return
|
|
164
|
+
return _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_7__[key];
|
|
137
165
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
138
166
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
139
|
-
var
|
|
167
|
+
var _tracing_headers__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__("./tracing-headers");
|
|
140
168
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
141
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
169
|
+
for(var __WEBPACK_IMPORT_KEY__ in _tracing_headers__WEBPACK_IMPORTED_MODULE_8__)if ([
|
|
170
|
+
"toOtlpKeyValueList",
|
|
171
|
+
"getOtlpSeverityText",
|
|
172
|
+
"isNativeAsyncGzipReadError",
|
|
173
|
+
"getFeatureFlagValue",
|
|
174
|
+
"uuidv7",
|
|
175
|
+
"getValidationError",
|
|
142
176
|
"ErrorTracking",
|
|
143
177
|
"gzipCompress",
|
|
144
178
|
"default",
|
|
145
179
|
"getRequirementsHint",
|
|
146
|
-
"
|
|
180
|
+
"getOtlpSeverityNumber",
|
|
147
181
|
"getLengthFromRules",
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
"
|
|
182
|
+
"buildOtlpLogsPayload",
|
|
183
|
+
"buildOtlpLogRecord",
|
|
184
|
+
"toOtlpAnyValue"
|
|
151
185
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
152
|
-
return
|
|
186
|
+
return _tracing_headers__WEBPACK_IMPORTED_MODULE_8__[key];
|
|
153
187
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
154
188
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
155
|
-
var
|
|
189
|
+
var _types__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__("./types");
|
|
156
190
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
157
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
191
|
+
for(var __WEBPACK_IMPORT_KEY__ in _types__WEBPACK_IMPORTED_MODULE_9__)if ([
|
|
192
|
+
"toOtlpKeyValueList",
|
|
193
|
+
"getOtlpSeverityText",
|
|
194
|
+
"isNativeAsyncGzipReadError",
|
|
195
|
+
"getFeatureFlagValue",
|
|
196
|
+
"uuidv7",
|
|
197
|
+
"getValidationError",
|
|
158
198
|
"ErrorTracking",
|
|
159
199
|
"gzipCompress",
|
|
160
200
|
"default",
|
|
161
201
|
"getRequirementsHint",
|
|
162
|
-
"
|
|
202
|
+
"getOtlpSeverityNumber",
|
|
163
203
|
"getLengthFromRules",
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
204
|
+
"buildOtlpLogsPayload",
|
|
205
|
+
"buildOtlpLogRecord",
|
|
206
|
+
"toOtlpAnyValue"
|
|
167
207
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
168
|
-
return
|
|
208
|
+
return _types__WEBPACK_IMPORTED_MODULE_9__[key];
|
|
169
209
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
170
210
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
171
|
-
var
|
|
211
|
+
var _surveys_validation__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__("./surveys/validation");
|
|
172
212
|
})();
|
|
173
213
|
exports.ErrorTracking = __webpack_exports__.ErrorTracking;
|
|
214
|
+
exports.buildOtlpLogRecord = __webpack_exports__.buildOtlpLogRecord;
|
|
215
|
+
exports.buildOtlpLogsPayload = __webpack_exports__.buildOtlpLogsPayload;
|
|
174
216
|
exports.getFeatureFlagValue = __webpack_exports__.getFeatureFlagValue;
|
|
175
217
|
exports.getLengthFromRules = __webpack_exports__.getLengthFromRules;
|
|
218
|
+
exports.getOtlpSeverityNumber = __webpack_exports__.getOtlpSeverityNumber;
|
|
219
|
+
exports.getOtlpSeverityText = __webpack_exports__.getOtlpSeverityText;
|
|
176
220
|
exports.getRequirementsHint = __webpack_exports__.getRequirementsHint;
|
|
177
221
|
exports.getValidationError = __webpack_exports__.getValidationError;
|
|
178
222
|
exports.gzipCompress = __webpack_exports__.gzipCompress;
|
|
179
223
|
exports.isNativeAsyncGzipReadError = __webpack_exports__.isNativeAsyncGzipReadError;
|
|
224
|
+
exports.toOtlpAnyValue = __webpack_exports__.toOtlpAnyValue;
|
|
225
|
+
exports.toOtlpKeyValueList = __webpack_exports__.toOtlpKeyValueList;
|
|
180
226
|
exports.uuidv7 = __webpack_exports__.uuidv7;
|
|
181
227
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
182
228
|
"ErrorTracking",
|
|
229
|
+
"buildOtlpLogRecord",
|
|
230
|
+
"buildOtlpLogsPayload",
|
|
183
231
|
"getFeatureFlagValue",
|
|
184
232
|
"getLengthFromRules",
|
|
233
|
+
"getOtlpSeverityNumber",
|
|
234
|
+
"getOtlpSeverityText",
|
|
185
235
|
"getRequirementsHint",
|
|
186
236
|
"getValidationError",
|
|
187
237
|
"gzipCompress",
|
|
188
238
|
"isNativeAsyncGzipReadError",
|
|
239
|
+
"toOtlpAnyValue",
|
|
240
|
+
"toOtlpKeyValueList",
|
|
189
241
|
"uuidv7"
|
|
190
242
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
191
243
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getFeatureFlagValue } from "./featureFlagUtils.mjs";
|
|
2
2
|
import { gzipCompress, isNativeAsyncGzipReadError } from "./gzip.mjs";
|
|
3
|
+
import { buildOtlpLogRecord, buildOtlpLogsPayload, getOtlpSeverityNumber, getOtlpSeverityText, toOtlpAnyValue, toOtlpKeyValueList } from "./logs/logs-utils.mjs";
|
|
3
4
|
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
4
5
|
import { getLengthFromRules, getRequirementsHint, getValidationError } from "./surveys/validation.mjs";
|
|
5
6
|
export * from "./utils/index.mjs";
|
|
@@ -8,4 +9,4 @@ export * from "./posthog-core-stateless.mjs";
|
|
|
8
9
|
export * from "./tracing-headers.mjs";
|
|
9
10
|
export * from "./types.mjs";
|
|
10
11
|
import * as __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ from "./error-tracking/index.mjs";
|
|
11
|
-
export { __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ as ErrorTracking, getFeatureFlagValue, getLengthFromRules, getRequirementsHint, getValidationError, gzipCompress, isNativeAsyncGzipReadError, uuidv7 };
|
|
12
|
+
export { __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ as ErrorTracking, buildOtlpLogRecord, buildOtlpLogsPayload, getFeatureFlagValue, getLengthFromRules, getOtlpSeverityNumber, getOtlpSeverityText, getRequirementsHint, getValidationError, gzipCompress, isNativeAsyncGzipReadError, toOtlpAnyValue, toOtlpKeyValueList, uuidv7 };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CaptureLogOptions, LogAttributeValue, LogSdkContext, LogSeverityLevel, OtlpAnyValue, OtlpKeyValue, OtlpLogRecord, OtlpLogsPayload, OtlpSeverityText } from '@posthog/types';
|
|
2
|
+
export declare function getOtlpSeverityText(level: LogSeverityLevel): OtlpSeverityText;
|
|
3
|
+
export declare function getOtlpSeverityNumber(level: LogSeverityLevel): number;
|
|
4
|
+
export declare function toOtlpAnyValue(value: LogAttributeValue): OtlpAnyValue;
|
|
5
|
+
export declare function toOtlpKeyValueList(attrs: Record<string, LogAttributeValue>): OtlpKeyValue[];
|
|
6
|
+
/**
|
|
7
|
+
* Builds a single OTLP log record.
|
|
8
|
+
*
|
|
9
|
+
* Auto-attribute population is shape-driven: any field present on `sdkContext`
|
|
10
|
+
* is emitted as the corresponding attribute. Each SDK populates only the
|
|
11
|
+
* fields that apply to it (browser fills `currentUrl`; mobile fills
|
|
12
|
+
* `screenName` / `appState`), so a missing field never adds a stray attribute.
|
|
13
|
+
*
|
|
14
|
+
* User-provided `options.attributes` always wins on conflicts.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildOtlpLogRecord(options: CaptureLogOptions, sdkContext: LogSdkContext): OtlpLogRecord;
|
|
17
|
+
/**
|
|
18
|
+
* Wraps a list of records in the OTLP `resourceLogs` envelope.
|
|
19
|
+
*
|
|
20
|
+
* `scopeName` is the SDK package name (`posthog-js`, `posthog-react-native`,
|
|
21
|
+
* etc.). `scopeVersion` is the SDK semver. The server combines them into a
|
|
22
|
+
* single `instrumentation_scope` field (`{name}@{version}`) used for
|
|
23
|
+
* SDK-version-level attribution in queries and dashboards.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildOtlpLogsPayload(logRecords: OtlpLogRecord[], resourceAttributes: Record<string, LogAttributeValue>, scopeName: string, scopeVersion: string): OtlpLogsPayload;
|
|
26
|
+
//# sourceMappingURL=logs-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs-utils.d.ts","sourceRoot":"","sources":["../../src/logs/logs-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EAEf,gBAAgB,EACjB,MAAM,gBAAgB,CAAA;AAkBvB,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAE7E;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAErE;AAMD,wBAAgB,cAAc,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAiCrE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,YAAY,EAAE,CAU3F;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,aAAa,GAAG,aAAa,CAmDvG;AAMD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,aAAa,EAAE,EAC3B,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACrD,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,eAAe,CAcjB"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
toOtlpKeyValueList: ()=>toOtlpKeyValueList,
|
|
28
|
+
getOtlpSeverityNumber: ()=>getOtlpSeverityNumber,
|
|
29
|
+
getOtlpSeverityText: ()=>getOtlpSeverityText,
|
|
30
|
+
buildOtlpLogsPayload: ()=>buildOtlpLogsPayload,
|
|
31
|
+
buildOtlpLogRecord: ()=>buildOtlpLogRecord,
|
|
32
|
+
toOtlpAnyValue: ()=>toOtlpAnyValue
|
|
33
|
+
});
|
|
34
|
+
const index_js_namespaceObject = require("../utils/index.js");
|
|
35
|
+
const OTLP_SEVERITY_MAP = {
|
|
36
|
+
trace: {
|
|
37
|
+
text: 'TRACE',
|
|
38
|
+
number: 1
|
|
39
|
+
},
|
|
40
|
+
debug: {
|
|
41
|
+
text: 'DEBUG',
|
|
42
|
+
number: 5
|
|
43
|
+
},
|
|
44
|
+
info: {
|
|
45
|
+
text: 'INFO',
|
|
46
|
+
number: 9
|
|
47
|
+
},
|
|
48
|
+
warn: {
|
|
49
|
+
text: 'WARN',
|
|
50
|
+
number: 13
|
|
51
|
+
},
|
|
52
|
+
error: {
|
|
53
|
+
text: 'ERROR',
|
|
54
|
+
number: 17
|
|
55
|
+
},
|
|
56
|
+
fatal: {
|
|
57
|
+
text: 'FATAL',
|
|
58
|
+
number: 21
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const DEFAULT_OTLP_SEVERITY = OTLP_SEVERITY_MAP.info;
|
|
62
|
+
function getOtlpSeverityText(level) {
|
|
63
|
+
return (OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY).text;
|
|
64
|
+
}
|
|
65
|
+
function getOtlpSeverityNumber(level) {
|
|
66
|
+
return (OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY).number;
|
|
67
|
+
}
|
|
68
|
+
function toOtlpAnyValue(value) {
|
|
69
|
+
if ((0, index_js_namespaceObject.isBoolean)(value)) return {
|
|
70
|
+
boolValue: value
|
|
71
|
+
};
|
|
72
|
+
if ('number' == typeof value) {
|
|
73
|
+
if (!Number.isFinite(value)) return {
|
|
74
|
+
stringValue: String(value)
|
|
75
|
+
};
|
|
76
|
+
if (Number.isInteger(value)) return {
|
|
77
|
+
intValue: value
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
doubleValue: value
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if ('string' == typeof value) return {
|
|
84
|
+
stringValue: value
|
|
85
|
+
};
|
|
86
|
+
if ((0, index_js_namespaceObject.isArray)(value)) return {
|
|
87
|
+
arrayValue: {
|
|
88
|
+
values: value.map((v)=>toOtlpAnyValue(v))
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
return {
|
|
93
|
+
stringValue: JSON.stringify(value)
|
|
94
|
+
};
|
|
95
|
+
} catch {
|
|
96
|
+
return {
|
|
97
|
+
stringValue: String(value)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function toOtlpKeyValueList(attrs) {
|
|
102
|
+
const result = [];
|
|
103
|
+
for(const key in attrs){
|
|
104
|
+
const value = attrs[key];
|
|
105
|
+
if (!((0, index_js_namespaceObject.isNull)(value) || (0, index_js_namespaceObject.isUndefined)(value))) result.push({
|
|
106
|
+
key,
|
|
107
|
+
value: toOtlpAnyValue(value)
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
function timestampToUnixNano() {
|
|
113
|
+
return String(Date.now()) + '000000';
|
|
114
|
+
}
|
|
115
|
+
function buildOtlpLogRecord(options, sdkContext) {
|
|
116
|
+
const level = options.level || 'info';
|
|
117
|
+
const { text: severityText, number: severityNumber } = OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY;
|
|
118
|
+
const now = timestampToUnixNano();
|
|
119
|
+
const autoAttributes = {};
|
|
120
|
+
if (sdkContext.distinctId) autoAttributes.posthogDistinctId = sdkContext.distinctId;
|
|
121
|
+
if (sdkContext.sessionId) autoAttributes.sessionId = sdkContext.sessionId;
|
|
122
|
+
if (sdkContext.currentUrl) autoAttributes['url.full'] = sdkContext.currentUrl;
|
|
123
|
+
if (sdkContext.screenName) autoAttributes['screen.name'] = sdkContext.screenName;
|
|
124
|
+
if (sdkContext.appState) autoAttributes['app.state'] = sdkContext.appState;
|
|
125
|
+
if (sdkContext.activeFeatureFlags && sdkContext.activeFeatureFlags.length > 0) autoAttributes.feature_flags = sdkContext.activeFeatureFlags;
|
|
126
|
+
const mergedAttributes = {
|
|
127
|
+
...autoAttributes,
|
|
128
|
+
...options.attributes || {}
|
|
129
|
+
};
|
|
130
|
+
const record = {
|
|
131
|
+
timeUnixNano: now,
|
|
132
|
+
observedTimeUnixNano: now,
|
|
133
|
+
severityNumber,
|
|
134
|
+
severityText,
|
|
135
|
+
body: {
|
|
136
|
+
stringValue: options.body
|
|
137
|
+
},
|
|
138
|
+
attributes: toOtlpKeyValueList(mergedAttributes)
|
|
139
|
+
};
|
|
140
|
+
if (options.trace_id) record.traceId = options.trace_id;
|
|
141
|
+
if (options.span_id) record.spanId = options.span_id;
|
|
142
|
+
if (!(0, index_js_namespaceObject.isUndefined)(options.trace_flags)) record.flags = options.trace_flags;
|
|
143
|
+
return record;
|
|
144
|
+
}
|
|
145
|
+
function buildOtlpLogsPayload(logRecords, resourceAttributes, scopeName, scopeVersion) {
|
|
146
|
+
return {
|
|
147
|
+
resourceLogs: [
|
|
148
|
+
{
|
|
149
|
+
resource: {
|
|
150
|
+
attributes: toOtlpKeyValueList(resourceAttributes)
|
|
151
|
+
},
|
|
152
|
+
scopeLogs: [
|
|
153
|
+
{
|
|
154
|
+
scope: {
|
|
155
|
+
name: scopeName,
|
|
156
|
+
version: scopeVersion
|
|
157
|
+
},
|
|
158
|
+
logRecords
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
exports.buildOtlpLogRecord = __webpack_exports__.buildOtlpLogRecord;
|
|
166
|
+
exports.buildOtlpLogsPayload = __webpack_exports__.buildOtlpLogsPayload;
|
|
167
|
+
exports.getOtlpSeverityNumber = __webpack_exports__.getOtlpSeverityNumber;
|
|
168
|
+
exports.getOtlpSeverityText = __webpack_exports__.getOtlpSeverityText;
|
|
169
|
+
exports.toOtlpAnyValue = __webpack_exports__.toOtlpAnyValue;
|
|
170
|
+
exports.toOtlpKeyValueList = __webpack_exports__.toOtlpKeyValueList;
|
|
171
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
172
|
+
"buildOtlpLogRecord",
|
|
173
|
+
"buildOtlpLogsPayload",
|
|
174
|
+
"getOtlpSeverityNumber",
|
|
175
|
+
"getOtlpSeverityText",
|
|
176
|
+
"toOtlpAnyValue",
|
|
177
|
+
"toOtlpKeyValueList"
|
|
178
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
179
|
+
Object.defineProperty(exports, '__esModule', {
|
|
180
|
+
value: true
|
|
181
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { isArray, isBoolean, isNull, isUndefined } from "../utils/index.mjs";
|
|
2
|
+
const OTLP_SEVERITY_MAP = {
|
|
3
|
+
trace: {
|
|
4
|
+
text: 'TRACE',
|
|
5
|
+
number: 1
|
|
6
|
+
},
|
|
7
|
+
debug: {
|
|
8
|
+
text: 'DEBUG',
|
|
9
|
+
number: 5
|
|
10
|
+
},
|
|
11
|
+
info: {
|
|
12
|
+
text: 'INFO',
|
|
13
|
+
number: 9
|
|
14
|
+
},
|
|
15
|
+
warn: {
|
|
16
|
+
text: 'WARN',
|
|
17
|
+
number: 13
|
|
18
|
+
},
|
|
19
|
+
error: {
|
|
20
|
+
text: 'ERROR',
|
|
21
|
+
number: 17
|
|
22
|
+
},
|
|
23
|
+
fatal: {
|
|
24
|
+
text: 'FATAL',
|
|
25
|
+
number: 21
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const DEFAULT_OTLP_SEVERITY = OTLP_SEVERITY_MAP.info;
|
|
29
|
+
function getOtlpSeverityText(level) {
|
|
30
|
+
return (OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY).text;
|
|
31
|
+
}
|
|
32
|
+
function getOtlpSeverityNumber(level) {
|
|
33
|
+
return (OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY).number;
|
|
34
|
+
}
|
|
35
|
+
function toOtlpAnyValue(value) {
|
|
36
|
+
if (isBoolean(value)) return {
|
|
37
|
+
boolValue: value
|
|
38
|
+
};
|
|
39
|
+
if ('number' == typeof value) {
|
|
40
|
+
if (!Number.isFinite(value)) return {
|
|
41
|
+
stringValue: String(value)
|
|
42
|
+
};
|
|
43
|
+
if (Number.isInteger(value)) return {
|
|
44
|
+
intValue: value
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
doubleValue: value
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if ('string' == typeof value) return {
|
|
51
|
+
stringValue: value
|
|
52
|
+
};
|
|
53
|
+
if (isArray(value)) return {
|
|
54
|
+
arrayValue: {
|
|
55
|
+
values: value.map((v)=>toOtlpAnyValue(v))
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
return {
|
|
60
|
+
stringValue: JSON.stringify(value)
|
|
61
|
+
};
|
|
62
|
+
} catch {
|
|
63
|
+
return {
|
|
64
|
+
stringValue: String(value)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function toOtlpKeyValueList(attrs) {
|
|
69
|
+
const result = [];
|
|
70
|
+
for(const key in attrs){
|
|
71
|
+
const value = attrs[key];
|
|
72
|
+
if (!(isNull(value) || isUndefined(value))) result.push({
|
|
73
|
+
key,
|
|
74
|
+
value: toOtlpAnyValue(value)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
function timestampToUnixNano() {
|
|
80
|
+
return String(Date.now()) + '000000';
|
|
81
|
+
}
|
|
82
|
+
function buildOtlpLogRecord(options, sdkContext) {
|
|
83
|
+
const level = options.level || 'info';
|
|
84
|
+
const { text: severityText, number: severityNumber } = OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY;
|
|
85
|
+
const now = timestampToUnixNano();
|
|
86
|
+
const autoAttributes = {};
|
|
87
|
+
if (sdkContext.distinctId) autoAttributes.posthogDistinctId = sdkContext.distinctId;
|
|
88
|
+
if (sdkContext.sessionId) autoAttributes.sessionId = sdkContext.sessionId;
|
|
89
|
+
if (sdkContext.currentUrl) autoAttributes['url.full'] = sdkContext.currentUrl;
|
|
90
|
+
if (sdkContext.screenName) autoAttributes['screen.name'] = sdkContext.screenName;
|
|
91
|
+
if (sdkContext.appState) autoAttributes['app.state'] = sdkContext.appState;
|
|
92
|
+
if (sdkContext.activeFeatureFlags && sdkContext.activeFeatureFlags.length > 0) autoAttributes.feature_flags = sdkContext.activeFeatureFlags;
|
|
93
|
+
const mergedAttributes = {
|
|
94
|
+
...autoAttributes,
|
|
95
|
+
...options.attributes || {}
|
|
96
|
+
};
|
|
97
|
+
const record = {
|
|
98
|
+
timeUnixNano: now,
|
|
99
|
+
observedTimeUnixNano: now,
|
|
100
|
+
severityNumber,
|
|
101
|
+
severityText,
|
|
102
|
+
body: {
|
|
103
|
+
stringValue: options.body
|
|
104
|
+
},
|
|
105
|
+
attributes: toOtlpKeyValueList(mergedAttributes)
|
|
106
|
+
};
|
|
107
|
+
if (options.trace_id) record.traceId = options.trace_id;
|
|
108
|
+
if (options.span_id) record.spanId = options.span_id;
|
|
109
|
+
if (!isUndefined(options.trace_flags)) record.flags = options.trace_flags;
|
|
110
|
+
return record;
|
|
111
|
+
}
|
|
112
|
+
function buildOtlpLogsPayload(logRecords, resourceAttributes, scopeName, scopeVersion) {
|
|
113
|
+
return {
|
|
114
|
+
resourceLogs: [
|
|
115
|
+
{
|
|
116
|
+
resource: {
|
|
117
|
+
attributes: toOtlpKeyValueList(resourceAttributes)
|
|
118
|
+
},
|
|
119
|
+
scopeLogs: [
|
|
120
|
+
{
|
|
121
|
+
scope: {
|
|
122
|
+
name: scopeName,
|
|
123
|
+
version: scopeVersion
|
|
124
|
+
},
|
|
125
|
+
logRecords
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export { buildOtlpLogRecord, buildOtlpLogsPayload, getOtlpSeverityNumber, getOtlpSeverityText, toOtlpAnyValue, toOtlpKeyValueList };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,oBA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,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,sBAAsB;IA0B9G,OAAO,CAAC,eAAe;IAOvB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAMvB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB5B,SAAS,CAAC,gBAAgB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;YAazC,MAAM;YA4FN,cAAc;IAsDtB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
|
|
@@ -89,7 +89,9 @@ class PostHogCoreStateless {
|
|
|
89
89
|
this._isInitialized = false;
|
|
90
90
|
const normalizedApiKey = 'string' == typeof apiKey ? apiKey.trim() : '';
|
|
91
91
|
const normalizedHost = 'string' == typeof options.host ? options.host.trim() : '';
|
|
92
|
-
|
|
92
|
+
const missingApiKey = !normalizedApiKey;
|
|
93
|
+
this._logger = (0, index_js_namespaceObject.createLogger)('[PostHog]', this.logMsgIfDebug.bind(this));
|
|
94
|
+
if (missingApiKey) this._logger.error("You must pass your PostHog project's api key. The client will be disabled.");
|
|
93
95
|
this.apiKey = normalizedApiKey;
|
|
94
96
|
this.host = (0, index_js_namespaceObject.removeTrailingSlash)(normalizedHost || 'https://us.i.posthog.com');
|
|
95
97
|
this.flushAt = options.flushAt ? Math.max(options.flushAt, 1) : 20;
|
|
@@ -108,11 +110,10 @@ class PostHogCoreStateless {
|
|
|
108
110
|
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
|
|
109
111
|
this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000;
|
|
110
112
|
this.disableGeoip = options.disableGeoip ?? true;
|
|
111
|
-
this.disabled = options.disabled ?? false;
|
|
113
|
+
this.disabled = (options.disabled ?? false) || missingApiKey;
|
|
112
114
|
this.historicalMigration = options?.historicalMigration ?? false;
|
|
113
115
|
this._initPromise = Promise.resolve();
|
|
114
116
|
this._isInitialized = true;
|
|
115
|
-
this._logger = (0, index_js_namespaceObject.createLogger)('[PostHog]', this.logMsgIfDebug.bind(this));
|
|
116
117
|
this.evaluationContexts = options?.evaluationContexts ?? options?.evaluationEnvironments;
|
|
117
118
|
if (options?.evaluationEnvironments && !options?.evaluationContexts) this._logger.warn('evaluationEnvironments is deprecated. Use evaluationContexts instead. This property will be removed in a future version.');
|
|
118
119
|
this.disableCompression = !(0, external_gzip_js_namespaceObject.isGzipSupported)() || (options?.disableCompression ?? false);
|
|
@@ -2,7 +2,7 @@ import { SimpleEventEmitter } from "./eventemitter.mjs";
|
|
|
2
2
|
import { getFeatureFlagValue, normalizeFlagsResponse } from "./featureFlagUtils.mjs";
|
|
3
3
|
import { gzipCompress, isGzipSupported } from "./gzip.mjs";
|
|
4
4
|
import { PostHogPersistedProperty } from "./types.mjs";
|
|
5
|
-
import { PromiseQueue, STRING_FORMAT, allSettled,
|
|
5
|
+
import { PromiseQueue, STRING_FORMAT, allSettled, createLogger, currentISOTime, removeTrailingSlash, retriable, safeSetTimeout } from "./utils/index.mjs";
|
|
6
6
|
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
7
7
|
class PostHogFetchHttpError extends Error {
|
|
8
8
|
constructor(response, reqByteLength){
|
|
@@ -58,7 +58,9 @@ class PostHogCoreStateless {
|
|
|
58
58
|
this._isInitialized = false;
|
|
59
59
|
const normalizedApiKey = 'string' == typeof apiKey ? apiKey.trim() : '';
|
|
60
60
|
const normalizedHost = 'string' == typeof options.host ? options.host.trim() : '';
|
|
61
|
-
|
|
61
|
+
const missingApiKey = !normalizedApiKey;
|
|
62
|
+
this._logger = createLogger('[PostHog]', this.logMsgIfDebug.bind(this));
|
|
63
|
+
if (missingApiKey) this._logger.error("You must pass your PostHog project's api key. The client will be disabled.");
|
|
62
64
|
this.apiKey = normalizedApiKey;
|
|
63
65
|
this.host = removeTrailingSlash(normalizedHost || 'https://us.i.posthog.com');
|
|
64
66
|
this.flushAt = options.flushAt ? Math.max(options.flushAt, 1) : 20;
|
|
@@ -77,11 +79,10 @@ class PostHogCoreStateless {
|
|
|
77
79
|
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
|
|
78
80
|
this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000;
|
|
79
81
|
this.disableGeoip = options.disableGeoip ?? true;
|
|
80
|
-
this.disabled = options.disabled ?? false;
|
|
82
|
+
this.disabled = (options.disabled ?? false) || missingApiKey;
|
|
81
83
|
this.historicalMigration = options?.historicalMigration ?? false;
|
|
82
84
|
this._initPromise = Promise.resolve();
|
|
83
85
|
this._isInitialized = true;
|
|
84
|
-
this._logger = createLogger('[PostHog]', this.logMsgIfDebug.bind(this));
|
|
85
86
|
this.evaluationContexts = options?.evaluationContexts ?? options?.evaluationEnvironments;
|
|
86
87
|
if (options?.evaluationEnvironments && !options?.evaluationContexts) this._logger.warn('evaluationEnvironments is deprecated. Use evaluationContexts instead. This property will be removed in a future version.');
|
|
87
88
|
this.disableCompression = !isGzipSupported() || (options?.disableCompression ?? false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/core",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"import": "./dist/utils/index.mjs"
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@posthog/types": "1.371.3"
|
|
47
|
+
},
|
|
45
48
|
"devDependencies": {
|
|
46
49
|
"@rslib/core": "0.10.6",
|
|
47
50
|
"@types/jest": "^29.5.14",
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,14 @@ export { getFeatureFlagValue } from './featureFlagUtils'
|
|
|
2
2
|
export { gzipCompress, isNativeAsyncGzipReadError } from './gzip'
|
|
3
3
|
export * from './utils'
|
|
4
4
|
export * as ErrorTracking from './error-tracking'
|
|
5
|
+
export {
|
|
6
|
+
buildOtlpLogRecord,
|
|
7
|
+
buildOtlpLogsPayload,
|
|
8
|
+
getOtlpSeverityNumber,
|
|
9
|
+
getOtlpSeverityText,
|
|
10
|
+
toOtlpAnyValue,
|
|
11
|
+
toOtlpKeyValueList,
|
|
12
|
+
} from './logs/logs-utils'
|
|
5
13
|
export { uuidv7 } from './vendor/uuidv7'
|
|
6
14
|
export * from './posthog-core'
|
|
7
15
|
export * from './posthog-core-stateless'
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import type { CaptureLogOptions, LogSdkContext, LogSeverityLevel } from '@posthog/types'
|
|
2
|
+
import {
|
|
3
|
+
buildOtlpLogRecord,
|
|
4
|
+
buildOtlpLogsPayload,
|
|
5
|
+
getOtlpSeverityNumber,
|
|
6
|
+
getOtlpSeverityText,
|
|
7
|
+
toOtlpAnyValue,
|
|
8
|
+
toOtlpKeyValueList,
|
|
9
|
+
} from './logs-utils'
|
|
10
|
+
|
|
11
|
+
const browserSdkContext: LogSdkContext = {
|
|
12
|
+
distinctId: 'user-123',
|
|
13
|
+
sessionId: 'session-456',
|
|
14
|
+
currentUrl: 'https://example.com/page',
|
|
15
|
+
activeFeatureFlags: ['flag-a', 'flag-b'],
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const mobileSdkContext: LogSdkContext = {
|
|
19
|
+
distinctId: 'user-123',
|
|
20
|
+
sessionId: 'session-456',
|
|
21
|
+
screenName: 'Home',
|
|
22
|
+
appState: 'foreground',
|
|
23
|
+
activeFeatureFlags: ['flag-a', 'flag-b'],
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const minimalSdkContext: LogSdkContext = {}
|
|
27
|
+
|
|
28
|
+
describe('logs-utils', () => {
|
|
29
|
+
describe('getOtlpSeverityText', () => {
|
|
30
|
+
it.each([
|
|
31
|
+
['trace', 'TRACE'],
|
|
32
|
+
['debug', 'DEBUG'],
|
|
33
|
+
['info', 'INFO'],
|
|
34
|
+
['warn', 'WARN'],
|
|
35
|
+
['error', 'ERROR'],
|
|
36
|
+
['fatal', 'FATAL'],
|
|
37
|
+
] as [LogSeverityLevel, string][])('maps %s to %s', (level, expected) => {
|
|
38
|
+
expect(getOtlpSeverityText(level)).toBe(expected)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('falls back to INFO for unknown levels', () => {
|
|
42
|
+
expect(getOtlpSeverityText('bogus' as LogSeverityLevel)).toBe('INFO')
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
describe('getOtlpSeverityNumber', () => {
|
|
47
|
+
it.each([
|
|
48
|
+
['trace', 1],
|
|
49
|
+
['debug', 5],
|
|
50
|
+
['info', 9],
|
|
51
|
+
['warn', 13],
|
|
52
|
+
['error', 17],
|
|
53
|
+
['fatal', 21],
|
|
54
|
+
] as [LogSeverityLevel, number][])('maps %s to %d', (level, expected) => {
|
|
55
|
+
expect(getOtlpSeverityNumber(level)).toBe(expected)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('falls back to 9 (INFO) for unknown levels', () => {
|
|
59
|
+
expect(getOtlpSeverityNumber('bogus' as LogSeverityLevel)).toBe(9)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe('toOtlpAnyValue', () => {
|
|
64
|
+
it('converts strings', () => {
|
|
65
|
+
expect(toOtlpAnyValue('hello')).toEqual({ stringValue: 'hello' })
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('converts integers', () => {
|
|
69
|
+
expect(toOtlpAnyValue(42)).toEqual({ intValue: 42 })
|
|
70
|
+
expect(toOtlpAnyValue(0)).toEqual({ intValue: 0 })
|
|
71
|
+
expect(toOtlpAnyValue(-7)).toEqual({ intValue: -7 })
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('converts floats to doubleValue', () => {
|
|
75
|
+
expect(toOtlpAnyValue(3.14)).toEqual({ doubleValue: 3.14 })
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('converts booleans', () => {
|
|
79
|
+
expect(toOtlpAnyValue(true)).toEqual({ boolValue: true })
|
|
80
|
+
expect(toOtlpAnyValue(false)).toEqual({ boolValue: false })
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// JSON has no representation for non-finite floats; without explicit
|
|
84
|
+
// handling, JSON.stringify silently turns them into `null` and the value
|
|
85
|
+
// is lost server-side.
|
|
86
|
+
it('converts NaN to stringValue', () => {
|
|
87
|
+
expect(toOtlpAnyValue(NaN)).toEqual({ stringValue: 'NaN' })
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('converts +Infinity to stringValue', () => {
|
|
91
|
+
expect(toOtlpAnyValue(Infinity)).toEqual({ stringValue: 'Infinity' })
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('converts -Infinity to stringValue', () => {
|
|
95
|
+
expect(toOtlpAnyValue(-Infinity)).toEqual({ stringValue: '-Infinity' })
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('converts arrays of strings to arrayValue', () => {
|
|
99
|
+
expect(toOtlpAnyValue(['a', 'b'])).toEqual({
|
|
100
|
+
arrayValue: { values: [{ stringValue: 'a' }, { stringValue: 'b' }] },
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('converts mixed primitive arrays recursively', () => {
|
|
105
|
+
expect(toOtlpAnyValue([1, 'x', true])).toEqual({
|
|
106
|
+
arrayValue: {
|
|
107
|
+
values: [{ intValue: 1 }, { stringValue: 'x' }, { boolValue: true }],
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('JSON-stringifies plain objects', () => {
|
|
113
|
+
expect(toOtlpAnyValue({ a: 1, b: 'two' })).toEqual({
|
|
114
|
+
stringValue: '{"a":1,"b":"two"}',
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('toOtlpKeyValueList', () => {
|
|
120
|
+
it('converts a record to key-value list', () => {
|
|
121
|
+
expect(
|
|
122
|
+
toOtlpKeyValueList({
|
|
123
|
+
name: 'test',
|
|
124
|
+
count: 5,
|
|
125
|
+
active: true,
|
|
126
|
+
})
|
|
127
|
+
).toEqual([
|
|
128
|
+
{ key: 'name', value: { stringValue: 'test' } },
|
|
129
|
+
{ key: 'count', value: { intValue: 5 } },
|
|
130
|
+
{ key: 'active', value: { boolValue: true } },
|
|
131
|
+
])
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('handles empty record', () => {
|
|
135
|
+
expect(toOtlpKeyValueList({})).toEqual([])
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('skips null and undefined values', () => {
|
|
139
|
+
expect(
|
|
140
|
+
toOtlpKeyValueList({
|
|
141
|
+
kept: 'yes',
|
|
142
|
+
nullish: null,
|
|
143
|
+
missing: undefined,
|
|
144
|
+
})
|
|
145
|
+
).toEqual([{ key: 'kept', value: { stringValue: 'yes' } }])
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('buildOtlpLogRecord', () => {
|
|
150
|
+
it('builds a minimal log record', () => {
|
|
151
|
+
const record = buildOtlpLogRecord({ body: 'hello world' }, minimalSdkContext)
|
|
152
|
+
|
|
153
|
+
expect(record.body).toEqual({ stringValue: 'hello world' })
|
|
154
|
+
expect(record.severityText).toBe('INFO')
|
|
155
|
+
expect(record.severityNumber).toBe(9)
|
|
156
|
+
expect(record.timeUnixNano).toBeDefined()
|
|
157
|
+
expect(record.observedTimeUnixNano).toBeDefined()
|
|
158
|
+
expect(record.observedTimeUnixNano).toBe(record.timeUnixNano)
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it('maps severity levels correctly', () => {
|
|
162
|
+
const record = buildOtlpLogRecord({ body: 'test', level: 'error' }, minimalSdkContext)
|
|
163
|
+
expect(record.severityText).toBe('ERROR')
|
|
164
|
+
expect(record.severityNumber).toBe(17)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it('falls back to INFO for unknown severity', () => {
|
|
168
|
+
const record = buildOtlpLogRecord({ body: 'test', level: 'bogus' as LogSeverityLevel }, minimalSdkContext)
|
|
169
|
+
expect(record.severityText).toBe('INFO')
|
|
170
|
+
expect(record.severityNumber).toBe(9)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it('auto-populates browser SDK context (currentUrl → url.full)', () => {
|
|
174
|
+
const record = buildOtlpLogRecord({ body: 'test' }, browserSdkContext)
|
|
175
|
+
const attrs = Object.fromEntries(record.attributes.map((a) => [a.key, a.value]))
|
|
176
|
+
expect(attrs['posthogDistinctId']).toEqual({ stringValue: 'user-123' })
|
|
177
|
+
expect(attrs['sessionId']).toEqual({ stringValue: 'session-456' })
|
|
178
|
+
expect(attrs['url.full']).toEqual({ stringValue: 'https://example.com/page' })
|
|
179
|
+
expect(attrs['feature_flags']).toEqual({
|
|
180
|
+
arrayValue: { values: [{ stringValue: 'flag-a' }, { stringValue: 'flag-b' }] },
|
|
181
|
+
})
|
|
182
|
+
// browser context shouldn't leak mobile-only attrs
|
|
183
|
+
expect(attrs['screen.name']).toBeUndefined()
|
|
184
|
+
expect(attrs['app.state']).toBeUndefined()
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('auto-populates mobile SDK context (screenName + appState)', () => {
|
|
188
|
+
const record = buildOtlpLogRecord({ body: 'test' }, mobileSdkContext)
|
|
189
|
+
const attrs = Object.fromEntries(record.attributes.map((a) => [a.key, a.value]))
|
|
190
|
+
expect(attrs['screen.name']).toEqual({ stringValue: 'Home' })
|
|
191
|
+
expect(attrs['app.state']).toEqual({ stringValue: 'foreground' })
|
|
192
|
+
// mobile context shouldn't leak browser-only attrs
|
|
193
|
+
expect(attrs['url.full']).toBeUndefined()
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('user attributes override auto-populated ones', () => {
|
|
197
|
+
const record = buildOtlpLogRecord(
|
|
198
|
+
{ body: 'test', attributes: { posthogDistinctId: 'custom-id' } },
|
|
199
|
+
browserSdkContext
|
|
200
|
+
)
|
|
201
|
+
const attrs = Object.fromEntries(record.attributes.map((a) => [a.key, a.value]))
|
|
202
|
+
expect(attrs['posthogDistinctId']).toEqual({ stringValue: 'custom-id' })
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('includes trace context when provided', () => {
|
|
206
|
+
const options: CaptureLogOptions = {
|
|
207
|
+
body: 'test',
|
|
208
|
+
trace_id: '4bf92f3577b34da6a3ce929d0e0e4736',
|
|
209
|
+
span_id: '00f067aa0ba902b7',
|
|
210
|
+
trace_flags: 1,
|
|
211
|
+
}
|
|
212
|
+
const record = buildOtlpLogRecord(options, minimalSdkContext)
|
|
213
|
+
expect(record.traceId).toBe('4bf92f3577b34da6a3ce929d0e0e4736')
|
|
214
|
+
expect(record.spanId).toBe('00f067aa0ba902b7')
|
|
215
|
+
expect(record.flags).toBe(1)
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('omits trace context when not provided', () => {
|
|
219
|
+
const record = buildOtlpLogRecord({ body: 'test' }, minimalSdkContext)
|
|
220
|
+
expect(record.traceId).toBeUndefined()
|
|
221
|
+
expect(record.spanId).toBeUndefined()
|
|
222
|
+
expect(record.flags).toBeUndefined()
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('preserves trace_flags === 0', () => {
|
|
226
|
+
// Easy to lose with a falsy check; trace_flags is a numeric bitfield
|
|
227
|
+
// where 0 is a valid value (means "not sampled").
|
|
228
|
+
const record = buildOtlpLogRecord({ body: 'test', trace_flags: 0 }, minimalSdkContext)
|
|
229
|
+
expect(record.flags).toBe(0)
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
it('does not include feature_flags when the array is empty', () => {
|
|
233
|
+
const record = buildOtlpLogRecord({ body: 'test' }, { ...minimalSdkContext, activeFeatureFlags: [] })
|
|
234
|
+
expect(record.attributes.map((a) => a.key)).not.toContain('feature_flags')
|
|
235
|
+
})
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
describe('buildOtlpLogsPayload', () => {
|
|
239
|
+
it('wraps log records in the OTLP envelope with scope name and version', () => {
|
|
240
|
+
const record = buildOtlpLogRecord({ body: 'test' }, minimalSdkContext)
|
|
241
|
+
const payload = buildOtlpLogsPayload([record], { 'service.name': 'my-app' }, 'posthog-js', '1.371.0')
|
|
242
|
+
|
|
243
|
+
expect(payload.resourceLogs).toHaveLength(1)
|
|
244
|
+
expect(payload.resourceLogs[0].resource.attributes).toEqual([
|
|
245
|
+
{ key: 'service.name', value: { stringValue: 'my-app' } },
|
|
246
|
+
])
|
|
247
|
+
expect(payload.resourceLogs[0].scopeLogs).toHaveLength(1)
|
|
248
|
+
expect(payload.resourceLogs[0].scopeLogs[0].scope).toEqual({
|
|
249
|
+
name: 'posthog-js',
|
|
250
|
+
version: '1.371.0',
|
|
251
|
+
})
|
|
252
|
+
expect(payload.resourceLogs[0].scopeLogs[0].logRecords).toHaveLength(1)
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('includes multiple log records', () => {
|
|
256
|
+
const records = [
|
|
257
|
+
buildOtlpLogRecord({ body: 'log 1' }, minimalSdkContext),
|
|
258
|
+
buildOtlpLogRecord({ body: 'log 2', level: 'error' }, minimalSdkContext),
|
|
259
|
+
]
|
|
260
|
+
const payload = buildOtlpLogsPayload(records, { 'service.name': 'x' }, 'lib', '1.0.0')
|
|
261
|
+
expect(payload.resourceLogs[0].scopeLogs[0].logRecords).toHaveLength(2)
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
})
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CaptureLogOptions,
|
|
3
|
+
LogAttributeValue,
|
|
4
|
+
LogSdkContext,
|
|
5
|
+
LogSeverityLevel,
|
|
6
|
+
OtlpAnyValue,
|
|
7
|
+
OtlpKeyValue,
|
|
8
|
+
OtlpLogRecord,
|
|
9
|
+
OtlpLogsPayload,
|
|
10
|
+
OtlpSeverityEntry,
|
|
11
|
+
OtlpSeverityText,
|
|
12
|
+
} from '@posthog/types'
|
|
13
|
+
import { isArray, isBoolean, isNull, isUndefined } from '../utils'
|
|
14
|
+
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Severity mapping
|
|
17
|
+
// ============================================================================
|
|
18
|
+
|
|
19
|
+
const OTLP_SEVERITY_MAP: Record<LogSeverityLevel, OtlpSeverityEntry> = {
|
|
20
|
+
trace: { text: 'TRACE', number: 1 },
|
|
21
|
+
debug: { text: 'DEBUG', number: 5 },
|
|
22
|
+
info: { text: 'INFO', number: 9 },
|
|
23
|
+
warn: { text: 'WARN', number: 13 },
|
|
24
|
+
error: { text: 'ERROR', number: 17 },
|
|
25
|
+
fatal: { text: 'FATAL', number: 21 },
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const DEFAULT_OTLP_SEVERITY = OTLP_SEVERITY_MAP.info
|
|
29
|
+
|
|
30
|
+
export function getOtlpSeverityText(level: LogSeverityLevel): OtlpSeverityText {
|
|
31
|
+
return (OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY).text
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getOtlpSeverityNumber(level: LogSeverityLevel): number {
|
|
35
|
+
return (OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY).number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// OTLP AnyValue conversion
|
|
40
|
+
// ============================================================================
|
|
41
|
+
|
|
42
|
+
export function toOtlpAnyValue(value: LogAttributeValue): OtlpAnyValue {
|
|
43
|
+
if (isBoolean(value)) {
|
|
44
|
+
return { boolValue: value }
|
|
45
|
+
}
|
|
46
|
+
// NOTE: typeof check (not core's isNumber) so NaN is included. core's
|
|
47
|
+
// isNumber explicitly excludes NaN via the `x === x` guard, which would
|
|
48
|
+
// route NaN through the JSON.stringify branch below — JSON has no
|
|
49
|
+
// representation for non-finite floats and JSON.stringify turns them into
|
|
50
|
+
// `null`, losing the value server-side. proto3 JSON mapping (which OTLP/HTTP
|
|
51
|
+
// rides) requires the literal strings; we encode them as stringValue to keep
|
|
52
|
+
// the human-readable signal regardless of which downstream parser sees them.
|
|
53
|
+
if (typeof value === 'number') {
|
|
54
|
+
if (!Number.isFinite(value)) {
|
|
55
|
+
return { stringValue: String(value) }
|
|
56
|
+
}
|
|
57
|
+
if (Number.isInteger(value)) {
|
|
58
|
+
return { intValue: value }
|
|
59
|
+
}
|
|
60
|
+
return { doubleValue: value }
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === 'string') {
|
|
63
|
+
return { stringValue: value }
|
|
64
|
+
}
|
|
65
|
+
if (isArray(value)) {
|
|
66
|
+
return { arrayValue: { values: value.map((v) => toOtlpAnyValue(v as LogAttributeValue)) } }
|
|
67
|
+
}
|
|
68
|
+
// Objects fall back to JSON. OTLP supports kvlistValue but the encoder
|
|
69
|
+
// stays flat for simplicity.
|
|
70
|
+
try {
|
|
71
|
+
return { stringValue: JSON.stringify(value) }
|
|
72
|
+
} catch {
|
|
73
|
+
return { stringValue: String(value) }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function toOtlpKeyValueList(attrs: Record<string, LogAttributeValue>): OtlpKeyValue[] {
|
|
78
|
+
const result: OtlpKeyValue[] = []
|
|
79
|
+
for (const key in attrs) {
|
|
80
|
+
const value = attrs[key]
|
|
81
|
+
if (isNull(value) || isUndefined(value)) {
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
result.push({ key, value: toOtlpAnyValue(value) })
|
|
85
|
+
}
|
|
86
|
+
return result
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// OTLP LogRecord construction
|
|
91
|
+
// ============================================================================
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Returns the current wall-clock time as a unix-nanos string.
|
|
95
|
+
*
|
|
96
|
+
* OTLP requires nanoseconds as a string (uint64 doesn't fit in JS Number).
|
|
97
|
+
* `Date.now() * 1_000_000` would exceed Number.MAX_SAFE_INTEGER, so we
|
|
98
|
+
* concatenate instead of multiplying.
|
|
99
|
+
*/
|
|
100
|
+
function timestampToUnixNano(): string {
|
|
101
|
+
return String(Date.now()) + '000000'
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Builds a single OTLP log record.
|
|
106
|
+
*
|
|
107
|
+
* Auto-attribute population is shape-driven: any field present on `sdkContext`
|
|
108
|
+
* is emitted as the corresponding attribute. Each SDK populates only the
|
|
109
|
+
* fields that apply to it (browser fills `currentUrl`; mobile fills
|
|
110
|
+
* `screenName` / `appState`), so a missing field never adds a stray attribute.
|
|
111
|
+
*
|
|
112
|
+
* User-provided `options.attributes` always wins on conflicts.
|
|
113
|
+
*/
|
|
114
|
+
export function buildOtlpLogRecord(options: CaptureLogOptions, sdkContext: LogSdkContext): OtlpLogRecord {
|
|
115
|
+
const level: LogSeverityLevel = options.level || 'info'
|
|
116
|
+
const { text: severityText, number: severityNumber } = OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY
|
|
117
|
+
const now = timestampToUnixNano()
|
|
118
|
+
|
|
119
|
+
const autoAttributes: Record<string, LogAttributeValue> = {}
|
|
120
|
+
|
|
121
|
+
if (sdkContext.distinctId) {
|
|
122
|
+
autoAttributes.posthogDistinctId = sdkContext.distinctId
|
|
123
|
+
}
|
|
124
|
+
if (sdkContext.sessionId) {
|
|
125
|
+
autoAttributes.sessionId = sdkContext.sessionId
|
|
126
|
+
}
|
|
127
|
+
if (sdkContext.currentUrl) {
|
|
128
|
+
autoAttributes['url.full'] = sdkContext.currentUrl
|
|
129
|
+
}
|
|
130
|
+
if (sdkContext.screenName) {
|
|
131
|
+
autoAttributes['screen.name'] = sdkContext.screenName
|
|
132
|
+
}
|
|
133
|
+
if (sdkContext.appState) {
|
|
134
|
+
autoAttributes['app.state'] = sdkContext.appState
|
|
135
|
+
}
|
|
136
|
+
if (sdkContext.activeFeatureFlags && sdkContext.activeFeatureFlags.length > 0) {
|
|
137
|
+
autoAttributes.feature_flags = sdkContext.activeFeatureFlags
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const mergedAttributes = {
|
|
141
|
+
...autoAttributes,
|
|
142
|
+
...(options.attributes || {}),
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const record: OtlpLogRecord = {
|
|
146
|
+
timeUnixNano: now,
|
|
147
|
+
observedTimeUnixNano: now,
|
|
148
|
+
severityNumber,
|
|
149
|
+
severityText,
|
|
150
|
+
body: { stringValue: options.body },
|
|
151
|
+
attributes: toOtlpKeyValueList(mergedAttributes),
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (options.trace_id) {
|
|
155
|
+
record.traceId = options.trace_id
|
|
156
|
+
}
|
|
157
|
+
if (options.span_id) {
|
|
158
|
+
record.spanId = options.span_id
|
|
159
|
+
}
|
|
160
|
+
if (!isUndefined(options.trace_flags)) {
|
|
161
|
+
record.flags = options.trace_flags
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return record
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ============================================================================
|
|
168
|
+
// OTLP envelope construction
|
|
169
|
+
// ============================================================================
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Wraps a list of records in the OTLP `resourceLogs` envelope.
|
|
173
|
+
*
|
|
174
|
+
* `scopeName` is the SDK package name (`posthog-js`, `posthog-react-native`,
|
|
175
|
+
* etc.). `scopeVersion` is the SDK semver. The server combines them into a
|
|
176
|
+
* single `instrumentation_scope` field (`{name}@{version}`) used for
|
|
177
|
+
* SDK-version-level attribution in queries and dashboards.
|
|
178
|
+
*/
|
|
179
|
+
export function buildOtlpLogsPayload(
|
|
180
|
+
logRecords: OtlpLogRecord[],
|
|
181
|
+
resourceAttributes: Record<string, LogAttributeValue>,
|
|
182
|
+
scopeName: string,
|
|
183
|
+
scopeVersion: string
|
|
184
|
+
): OtlpLogsPayload {
|
|
185
|
+
return {
|
|
186
|
+
resourceLogs: [
|
|
187
|
+
{
|
|
188
|
+
resource: { attributes: toOtlpKeyValueList(resourceAttributes) },
|
|
189
|
+
scopeLogs: [
|
|
190
|
+
{
|
|
191
|
+
scope: { name: scopeName, version: scopeVersion },
|
|
192
|
+
logRecords,
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
} from './types'
|
|
25
25
|
import {
|
|
26
26
|
allSettled,
|
|
27
|
-
assert,
|
|
28
27
|
currentISOTime,
|
|
29
28
|
PromiseQueue,
|
|
30
29
|
removeTrailingSlash,
|
|
@@ -147,8 +146,12 @@ export abstract class PostHogCoreStateless {
|
|
|
147
146
|
constructor(apiKey: string, options: PostHogCoreOptions = {}) {
|
|
148
147
|
const normalizedApiKey = typeof apiKey === 'string' ? apiKey.trim() : ''
|
|
149
148
|
const normalizedHost = typeof options.host === 'string' ? options.host.trim() : ''
|
|
149
|
+
const missingApiKey = !normalizedApiKey
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
this._logger = createLogger('[PostHog]', this.logMsgIfDebug.bind(this))
|
|
152
|
+
if (missingApiKey) {
|
|
153
|
+
this._logger.error("You must pass your PostHog project's api key. The client will be disabled.")
|
|
154
|
+
}
|
|
152
155
|
|
|
153
156
|
this.apiKey = normalizedApiKey
|
|
154
157
|
this.host = removeTrailingSlash(normalizedHost || 'https://us.i.posthog.com')
|
|
@@ -170,12 +173,11 @@ export abstract class PostHogCoreStateless {
|
|
|
170
173
|
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000 // 3 seconds
|
|
171
174
|
this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000 // 3 seconds
|
|
172
175
|
this.disableGeoip = options.disableGeoip ?? true
|
|
173
|
-
this.disabled = options.disabled ?? false
|
|
176
|
+
this.disabled = (options.disabled ?? false) || missingApiKey
|
|
174
177
|
this.historicalMigration = options?.historicalMigration ?? false
|
|
175
178
|
// Init promise allows the derived class to block calls until it is ready
|
|
176
179
|
this._initPromise = Promise.resolve()
|
|
177
180
|
this._isInitialized = true
|
|
178
|
-
this._logger = createLogger('[PostHog]', this.logMsgIfDebug.bind(this))
|
|
179
181
|
// Support both evaluationContexts (new) and evaluationEnvironments (deprecated)
|
|
180
182
|
this.evaluationContexts = options?.evaluationContexts ?? options?.evaluationEnvironments
|
|
181
183
|
if (options?.evaluationEnvironments && !options?.evaluationContexts) {
|