@posthog/core 1.70.0 → 1.71.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 (117) hide show
  1. package/capture-v1/package.json +6 -0
  2. package/dist/capture-v1/compression.d.ts +18 -0
  3. package/dist/capture-v1/compression.d.ts.map +1 -0
  4. package/dist/capture-v1/compression.js +70 -0
  5. package/dist/capture-v1/compression.mjs +26 -0
  6. package/dist/capture-v1/errors.d.ts +48 -0
  7. package/dist/capture-v1/errors.d.ts.map +1 -0
  8. package/dist/capture-v1/errors.js +82 -0
  9. package/dist/capture-v1/errors.mjs +38 -0
  10. package/dist/capture-v1/index.d.ts +15 -0
  11. package/dist/capture-v1/index.d.ts.map +1 -0
  12. package/dist/capture-v1/index.js +88 -0
  13. package/dist/capture-v1/index.mjs +7 -0
  14. package/dist/capture-v1/sender.d.ts +150 -0
  15. package/dist/capture-v1/sender.d.ts.map +1 -0
  16. package/dist/capture-v1/sender.js +554 -0
  17. package/dist/capture-v1/sender.mjs +507 -0
  18. package/dist/capture-v1/serialize.d.ts +30 -0
  19. package/dist/capture-v1/serialize.d.ts.map +1 -0
  20. package/dist/capture-v1/serialize.js +106 -0
  21. package/dist/capture-v1/serialize.mjs +59 -0
  22. package/dist/capture-v1/transform.d.ts +19 -0
  23. package/dist/capture-v1/transform.d.ts.map +1 -0
  24. package/dist/capture-v1/transform.js +118 -0
  25. package/dist/capture-v1/transform.mjs +77 -0
  26. package/dist/capture-v1/types.d.ts +52 -0
  27. package/dist/capture-v1/types.d.ts.map +1 -0
  28. package/dist/capture-v1/types.js +44 -0
  29. package/dist/capture-v1/types.mjs +3 -0
  30. package/dist/capture-v1/uuid.d.ts +9 -0
  31. package/dist/capture-v1/uuid.d.ts.map +1 -0
  32. package/dist/capture-v1/uuid.js +75 -0
  33. package/dist/capture-v1/uuid.mjs +34 -0
  34. package/dist/featureFlagUtils.d.ts +7 -5
  35. package/dist/featureFlagUtils.d.ts.map +1 -1
  36. package/dist/featureFlagUtils.js +17 -11
  37. package/dist/featureFlagUtils.mjs +14 -11
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +27 -16
  41. package/dist/index.mjs +1 -1
  42. package/dist/posthog-core-stateless.d.ts +40 -3
  43. package/dist/posthog-core-stateless.d.ts.map +1 -1
  44. package/dist/posthog-core-stateless.js +87 -19
  45. package/dist/posthog-core-stateless.mjs +87 -19
  46. package/dist/posthog-core.d.ts +138 -53
  47. package/dist/posthog-core.d.ts.map +1 -1
  48. package/dist/posthog-core.js +341 -115
  49. package/dist/posthog-core.mjs +338 -115
  50. package/dist/types.d.ts +24 -1
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/utils/index.d.ts +1 -1
  53. package/dist/utils/index.d.ts.map +1 -1
  54. package/dist/utils/index.js +25 -12
  55. package/dist/utils/index.mjs +1 -1
  56. package/dist/utils/json-utils.d.ts +11 -1
  57. package/dist/utils/json-utils.d.ts.map +1 -1
  58. package/dist/utils/json-utils.js +50 -2
  59. package/dist/utils/json-utils.mjs +46 -1
  60. package/package.json +12 -2
  61. package/src/capture-v1/compression.ts +50 -0
  62. package/src/capture-v1/errors.ts +91 -0
  63. package/src/capture-v1/index.ts +34 -0
  64. package/src/capture-v1/sender.ts +779 -0
  65. package/src/capture-v1/serialize.ts +113 -0
  66. package/src/capture-v1/transform.ts +135 -0
  67. package/src/capture-v1/types.ts +59 -0
  68. package/src/capture-v1/uuid.ts +53 -0
  69. package/src/featureFlagUtils.ts +22 -10
  70. package/src/index.ts +1 -0
  71. package/src/posthog-core-stateless.ts +166 -30
  72. package/src/posthog-core.ts +615 -178
  73. package/src/types.ts +21 -1
  74. package/src/utils/index.ts +1 -1
  75. package/src/utils/json-utils.ts +64 -1
  76. package/src/error-tracking/chunk-ids.spec.ts +0 -77
  77. package/src/error-tracking/coercers/error-event-coercer.spec.ts +0 -142
  78. package/src/error-tracking/coercers/promise-rejection-event.spec.ts +0 -77
  79. package/src/error-tracking/coercers/string-coercer.spec.ts +0 -26
  80. package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +0 -412
  81. package/src/error-tracking/error-properties-builder.coerce.spec.ts +0 -337
  82. package/src/error-tracking/error-properties-builder.metadata.spec.ts +0 -318
  83. package/src/error-tracking/error-properties-builder.parse.spec.ts +0 -37
  84. package/src/error-tracking/exception-steps.spec.ts +0 -115
  85. package/src/error-tracking/parsers/base.spec.ts +0 -156
  86. package/src/error-tracking/parsers/index.spec.ts +0 -270
  87. package/src/error-tracking/parsers/node.spec.ts +0 -34
  88. package/src/error-tracking/release.spec.ts +0 -34
  89. package/src/logs/index.spec.ts +0 -2421
  90. package/src/logs/logs-utils.spec.ts +0 -266
  91. package/src/metrics/index.spec.ts +0 -1249
  92. package/src/surveys/activation.spec.ts +0 -61
  93. package/src/surveys/events.spec.ts +0 -183
  94. package/src/surveys/keys.spec.ts +0 -29
  95. package/src/surveys/property-matching.spec.ts +0 -539
  96. package/src/surveys/shuffling.spec.ts +0 -51
  97. package/src/surveys/translations.spec.ts +0 -274
  98. package/src/surveys/validation.spec.ts +0 -168
  99. package/src/traces/config.spec.ts +0 -271
  100. package/src/traces/ids.spec.ts +0 -115
  101. package/src/traces/index.spec.ts +0 -3287
  102. package/src/traces/live-spans.spec.ts +0 -69
  103. package/src/traces/otlp.spec.ts +0 -368
  104. package/src/traces/span.spec.ts +0 -1137
  105. package/src/traces/traceparent.spec.ts +0 -184
  106. package/src/utils/bot-detection.spec.ts +0 -107
  107. package/src/utils/bucketed-rate-limiter.spec.ts +0 -327
  108. package/src/utils/json-utils.spec.ts +0 -115
  109. package/src/utils/named-error.spec.ts +0 -36
  110. package/src/utils/number-utils.spec.ts +0 -212
  111. package/src/utils/otlp-any-value.spec.ts +0 -376
  112. package/src/utils/otlp-resource.spec.ts +0 -171
  113. package/src/utils/promise-queue.spec.ts +0 -55
  114. package/src/utils/string-utils.spec.ts +0 -158
  115. package/src/utils/type-utils.spec.ts +0 -38
  116. package/src/utils/webview-app-utils.spec.ts +0 -118
  117. package/src/vendor/uuidv7.spec.ts +0 -26
