@posthog/core 1.49.2 → 1.50.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.
@@ -24,16 +24,15 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- toOtlpKeyValueList: ()=>toOtlpKeyValueList,
28
27
  getOtlpSeverityNumber: ()=>getOtlpSeverityNumber,
29
28
  buildResourceAttributes: ()=>buildResourceAttributes,
30
29
  getOtlpSeverityText: ()=>getOtlpSeverityText,
31
30
  buildOtlpLogsPayload: ()=>buildOtlpLogsPayload,
32
- buildOtlpLogRecord: ()=>buildOtlpLogRecord,
33
- toOtlpAnyValue: ()=>toOtlpAnyValue
31
+ buildOtlpLogRecord: ()=>buildOtlpLogRecord
34
32
  });
35
33
  const index_js_namespaceObject = require("../utils/index.js");
36
34
  const json_utils_js_namespaceObject = require("../utils/json-utils.js");
35
+ const otlp_any_value_js_namespaceObject = require("../utils/otlp-any-value.js");
37
36
  const OTLP_SEVERITY_MAP = {
38
37
  trace: {
39
38
  text: 'TRACE',
@@ -67,154 +66,6 @@ function getOtlpSeverityText(level) {
67
66
  function getOtlpSeverityNumber(level) {
68
67
  return (OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY).number;
69
68
  }
70
- const INT64_RANGE_LIMIT = 9223372036854775808;
71
- const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
72
- function newState() {
73
- return {
74
- ancestors: new WeakSet(),
75
- remainingNodes: json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_NODES
76
- };
77
- }
78
- function toOtlpAnyValue(value, logger) {
79
- try {
80
- return encodeAnyValue(value, logger, newState(), 0);
81
- } catch {
82
- return {
83
- stringValue: json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE
84
- };
85
- }
86
- }
87
- function toOtlpKeyValueList(attrs, logger) {
88
- try {
89
- return encodeKeyValueList(attrs, logger, newState(), 0);
90
- } catch {
91
- return [];
92
- }
93
- }
94
- function encodeAnyValue(value, logger, state, depth) {
95
- if (state.remainingNodes <= 0) return {
96
- stringValue: json_utils_js_namespaceObject.TRUNCATED_VALUE
97
- };
98
- state.remainingNodes--;
99
- if ((0, index_js_namespaceObject.isBoolean)(value)) return {
100
- boolValue: value
101
- };
102
- if ('number' == typeof value) {
103
- if (!Number.isFinite(value)) return {
104
- stringValue: String(value)
105
- };
106
- if (Number.isInteger(value)) {
107
- if (Number.isSafeInteger(value)) return {
108
- intValue: String(value)
109
- };
110
- if ('undefined' == typeof BigInt) return {
111
- stringValue: String(value)
112
- };
113
- const decimal = BigInt(value).toString();
114
- if (value >= INT64_RANGE_LIMIT || value < -INT64_RANGE_LIMIT) {
115
- logger?.debug(`Attribute ${decimal} is outside the int64 range; encoding it as a string`);
116
- return {
117
- stringValue: decimal
118
- };
119
- }
120
- return {
121
- intValue: decimal
122
- };
123
- }
124
- return {
125
- doubleValue: value
126
- };
127
- }
128
- if ('string' == typeof value) return {
129
- stringValue: (0, json_utils_js_namespaceObject.sanitizeString)(value)
130
- };
131
- if ('function' == typeof value) return {
132
- stringValue: json_utils_js_namespaceObject.FUNCTION_VALUE
133
- };
134
- if ('symbol' == typeof value) return {
135
- stringValue: String(value)
136
- };
137
- if ('object' == typeof value && null !== value) {
138
- if (state.ancestors.has(value)) return {
139
- stringValue: json_utils_js_namespaceObject.CIRCULAR_VALUE
140
- };
141
- if (depth >= json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_DEPTH) return {
142
- stringValue: json_utils_js_namespaceObject.TRUNCATED_VALUE
143
- };
144
- if (value instanceof Date) {
145
- const time = value.getTime();
146
- const iso = Number.isFinite(time) ? value.toISOString() : String(value);
147
- return {
148
- stringValue: 'string' == typeof iso ? (0, json_utils_js_namespaceObject.sanitizeString)(iso) : String(iso)
149
- };
150
- }
151
- state.ancestors.add(value);
152
- try {
153
- try {
154
- const toJSON = value.toJSON;
155
- if ('function' == typeof toJSON) return encodeAnyValue(toJSON.call(value), logger, state, depth + 1);
156
- } catch {}
157
- if ((0, index_js_namespaceObject.isArray)(value)) return {
158
- arrayValue: {
159
- values: encodeArrayValues(value, logger, state, depth + 1)
160
- }
161
- };
162
- return {
163
- kvlistValue: {
164
- values: encodeKeyValueList(value, logger, state, depth + 1)
165
- }
166
- };
167
- } finally{
168
- state.ancestors.delete(value);
169
- }
170
- }
171
- return {
172
- stringValue: (0, json_utils_js_namespaceObject.sanitizeString)(String(value))
173
- };
174
- }
175
- function encodeArrayValues(values, logger, state, depth) {
176
- const result = [];
177
- const itemCount = Math.min(values.length, json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_ITEMS);
178
- let index = 0;
179
- for(; index < itemCount && state.remainingNodes > 0; index++)try {
180
- const element = index in values ? values[index] : void 0;
181
- if ((0, index_js_namespaceObject.isNullish)(element)) continue;
182
- result.push(encodeAnyValue(element, logger, state, depth));
183
- } catch {
184
- result.push({
185
- stringValue: json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE
186
- });
187
- }
188
- if (values.length > index) result.push({
189
- stringValue: json_utils_js_namespaceObject.TRUNCATED_VALUE
190
- });
191
- return result;
192
- }
193
- function encodeKeyValueList(attrs, logger, state, depth) {
194
- const result = [];
195
- for(const key in attrs)if (propertyIsEnumerable.call(attrs, key)) {
196
- if (result.length >= json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_ITEMS || state.remainingNodes <= 0) {
197
- logger?.debug('Attributes truncated: the value exceeds the OTLP encoder budget');
198
- break;
199
- }
200
- try {
201
- const value = attrs[key];
202
- if ((0, index_js_namespaceObject.isNull)(value) || (0, index_js_namespaceObject.isUndefined)(value)) continue;
203
- result.push({
204
- key: (0, json_utils_js_namespaceObject.sanitizeString)(key),
205
- value: encodeAnyValue(value, logger, state, depth)
206
- });
207
- } catch {
208
- result.push({
209
- key: (0, json_utils_js_namespaceObject.sanitizeString)(key),
210
- value: {
211
- stringValue: json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE
212
- }
213
- });
214
- }
215
- }
216
- return result;
217
- }
218
69
  function timestampToUnixNano(timestampMs = Date.now()) {
219
70
  return String(timestampMs) + '000000';
220
71
  }
@@ -273,7 +124,7 @@ function buildOtlpLogRecord(options, sdkContext, logger, occurredAtMs) {
273
124
  body: {
274
125
  stringValue: encodeBody(options.body)
275
126
  },
276
- attributes: toOtlpKeyValueList(mergedAttributes, logger)
127
+ attributes: (0, otlp_any_value_js_namespaceObject.toOtlpKeyValueList)(mergedAttributes, logger)
277
128
  };
278
129
  if (options.trace_id) record.traceId = options.trace_id;
279
130
  if (options.span_id) record.spanId = options.span_id;
@@ -299,7 +150,7 @@ function buildOtlpLogsPayload(logRecords, resourceAttributes, scopeName, scopeVe
299
150
  resourceLogs: [
300
151
  {
301
152
  resource: {
302
- attributes: toOtlpKeyValueList(resourceAttributes)
153
+ attributes: (0, otlp_any_value_js_namespaceObject.toOtlpKeyValueList)(resourceAttributes)
303
154
  },
304
155
  scopeLogs: [
305
156
  {
@@ -319,16 +170,12 @@ exports.buildOtlpLogsPayload = __webpack_exports__.buildOtlpLogsPayload;
319
170
  exports.buildResourceAttributes = __webpack_exports__.buildResourceAttributes;
320
171
  exports.getOtlpSeverityNumber = __webpack_exports__.getOtlpSeverityNumber;
321
172
  exports.getOtlpSeverityText = __webpack_exports__.getOtlpSeverityText;
322
- exports.toOtlpAnyValue = __webpack_exports__.toOtlpAnyValue;
323
- exports.toOtlpKeyValueList = __webpack_exports__.toOtlpKeyValueList;
324
173
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
325
174
  "buildOtlpLogRecord",
326
175
  "buildOtlpLogsPayload",
327
176
  "buildResourceAttributes",
328
177
  "getOtlpSeverityNumber",
329
- "getOtlpSeverityText",
330
- "toOtlpAnyValue",
331
- "toOtlpKeyValueList"
178
+ "getOtlpSeverityText"
332
179
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
333
180
  Object.defineProperty(exports, '__esModule', {
334
181
  value: true
@@ -1,5 +1,6 @@
1
- import { isArray, isBoolean, isNull, isNullish, isNumber, isUndefined } from "../utils/index.mjs";
2
- import { CIRCULAR_VALUE, FUNCTION_VALUE, MAX_JSON_SAFE_VALUE_DEPTH, MAX_JSON_SAFE_VALUE_ITEMS, MAX_JSON_SAFE_VALUE_NODES, TRUNCATED_VALUE, UNSERIALIZABLE_VALUE, sanitizeString } from "../utils/json-utils.mjs";
1
+ import { isNullish, isNumber, isUndefined } from "../utils/index.mjs";
2
+ import { UNSERIALIZABLE_VALUE, sanitizeString } from "../utils/json-utils.mjs";
3
+ import { toOtlpKeyValueList } from "../utils/otlp-any-value.mjs";
3
4
  const OTLP_SEVERITY_MAP = {
4
5
  trace: {
5
6
  text: 'TRACE',
@@ -33,154 +34,6 @@ function getOtlpSeverityText(level) {
33
34
  function getOtlpSeverityNumber(level) {
34
35
  return (OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY).number;
35
36
  }
36
- const INT64_RANGE_LIMIT = 9223372036854775808;
37
- const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
38
- function newState() {
39
- return {
40
- ancestors: new WeakSet(),
41
- remainingNodes: MAX_JSON_SAFE_VALUE_NODES
42
- };
43
- }
44
- function toOtlpAnyValue(value, logger) {
45
- try {
46
- return encodeAnyValue(value, logger, newState(), 0);
47
- } catch {
48
- return {
49
- stringValue: UNSERIALIZABLE_VALUE
50
- };
51
- }
52
- }
53
- function toOtlpKeyValueList(attrs, logger) {
54
- try {
55
- return encodeKeyValueList(attrs, logger, newState(), 0);
56
- } catch {
57
- return [];
58
- }
59
- }
60
- function encodeAnyValue(value, logger, state, depth) {
61
- if (state.remainingNodes <= 0) return {
62
- stringValue: TRUNCATED_VALUE
63
- };
64
- state.remainingNodes--;
65
- if (isBoolean(value)) return {
66
- boolValue: value
67
- };
68
- if ('number' == typeof value) {
69
- if (!Number.isFinite(value)) return {
70
- stringValue: String(value)
71
- };
72
- if (Number.isInteger(value)) {
73
- if (Number.isSafeInteger(value)) return {
74
- intValue: String(value)
75
- };
76
- if ('undefined' == typeof BigInt) return {
77
- stringValue: String(value)
78
- };
79
- const decimal = BigInt(value).toString();
80
- if (value >= INT64_RANGE_LIMIT || value < -INT64_RANGE_LIMIT) {
81
- logger?.debug(`Attribute ${decimal} is outside the int64 range; encoding it as a string`);
82
- return {
83
- stringValue: decimal
84
- };
85
- }
86
- return {
87
- intValue: decimal
88
- };
89
- }
90
- return {
91
- doubleValue: value
92
- };
93
- }
94
- if ('string' == typeof value) return {
95
- stringValue: sanitizeString(value)
96
- };
97
- if ('function' == typeof value) return {
98
- stringValue: FUNCTION_VALUE
99
- };
100
- if ('symbol' == typeof value) return {
101
- stringValue: String(value)
102
- };
103
- if ('object' == typeof value && null !== value) {
104
- if (state.ancestors.has(value)) return {
105
- stringValue: CIRCULAR_VALUE
106
- };
107
- if (depth >= MAX_JSON_SAFE_VALUE_DEPTH) return {
108
- stringValue: TRUNCATED_VALUE
109
- };
110
- if (value instanceof Date) {
111
- const time = value.getTime();
112
- const iso = Number.isFinite(time) ? value.toISOString() : String(value);
113
- return {
114
- stringValue: 'string' == typeof iso ? sanitizeString(iso) : String(iso)
115
- };
116
- }
117
- state.ancestors.add(value);
118
- try {
119
- try {
120
- const toJSON = value.toJSON;
121
- if ('function' == typeof toJSON) return encodeAnyValue(toJSON.call(value), logger, state, depth + 1);
122
- } catch {}
123
- if (isArray(value)) return {
124
- arrayValue: {
125
- values: encodeArrayValues(value, logger, state, depth + 1)
126
- }
127
- };
128
- return {
129
- kvlistValue: {
130
- values: encodeKeyValueList(value, logger, state, depth + 1)
131
- }
132
- };
133
- } finally{
134
- state.ancestors.delete(value);
135
- }
136
- }
137
- return {
138
- stringValue: sanitizeString(String(value))
139
- };
140
- }
141
- function encodeArrayValues(values, logger, state, depth) {
142
- const result = [];
143
- const itemCount = Math.min(values.length, MAX_JSON_SAFE_VALUE_ITEMS);
144
- let index = 0;
145
- for(; index < itemCount && state.remainingNodes > 0; index++)try {
146
- const element = index in values ? values[index] : void 0;
147
- if (isNullish(element)) continue;
148
- result.push(encodeAnyValue(element, logger, state, depth));
149
- } catch {
150
- result.push({
151
- stringValue: UNSERIALIZABLE_VALUE
152
- });
153
- }
154
- if (values.length > index) result.push({
155
- stringValue: TRUNCATED_VALUE
156
- });
157
- return result;
158
- }
159
- function encodeKeyValueList(attrs, logger, state, depth) {
160
- const result = [];
161
- for(const key in attrs)if (propertyIsEnumerable.call(attrs, key)) {
162
- if (result.length >= MAX_JSON_SAFE_VALUE_ITEMS || state.remainingNodes <= 0) {
163
- logger?.debug('Attributes truncated: the value exceeds the OTLP encoder budget');
164
- break;
165
- }
166
- try {
167
- const value = attrs[key];
168
- if (isNull(value) || isUndefined(value)) continue;
169
- result.push({
170
- key: sanitizeString(key),
171
- value: encodeAnyValue(value, logger, state, depth)
172
- });
173
- } catch {
174
- result.push({
175
- key: sanitizeString(key),
176
- value: {
177
- stringValue: UNSERIALIZABLE_VALUE
178
- }
179
- });
180
- }
181
- }
182
- return result;
183
- }
184
37
  function timestampToUnixNano(timestampMs = Date.now()) {
185
38
  return String(timestampMs) + '000000';
186
39
  }
@@ -280,4 +133,4 @@ function buildOtlpLogsPayload(logRecords, resourceAttributes, scopeName, scopeVe
280
133
  ]
281
134
  };
282
135
  }
283
- export { buildOtlpLogRecord, buildOtlpLogsPayload, buildResourceAttributes, getOtlpSeverityNumber, getOtlpSeverityText, toOtlpAnyValue, toOtlpKeyValueList };
136
+ export { buildOtlpLogRecord, buildOtlpLogsPayload, buildResourceAttributes, getOtlpSeverityNumber, getOtlpSeverityText };
@@ -31,7 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  DEFAULT_HISTOGRAM_BOUNDS: ()=>external_metrics_utils_js_namespaceObject.DEFAULT_HISTOGRAM_BOUNDS
32
32
  });
33
33
  const index_js_namespaceObject = require("../utils/index.js");
34
- const logs_utils_js_namespaceObject = require("../logs/logs-utils.js");
34
+ const otlp_any_value_js_namespaceObject = require("../utils/otlp-any-value.js");
35
35
  const external_metrics_utils_js_namespaceObject = require("./metrics-utils.js");
36
36
  const external_config_js_namespaceObject = require("./config.js");
37
37
  const OTLP_TEMPORALITY_DELTA = 1;
@@ -268,7 +268,7 @@ class PostHogMetrics {
268
268
  };
269
269
  byMetric.set(metricKey, metric);
270
270
  }
271
- const attributes = (0, logs_utils_js_namespaceObject.toOtlpKeyValueList)(state.attributes ?? {}, this._logger);
271
+ const attributes = (0, otlp_any_value_js_namespaceObject.toOtlpKeyValueList)(state.attributes ?? {}, this._logger);
272
272
  const startNano = (0, external_metrics_utils_js_namespaceObject.msToUnixNano)(state.windowStartMs);
273
273
  if ('count' === state.type) {
274
274
  const dp = {
@@ -1,5 +1,5 @@
1
1
  import { isArray, safeSetTimeout } from "../utils/index.mjs";
2
- import { toOtlpKeyValueList } from "../logs/logs-utils.mjs";
2
+ import { toOtlpKeyValueList } from "../utils/otlp-any-value.mjs";
3
3
  import { DEFAULT_HISTOGRAM_BOUNDS, bucketIndexFor, buildMetricsResourceAttributes, buildOtlpMetricsPayload, msToUnixNano, seriesKey } from "./metrics-utils.mjs";
4
4
  import { resolveMetricsConfig } from "./config.mjs";
5
5
  const OTLP_TEMPORALITY_DELTA = 1;
@@ -31,7 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  seriesKey: ()=>seriesKey,
32
32
  DEFAULT_HISTOGRAM_BOUNDS: ()=>DEFAULT_HISTOGRAM_BOUNDS
33
33
  });
34
- const logs_utils_js_namespaceObject = require("../logs/logs-utils.js");
34
+ const otlp_any_value_js_namespaceObject = require("../utils/otlp-any-value.js");
35
35
  const DEFAULT_HISTOGRAM_BOUNDS = [
36
36
  0,
37
37
  5,
@@ -83,7 +83,7 @@ function buildOtlpMetricsPayload(metrics, resourceAttributes, scopeName, scopeVe
83
83
  resourceMetrics: [
84
84
  {
85
85
  resource: {
86
- attributes: (0, logs_utils_js_namespaceObject.toOtlpKeyValueList)(resourceAttributes)
86
+ attributes: (0, otlp_any_value_js_namespaceObject.toOtlpKeyValueList)(resourceAttributes)
87
87
  },
88
88
  scopeMetrics: [
89
89
  {
@@ -1,4 +1,4 @@
1
- import { toOtlpKeyValueList } from "../logs/logs-utils.mjs";
1
+ import { toOtlpKeyValueList } from "../utils/otlp-any-value.mjs";
2
2
  const DEFAULT_HISTOGRAM_BOUNDS = [
3
3
  0,
4
4
  5,
@@ -0,0 +1,5 @@
1
+ import type { OtlpAnyValue, OtlpKeyValue } from '@posthog/types';
2
+ import type { Logger } from '../types';
3
+ export declare function toOtlpAnyValue(value: unknown, logger?: Logger): OtlpAnyValue;
4
+ export declare function toOtlpKeyValueList(attrs: Record<string, unknown>, logger?: Logger): OtlpKeyValue[];
5
+ //# sourceMappingURL=otlp-any-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otlp-any-value.d.ts","sourceRoot":"","sources":["../../src/utils/otlp-any-value.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAiCtC,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAQ5E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CAMlG"}
@@ -0,0 +1,203 @@
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
+ toOtlpAnyValue: ()=>toOtlpAnyValue
29
+ });
30
+ const external_type_utils_js_namespaceObject = require("./type-utils.js");
31
+ const external_json_utils_js_namespaceObject = require("./json-utils.js");
32
+ const INT64_RANGE_LIMIT = 9223372036854775808;
33
+ const INT64_RANGE_LIMIT_DECIMAL = '9223372036854775808';
34
+ const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
35
+ function newState() {
36
+ return {
37
+ ancestors: new WeakSet(),
38
+ remainingNodes: external_json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_NODES
39
+ };
40
+ }
41
+ function toOtlpAnyValue(value, logger) {
42
+ try {
43
+ return encodeAnyValue(value, logger, newState(), 0);
44
+ } catch {
45
+ return {
46
+ stringValue: external_json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE
47
+ };
48
+ }
49
+ }
50
+ function toOtlpKeyValueList(attrs, logger) {
51
+ try {
52
+ return encodeKeyValueList(attrs, logger, newState(), 0);
53
+ } catch {
54
+ return [];
55
+ }
56
+ }
57
+ function encodeBigInt(value, logger) {
58
+ const decimal = value.toString();
59
+ const limit = BigInt(INT64_RANGE_LIMIT_DECIMAL);
60
+ if (value >= limit || value < -limit) {
61
+ logger?.debug(`Attribute ${decimal} is outside the int64 range; encoding it as a string`);
62
+ return {
63
+ stringValue: decimal
64
+ };
65
+ }
66
+ return {
67
+ intValue: decimal
68
+ };
69
+ }
70
+ function encodeAnyValue(value, logger, state, depth) {
71
+ if (state.remainingNodes <= 0) return {
72
+ stringValue: external_json_utils_js_namespaceObject.TRUNCATED_VALUE
73
+ };
74
+ state.remainingNodes--;
75
+ if ((0, external_type_utils_js_namespaceObject.isBoolean)(value)) return {
76
+ boolValue: value
77
+ };
78
+ if ('bigint' == typeof value) return encodeBigInt(value, logger);
79
+ if ('number' == typeof value) {
80
+ if (!Number.isFinite(value)) return {
81
+ stringValue: String(value)
82
+ };
83
+ if (Number.isInteger(value)) {
84
+ if (Number.isSafeInteger(value)) return {
85
+ intValue: String(value)
86
+ };
87
+ if ('undefined' == typeof BigInt) return {
88
+ stringValue: String(value)
89
+ };
90
+ const decimal = BigInt(value).toString();
91
+ if (value >= INT64_RANGE_LIMIT || value < -INT64_RANGE_LIMIT) {
92
+ logger?.debug(`Attribute ${decimal} is outside the int64 range; encoding it as a string`);
93
+ return {
94
+ stringValue: decimal
95
+ };
96
+ }
97
+ return {
98
+ intValue: decimal
99
+ };
100
+ }
101
+ return {
102
+ doubleValue: value
103
+ };
104
+ }
105
+ if ('string' == typeof value) return {
106
+ stringValue: (0, external_json_utils_js_namespaceObject.sanitizeString)(value)
107
+ };
108
+ if ('function' == typeof value) return {
109
+ stringValue: external_json_utils_js_namespaceObject.FUNCTION_VALUE
110
+ };
111
+ if ('symbol' == typeof value) return {
112
+ stringValue: String(value)
113
+ };
114
+ if ('object' == typeof value && null !== value) {
115
+ if (state.ancestors.has(value)) return {
116
+ stringValue: external_json_utils_js_namespaceObject.CIRCULAR_VALUE
117
+ };
118
+ if (depth >= external_json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_DEPTH) return {
119
+ stringValue: external_json_utils_js_namespaceObject.TRUNCATED_VALUE
120
+ };
121
+ if (value instanceof Date) {
122
+ const time = value.getTime();
123
+ const iso = Number.isFinite(time) ? value.toISOString() : String(value);
124
+ return {
125
+ stringValue: 'string' == typeof iso ? (0, external_json_utils_js_namespaceObject.sanitizeString)(iso) : String(iso)
126
+ };
127
+ }
128
+ state.ancestors.add(value);
129
+ try {
130
+ try {
131
+ const toJSON = value.toJSON;
132
+ if ('function' == typeof toJSON) return encodeAnyValue(toJSON.call(value), logger, state, depth + 1);
133
+ } catch {}
134
+ if ((0, external_type_utils_js_namespaceObject.isArray)(value)) return {
135
+ arrayValue: {
136
+ values: encodeArrayValues(value, logger, state, depth + 1)
137
+ }
138
+ };
139
+ return {
140
+ kvlistValue: {
141
+ values: encodeKeyValueList(value, logger, state, depth + 1)
142
+ }
143
+ };
144
+ } finally{
145
+ state.ancestors.delete(value);
146
+ }
147
+ }
148
+ return {
149
+ stringValue: (0, external_json_utils_js_namespaceObject.sanitizeString)(String(value))
150
+ };
151
+ }
152
+ function encodeArrayValues(values, logger, state, depth) {
153
+ const result = [];
154
+ const itemCount = Math.min(values.length, external_json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_ITEMS);
155
+ let index = 0;
156
+ for(; index < itemCount && state.remainingNodes > 0; index++)try {
157
+ const element = index in values ? values[index] : void 0;
158
+ if ((0, external_type_utils_js_namespaceObject.isNullish)(element)) continue;
159
+ result.push(encodeAnyValue(element, logger, state, depth));
160
+ } catch {
161
+ result.push({
162
+ stringValue: external_json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE
163
+ });
164
+ }
165
+ if (values.length > index) result.push({
166
+ stringValue: external_json_utils_js_namespaceObject.TRUNCATED_VALUE
167
+ });
168
+ return result;
169
+ }
170
+ function encodeKeyValueList(attrs, logger, state, depth) {
171
+ const result = [];
172
+ for(const key in attrs)if (propertyIsEnumerable.call(attrs, key)) {
173
+ if (result.length >= external_json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_ITEMS || state.remainingNodes <= 0) {
174
+ logger?.debug('Attributes truncated: the value exceeds the OTLP encoder budget');
175
+ break;
176
+ }
177
+ try {
178
+ const value = attrs[key];
179
+ if ((0, external_type_utils_js_namespaceObject.isNull)(value) || (0, external_type_utils_js_namespaceObject.isUndefined)(value)) continue;
180
+ result.push({
181
+ key: (0, external_json_utils_js_namespaceObject.sanitizeString)(key),
182
+ value: encodeAnyValue(value, logger, state, depth)
183
+ });
184
+ } catch {
185
+ result.push({
186
+ key: (0, external_json_utils_js_namespaceObject.sanitizeString)(key),
187
+ value: {
188
+ stringValue: external_json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE
189
+ }
190
+ });
191
+ }
192
+ }
193
+ return result;
194
+ }
195
+ exports.toOtlpAnyValue = __webpack_exports__.toOtlpAnyValue;
196
+ exports.toOtlpKeyValueList = __webpack_exports__.toOtlpKeyValueList;
197
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
198
+ "toOtlpAnyValue",
199
+ "toOtlpKeyValueList"
200
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
201
+ Object.defineProperty(exports, '__esModule', {
202
+ value: true
203
+ });