@@ -1,69 +0,0 @@
1
- import { PostHogTraces } from './index'
2
- import { SyncSpanContextManager } from './context'
3
- import type { ResolvedTracesConfig } from './types'
4
- import type { Logger } from '../types'
5
-
6
- // Live-span accounting keeps an id and a timestamp per span, never the span, so a
7
- // handle the caller drops stays collectable. This probe is what stops a later
8
- // change from turning that accounting into a registry of span objects.
9
- const gc = (globalThis as { gc?: () => void }).gc
10
-
11
- // `--expose-gc` is set by the `test:unit` script. A runner that invokes vitest
12
- // directly has no `gc`, and a probe that cannot force a collection proves nothing.
13
- const itWithGc = gc ? it : process.env.CI ? it : it.skip
14
-
15
- describe('live spans', () => {
16
- const config: ResolvedTracesConfig = {
17
- serviceName: 'svc',
18
- flushIntervalMs: 5000,
19
- maxExportBatchSize: 512,
20
- maxQueueSize: 2048,
21
- maxLiveSpans: 10000,
22
- maxSpanAgeMs: 3600000,
23
- beforeSpanSend: [],
24
- maxAttributesPerSpan: 128,
25
- maxEventsPerSpan: 128,
26
- maxAttributesPerEvent: 128,
27
- maxAttributeValueLength: 8192,
28
- }
29
-
30
- const createTraces = (): PostHogTraces =>
31
- new PostHogTraces(
32
- {
33
- isDisabled: false,
34
- optedOut: false,
35
- getLibraryId: () => 'posthog-core',
36
- getLibraryVersion: () => '0.0.0',
37
- _sendTracesBatch: async () => ({ kind: 'ok' }),
38
- },
39
- config,
40
- { debug: vi.fn(), warn: vi.fn() } as unknown as Logger,
41
- () => ({}),
42
- new SyncSpanContextManager()
43
- )
44
-
45
- itWithGc('does not retain spans that never end', async () => {
46
- if (!gc) {
47
- throw new Error('Run this suite with NODE_OPTIONS=--expose-gc; see packages/core test:unit')
48
- }
49
- vi.useRealTimers()
50
- try {
51
- const traces = createTraces()
52
- // Started in their own frame so the handles are unreachable once it returns.
53
- const refs = ((): WeakRef<object>[] =>
54
- Array.from({ length: 1000 }, (_unused, i) => new WeakRef(traces.startSpan(`leaked-${i}`) as object)))()
55
-
56
- await new Promise((resolve) => setTimeout(resolve, 50))
57
- gc()
58
- await new Promise((resolve) => setTimeout(resolve, 50))
59
- gc()
60
-
61
- // A threshold, not zero: collection timing is not guaranteed, but a registry
62
- // holding every span would keep all 1000 alive.
63
- const alive = refs.filter((ref) => ref.deref() !== undefined).length
64
- expect(alive).toBeLessThan(100)
65
- } finally {
66
- vi.useFakeTimers()
67
- }
68
- })
69
- })
@@ -1,368 +0,0 @@
1
- import {
2
- buildOtlpSpan,
3
- buildOtlpTracesPayload,
4
- buildTracesResourceAttributes,
5
- msToUnixNanoString,
6
- spanKindToOtlp,
7
- } from './otlp'
8
- import type { OtlpSpan, ResolvedTracesConfig, SpanRecord } from './types'
9
-
10
- const record = (overrides: Partial<SpanRecord> = {}): SpanRecord => ({
11
- traceId: '4bf92f3577b34da6a3ce929d0e0e4736',
12
- spanId: '00f067aa0ba902b7',
13
- name: 'checkout',
14
- kind: 'internal',
15
- traceFlags: '01',
16
- parentIsRemote: false,
17
- attributes: {},
18
- events: [],
19
- startTime: 1_700_000_000_000,
20
- endTime: 1_700_000_000_080,
21
- ...overrides,
22
- })
23
-
24
- describe('OTLP span encoding', () => {
25
- describe('msToUnixNanoString', () => {
26
- it('encodes milliseconds as a nanosecond string', () => {
27
- expect(msToUnixNanoString(1_700_000_000_000)).toBe('1700000000000000000')
28
- })
29
-
30
- it('keeps sub-millisecond precision', () => {
31
- expect(msToUnixNanoString(1_700_000_000_000.5)).toBe('1700000000000500000')
32
- })
33
-
34
- it('stays exact beyond Number.MAX_SAFE_INTEGER', () => {
35
- // The whole point of string concatenation over `ms * 1e6`, which would
36
- // silently lose precision at this magnitude.
37
- const encoded = msToUnixNanoString(1_700_000_000_123)
38
- expect(encoded).toBe('1700000000123000000')
39
- expect(Number(encoded)).toBeGreaterThan(Number.MAX_SAFE_INTEGER)
40
- })
41
-
42
- it.each([0.9999999, 1.9999999, 999.9999999])(
43
- 'carries a rounded-up fraction into the next millisecond for %p',
44
- (ms) => {
45
- // Without the carry the padded fraction gains a seventh digit, producing
46
- // a malformed timestamp that 400s the whole request. Unreachable from a
47
- // real clock — float64 quantization at epoch-ms magnitude keeps the
48
- // fraction well below the carry — but reachable via a caller-supplied
49
- // `startTime`, which the validity check accepts anywhere in [0, MAX].
50
- const encoded = msToUnixNanoString(ms)
51
- expect(encoded).toHaveLength(String(Math.round(ms)).length + 6)
52
- expect(encoded).toMatch(/^\d+$/)
53
- }
54
- )
55
- })
56
-
57
- describe('spanKindToOtlp', () => {
58
- it.each([
59
- ['internal', 1],
60
- ['server', 2],
61
- ['client', 3],
62
- ['producer', 4],
63
- ['consumer', 5],
64
- ] as const)('maps %s to %i', (kind, expected) => {
65
- expect(spanKindToOtlp(kind)).toBe(expected)
66
- })
67
-
68
- it('defaults to internal', () => {
69
- expect(spanKindToOtlp(undefined)).toBe(1)
70
- })
71
- })
72
-
73
- describe('buildOtlpSpan', () => {
74
- it('builds the minimal shape', () => {
75
- expect(buildOtlpSpan(record())).toEqual({
76
- traceId: '4bf92f3577b34da6a3ce929d0e0e4736',
77
- spanId: '00f067aa0ba902b7',
78
- name: 'checkout',
79
- kind: 1,
80
- startTimeUnixNano: '1700000000000000000',
81
- endTimeUnixNano: '1700000000080000000',
82
- flags: 0x101,
83
- })
84
- })
85
-
86
- it('omits status when it was never set', () => {
87
- expect(buildOtlpSpan(record())).not.toHaveProperty('status')
88
- })
89
-
90
- it('encodes ok and error status codes', () => {
91
- expect(buildOtlpSpan(record({ status: { code: 'ok' } })).status).toEqual({ code: 1 })
92
- expect(buildOtlpSpan(record({ status: { code: 'error', message: 'boom' } })).status).toEqual({
93
- code: 2,
94
- message: 'boom',
95
- })
96
- })
97
-
98
- it('includes parent, tracestate, attributes and events when present', () => {
99
- const span = buildOtlpSpan(
100
- record({
101
- parentSpanId: 'b7ad6b7169203331',
102
- traceState: 'vendor=abc',
103
- attributes: { plan: 'pro' },
104
- events: [{ name: 'cache miss', timestamp: 1_700_000_000_040 }],
105
- })
106
- )
107
- expect(span.parentSpanId).toBe('b7ad6b7169203331')
108
- expect(span.traceState).toBe('vendor=abc')
109
- expect(span.attributes).toEqual([{ key: 'plan', value: { stringValue: 'pro' } }])
110
- expect(span.events).toEqual([{ name: 'cache miss', timeUnixNano: '1700000000040000000' }])
111
- })
112
-
113
- it('carries an event attribute drop as the proto counter', () => {
114
- const span = buildOtlpSpan(
115
- record({
116
- events: [{ name: 'query', timestamp: 1_700_000_000_040, droppedAttributesCount: 3 }],
117
- })
118
- )
119
- expect(span.events?.[0]).toMatchObject({ name: 'query', droppedAttributesCount: 3 })
120
- })
121
-
122
- it.each([
123
- ['none were dropped', 0],
124
- ['a hook wrote a negative', -2],
125
- ['a hook wrote a non-number', 'lots' as unknown as number],
126
- ])('omits the event drop counter when %s', (_label, dropped) => {
127
- // Coerced like the span's own counters: a non-integer here is refused for
128
- // the whole request, taking unrelated spans with it.
129
- const span = buildOtlpSpan(
130
- record({
131
- events: [{ name: 'query', timestamp: 1_700_000_000_040, droppedAttributesCount: dropped }],
132
- })
133
- )
134
- expect(span.events?.[0].droppedAttributesCount).toBeUndefined()
135
- })
136
-
137
- it('sets the sampled bit and marks a root span as known-not-remote', () => {
138
- // A root span has no parent context to be remote, which the OTel Go and
139
- // Java exporters also report as known-not-remote rather than unknown.
140
- expect(buildOtlpSpan(record()).flags).toBe(0x101)
141
- })
142
-
143
- it('marks a local parent as known-not-remote', () => {
144
- expect(buildOtlpSpan(record({ parentSpanId: 'b7ad6b7169203331' })).flags).toBe(0x101)
145
- })
146
-
147
- it('marks a parent that arrived as a header as remote', () => {
148
- expect(buildOtlpSpan(record({ parentSpanId: 'b7ad6b7169203331', parentIsRemote: true })).flags).toBe(0x301)
149
- })
150
-
151
- it('propagates an inbound sampled-out flag rather than overriding it', () => {
152
- // The span is still recorded and exported; what the wire says is the
153
- // decision the head sampler made.
154
- expect(buildOtlpSpan(record({ traceFlags: '00', parentIsRemote: true })).flags).toBe(0x300)
155
- })
156
-
157
- it('falls back to sampled when the flags byte is unusable', () => {
158
- expect(buildOtlpSpan(record({ traceFlags: 'zz' })).flags).toBe(0x101)
159
- })
160
- })
161
-
162
- describe('buildTracesResourceAttributes', () => {
163
- const config = (partial: Partial<ResolvedTracesConfig> = {}): ResolvedTracesConfig => ({
164
- flushIntervalMs: 5000,
165
- maxExportBatchSize: 512,
166
- maxQueueSize: 2048,
167
- beforeSpanSend: [],
168
- maxAttributesPerSpan: 128,
169
- maxEventsPerSpan: 128,
170
- maxAttributesPerEvent: 128,
171
- maxAttributeValueLength: 8192,
172
- maxLiveSpans: 10000,
173
- maxSpanAgeMs: 3600000,
174
- ...partial,
175
- })
176
-
177
- it('always emits service.name', () => {
178
- // The server reads service_name only from this attribute and stores an
179
- // empty string when it's missing, leaving spans unattributable.
180
- expect(buildTracesResourceAttributes(config(), 'posthog-node', '1.0.0')['service.name']).toBe('unknown_service')
181
- })
182
-
183
- it('uses the configured service name', () => {
184
- expect(buildTracesResourceAttributes(config({ serviceName: 'checkout' }), 'posthog-node', '1.0.0')).toMatchObject(
185
- {
186
- 'service.name': 'checkout',
187
- }
188
- )
189
- })
190
-
191
- it('includes environment and version only when set', () => {
192
- const attributes = buildTracesResourceAttributes(
193
- config({ environment: 'production', serviceVersion: '2.1.0' }),
194
- 'posthog-node',
195
- '1.0.0'
196
- )
197
- expect(attributes['deployment.environment']).toBe('production')
198
- expect(attributes['service.version']).toBe('2.1.0')
199
- expect(buildTracesResourceAttributes(config(), 'posthog-node', '1.0.0')).not.toHaveProperty(
200
- 'deployment.environment'
201
- )
202
- })
203
-
204
- it('protects SDK identity keys from user resource attributes', () => {
205
- const attributes = buildTracesResourceAttributes(
206
- config({ resourceAttributes: { 'telemetry.sdk.name': 'custom', 'host.name': 'web-01' } }),
207
- 'posthog-node',
208
- '1.0.0'
209
- )
210
- expect(attributes['telemetry.sdk.name']).toBe('posthog-node')
211
- expect(attributes['host.name']).toBe('web-01')
212
- })
213
- })
214
-
215
- describe('buildOtlpTracesPayload', () => {
216
- it('produces one resource, one scope, N spans', () => {
217
- const spans = [buildOtlpSpan(record()), buildOtlpSpan(record({ name: 'other' }))]
218
- const payload = buildOtlpTracesPayload(spans, { 'service.name': 'checkout' }, 'posthog-node', '1.0.0')
219
-
220
- expect(payload.resourceSpans).toHaveLength(1)
221
- expect(payload.resourceSpans[0].scopeSpans).toHaveLength(1)
222
- expect(payload.resourceSpans[0].scopeSpans[0].spans).toHaveLength(2)
223
- expect(payload.resourceSpans[0].scopeSpans[0].scope).toEqual({ name: 'posthog-node', version: '1.0.0' })
224
- expect(payload.resourceSpans[0].resource.attributes).toEqual([
225
- { key: 'service.name', value: { stringValue: 'checkout' } },
226
- ])
227
- })
228
- })
229
-
230
- describe('golden wire fixture', () => {
231
- it('matches the shape the ingestion service accepts', () => {
232
- // Pinned against the OTLP/JSON encoding the capture-logs service's own
233
- // trace fixtures use: hex ids, string nanosecond timestamps, integer kind
234
- // and status enums, and stringified int64 attribute values.
235
- const payload = buildOtlpTracesPayload(
236
- [
237
- buildOtlpSpan(
238
- record({
239
- parentSpanId: 'b7ad6b7169203331',
240
- name: 'GET /users/:id',
241
- kind: 'server',
242
- status: { code: 'error', message: 'boom' },
243
- attributes: {
244
- posthogDistinctId: 'user-123',
245
- sessionId: 'session-123',
246
- 'http.status_code': 500,
247
- 'http.duration_ratio': 0.25,
248
- cached: false,
249
- },
250
- events: [
251
- {
252
- name: 'exception',
253
- timestamp: 1_700_000_000_040,
254
- attributes: { 'exception.type': 'TypeError', 'exception.message': 'boom' },
255
- },
256
- ],
257
- })
258
- ),
259
- ],
260
- { 'service.name': 'checkout-api', 'telemetry.sdk.name': 'posthog-node' },
261
- 'posthog-node',
262
- '1.0.0'
263
- )
264
-
265
- expect(payload).toEqual({
266
- resourceSpans: [
267
- {
268
- resource: {
269
- attributes: [
270
- { key: 'service.name', value: { stringValue: 'checkout-api' } },
271
- { key: 'telemetry.sdk.name', value: { stringValue: 'posthog-node' } },
272
- ],
273
- },
274
- scopeSpans: [
275
- {
276
- scope: { name: 'posthog-node', version: '1.0.0' },
277
- spans: [
278
- {
279
- traceId: '4bf92f3577b34da6a3ce929d0e0e4736',
280
- spanId: '00f067aa0ba902b7',
281
- parentSpanId: 'b7ad6b7169203331',
282
- name: 'GET /users/:id',
283
- kind: 2,
284
- startTimeUnixNano: '1700000000000000000',
285
- endTimeUnixNano: '1700000000080000000',
286
- flags: 0x101,
287
- attributes: [
288
- { key: 'posthogDistinctId', value: { stringValue: 'user-123' } },
289
- { key: 'sessionId', value: { stringValue: 'session-123' } },
290
- { key: 'http.status_code', value: { intValue: '500' } },
291
- { key: 'http.duration_ratio', value: { doubleValue: 0.25 } },
292
- { key: 'cached', value: { boolValue: false } },
293
- ],
294
- events: [
295
- {
296
- name: 'exception',
297
- timeUnixNano: '1700000000040000000',
298
- attributes: [
299
- { key: 'exception.type', value: { stringValue: 'TypeError' } },
300
- { key: 'exception.message', value: { stringValue: 'boom' } },
301
- ],
302
- },
303
- ],
304
- status: { code: 2, message: 'boom' },
305
- },
306
- ],
307
- },
308
- ],
309
- },
310
- ],
311
- })
312
- })
313
- })
314
- })
315
-
316
- describe('wire string safety', () => {
317
- const lone = 'value \u{1F680}'.slice(0, 7)
318
-
319
- const encode = (record: Partial<SpanRecord> = {}): OtlpSpan =>
320
- buildOtlpSpan({
321
- traceId: 'a'.repeat(32),
322
- spanId: 'b'.repeat(16),
323
- name: 'checkout',
324
- kind: 'internal',
325
- attributes: {},
326
- events: [],
327
- startTime: 1,
328
- endTime: 2,
329
- ...record,
330
- } as SpanRecord)
331
-
332
- it('replaces a lone surrogate in every free-text field', () => {
333
- const span = encode({
334
- name: lone,
335
- traceState: `vendor=${lone}`,
336
- status: { code: 'error', message: lone },
337
- events: [{ name: lone, timestamp: 1 }],
338
- })
339
-
340
- expect(span.name).not.toContain('\ud83d')
341
- expect(span.events?.[0].name).not.toContain('\ud83d')
342
- expect(span.status?.message).not.toContain('\ud83d')
343
- expect(span.traceState).not.toContain('\ud83d')
344
- })
345
-
346
- it('keeps the span when a status message cannot be stringified', () => {
347
- const hostile = {
348
- toString() {
349
- throw new Error('toString exploded')
350
- },
351
- }
352
- const span = encode({ status: { code: 'error', message: hostile as unknown as string } })
353
-
354
- expect(span.name).toBe('checkout')
355
- expect(span.status?.message).toBe('[Unserializable]')
356
- })
357
-
358
- it('coerces a non-string status message', () => {
359
- const span = encode({ status: { code: 'error', message: 500 as unknown as string } })
360
-
361
- expect(span.status?.message).toBe('500')
362
- })
363
-
364
- it('falls back to internal for a prototype key passed as a kind', () => {
365
- expect(spanKindToOtlp('__proto__' as never)).toBe(1)
366
- expect(spanKindToOtlp('toString' as never)).toBe(1)
367
- })
368
- })