@dxos/observability 0.16.0 → 0.17.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.
- package/dist/lib/chunk-ObservabilityExtension.mjs +33 -2
- package/dist/lib/chunk-ObservabilityExtension.mjs.map +1 -1
- package/dist/lib/chunk-OtelProxy.mjs +102 -0
- package/dist/lib/chunk-OtelProxy.mjs.map +1 -0
- package/dist/lib/chunk-OtelSpanSink.mjs +1 -1
- package/dist/lib/chunk-OtelSpanSink.mjs.map +1 -1
- package/dist/lib/extensions/otel/OtelProxy.mjs +1 -0
- package/dist/lib/index.mjs +2 -1
- package/dist/types/src/extensions/otel/OtelProxy.d.ts +18 -0
- package/dist/types/src/extensions/otel/OtelProxy.d.ts.map +1 -0
- package/dist/types/src/extensions/otel/OtelProxy.js +90 -0
- package/dist/types/src/extensions/otel/OtelProxy.js.map +1 -0
- package/dist/types/src/extensions/otel/OtelProxy.test.d.ts +2 -0
- package/dist/types/src/extensions/otel/OtelProxy.test.d.ts.map +1 -0
- package/dist/types/src/extensions/otel/OtelProxy.test.js +62 -0
- package/dist/types/src/extensions/otel/OtelProxy.test.js.map +1 -0
- package/dist/types/src/extensions/otel/tail-sampling.d.ts +1 -1
- package/dist/types/src/extensions/otel/tail-sampling.js +1 -1
- package/{src/extensions/otel/sinks.ts → dist/types/src/extensions/otel/worker-entrypoints.d.ts} +2 -5
- package/dist/types/src/extensions/otel/worker-entrypoints.d.ts.map +1 -0
- package/dist/types/src/extensions/otel/{sinks.js → worker-entrypoints.js} +2 -2
- package/dist/types/src/extensions/otel/worker-entrypoints.js.map +1 -0
- package/dist/types/src/extensions/posthog/before-send.d.ts +1 -0
- package/dist/types/src/extensions/posthog/before-send.d.ts.map +1 -1
- package/dist/types/src/extensions/posthog/before-send.js +38 -0
- package/dist/types/src/extensions/posthog/before-send.js.map +1 -1
- package/dist/types/src/extensions/posthog/before-send.test.js +52 -1
- package/dist/types/src/extensions/posthog/before-send.test.js.map +1 -1
- package/dist/types/src/extensions/posthog/extension.js +2 -2
- package/dist/types/src/extensions/posthog/extension.js.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/index.js +1 -1
- package/dist/types/src/index.js.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.js +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -21
- package/src/extensions/otel/OtelProxy.test.ts +74 -0
- package/src/extensions/otel/OtelProxy.ts +119 -0
- package/src/extensions/otel/tail-sampling.ts +1 -1
- package/{dist/types/src/extensions/otel/sinks.d.ts → src/extensions/otel/worker-entrypoints.ts} +5 -1
- package/src/extensions/posthog/before-send.test.ts +69 -1
- package/src/extensions/posthog/before-send.ts +45 -1
- package/src/extensions/posthog/extension.ts +2 -2
- package/src/index.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/types/src/extensions/otel/sinks.d.ts.map +0 -1
- package/dist/types/src/extensions/otel/sinks.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/observability",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Provides a common interface for app and platform observability",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -74,6 +74,10 @@
|
|
|
74
74
|
"types": "./dist/types/src/extensions/otel/OtelMetricsSink.d.ts",
|
|
75
75
|
"import": "./dist/lib/extensions/otel/OtelMetricsSink.mjs"
|
|
76
76
|
},
|
|
77
|
+
"./OtelProxy": {
|
|
78
|
+
"types": "./dist/types/src/extensions/otel/OtelProxy.d.ts",
|
|
79
|
+
"import": "./dist/lib/extensions/otel/OtelProxy.mjs"
|
|
80
|
+
},
|
|
77
81
|
"./OtelSpanSink": {
|
|
78
82
|
"types": "./dist/types/src/extensions/otel/OtelSpanSink.d.ts",
|
|
79
83
|
"import": "./dist/lib/extensions/otel/OtelSpanSink.mjs"
|
|
@@ -87,6 +91,20 @@
|
|
|
87
91
|
],
|
|
88
92
|
"dependencies": {
|
|
89
93
|
"@bufbuild/protobuf": "2.11.0",
|
|
94
|
+
"@dxos/async": "0.17.0",
|
|
95
|
+
"@dxos/client": "0.17.0",
|
|
96
|
+
"@dxos/client-protocol": "0.17.0",
|
|
97
|
+
"@dxos/config": "0.17.0",
|
|
98
|
+
"@dxos/context": "0.17.0",
|
|
99
|
+
"@dxos/echo": "0.17.0",
|
|
100
|
+
"@dxos/effect": "0.17.0",
|
|
101
|
+
"@dxos/invariant": "0.17.0",
|
|
102
|
+
"@dxos/log": "0.17.0",
|
|
103
|
+
"@dxos/log-store-idb": "0.17.0",
|
|
104
|
+
"@dxos/node-std": "0.17.0",
|
|
105
|
+
"@dxos/protocols": "0.17.0",
|
|
106
|
+
"@dxos/tracing": "0.17.0",
|
|
107
|
+
"@dxos/util": "0.17.0",
|
|
90
108
|
"@opentelemetry/api": "^1.9.1",
|
|
91
109
|
"@opentelemetry/api-logs": "^0.222.0",
|
|
92
110
|
"@opentelemetry/auto-instrumentations-web": "^0.67.0",
|
|
@@ -108,28 +126,14 @@
|
|
|
108
126
|
"posthog-js": "^1.422.5",
|
|
109
127
|
"posthog-node": "^5.51.4",
|
|
110
128
|
"uuid": "^9.0.0",
|
|
111
|
-
"zone.js": "^0.15.0"
|
|
112
|
-
"@dxos/async": "0.16.0",
|
|
113
|
-
"@dxos/client": "0.16.0",
|
|
114
|
-
"@dxos/client-protocol": "0.16.0",
|
|
115
|
-
"@dxos/config": "0.16.0",
|
|
116
|
-
"@dxos/context": "0.16.0",
|
|
117
|
-
"@dxos/echo": "0.16.0",
|
|
118
|
-
"@dxos/effect": "0.16.0",
|
|
119
|
-
"@dxos/invariant": "0.16.0",
|
|
120
|
-
"@dxos/log": "0.16.0",
|
|
121
|
-
"@dxos/log-store-idb": "0.16.0",
|
|
122
|
-
"@dxos/node-std": "0.16.0",
|
|
123
|
-
"@dxos/protocols": "0.16.0",
|
|
124
|
-
"@dxos/tracing": "0.16.0",
|
|
125
|
-
"@dxos/util": "0.16.0"
|
|
129
|
+
"zone.js": "^0.15.0"
|
|
126
130
|
},
|
|
127
131
|
"devDependencies": {
|
|
128
|
-
"@
|
|
129
|
-
"@dxos/
|
|
130
|
-
"@dxos/
|
|
131
|
-
"@dxos/
|
|
132
|
-
"@
|
|
132
|
+
"@dxos/ai": "0.17.0",
|
|
133
|
+
"@dxos/client-services": "0.17.0",
|
|
134
|
+
"@dxos/errors": "0.17.0",
|
|
135
|
+
"@dxos/network-manager": "0.17.0",
|
|
136
|
+
"@types/js-yaml": "^4.0.5"
|
|
133
137
|
},
|
|
134
138
|
"peerDependencies": {
|
|
135
139
|
"effect": "4.0.4"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import * as OtelProxy from './OtelProxy.ts';
|
|
8
|
+
|
|
9
|
+
const ORIGIN = 'https://app.test';
|
|
10
|
+
|
|
11
|
+
const options: OtelProxy.Options = {
|
|
12
|
+
url: 'https://eu.i.posthog.com/i',
|
|
13
|
+
token: 'phc_test',
|
|
14
|
+
extraOrigins: new Set(['tauri://localhost']),
|
|
15
|
+
maxBodySize: 16,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.unstubAllGlobals();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('OtelProxy', () => {
|
|
23
|
+
test('forwards a signal to PostHog with the project token', async () => {
|
|
24
|
+
const upstream = stubUpstream();
|
|
25
|
+
const response = await OtelProxy.handle(post('/api/otel/v1/logs'), options);
|
|
26
|
+
expect(response?.status).toBe(200);
|
|
27
|
+
expect(response?.headers.get('Access-Control-Allow-Origin')).toBe(ORIGIN);
|
|
28
|
+
expect(upstream).toEqual([{ url: 'https://eu.i.posthog.com/i/v1/logs', headers: expect.any(Headers), body: '{}' }]);
|
|
29
|
+
expect(upstream[0].headers.get('Authorization')).toBe('Bearer phc_test');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('admits an extra origin and refuses any other, or none', async () => {
|
|
33
|
+
const upstream = stubUpstream();
|
|
34
|
+
expect((await OtelProxy.handle(post('/api/otel/v1/traces', 'tauri://localhost'), options))?.status).toBe(200);
|
|
35
|
+
expect((await OtelProxy.handle(post('/api/otel/v1/traces', 'https://elsewhere.test'), options))?.status).toBe(403);
|
|
36
|
+
expect((await OtelProxy.handle(post('/api/otel/v1/traces', null), options))?.status).toBe(403);
|
|
37
|
+
expect(upstream).toHaveLength(1);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('answers 503 without the token and 413 over the size limit', async () => {
|
|
41
|
+
stubUpstream();
|
|
42
|
+
expect((await OtelProxy.handle(post('/api/otel/v1/metrics'), { ...options, token: undefined }))?.status).toBe(503);
|
|
43
|
+
expect((await OtelProxy.handle(post('/api/otel/v1/metrics', ORIGIN, 'x'.repeat(17)), options))?.status).toBe(413);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('answers 502 when PostHog is unreachable', async () => {
|
|
47
|
+
vi.stubGlobal('fetch', async () => {
|
|
48
|
+
throw new TypeError('fetch failed');
|
|
49
|
+
});
|
|
50
|
+
expect((await OtelProxy.handle(post('/api/otel/v1/logs'), options))?.status).toBe(502);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('leaves any other path to the caller', () => {
|
|
54
|
+
expect(OtelProxy.handle(post('/api/otel/v1/other'), options)).toBeUndefined();
|
|
55
|
+
expect(OtelProxy.handle(post('/api/feedback-logs'), options)).toBeUndefined();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const post = (path: string, origin: string | null = ORIGIN, body = '{}') =>
|
|
60
|
+
new Request(`${ORIGIN}${path}`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { 'Content-Type': 'application/json', ...(origin ? { Origin: origin } : {}) },
|
|
63
|
+
body,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const stubUpstream = () => {
|
|
67
|
+
const requests: { url: string; headers: Headers; body: string }[] = [];
|
|
68
|
+
vi.stubGlobal('fetch', async (url: string, init: RequestInit) => {
|
|
69
|
+
const body = await new Response(init.body).text();
|
|
70
|
+
requests.push({ url, headers: new Headers(init.headers), body });
|
|
71
|
+
return new Response('{}', { status: 200, headers: { 'Content-Type': 'application/json' } });
|
|
72
|
+
});
|
|
73
|
+
return requests;
|
|
74
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
// Cloudflare Workers import this through its own subpath, so it uses only the Fetch API.
|
|
8
|
+
|
|
9
|
+
/** The route a client's OTel exporter posts to on the deployment that serves it. */
|
|
10
|
+
export const PREFIX = '/api/otel';
|
|
11
|
+
|
|
12
|
+
const SIGNALS = new Set(['/v1/traces', '/v1/logs', '/v1/metrics']);
|
|
13
|
+
|
|
14
|
+
export type Options = {
|
|
15
|
+
/** PostHog's OTLP base URL, e.g. `https://eu.i.posthog.com/i`. */
|
|
16
|
+
url?: string;
|
|
17
|
+
/** The project token, sent upstream as the bearer token so it never reaches the client. */
|
|
18
|
+
token?: string;
|
|
19
|
+
/** Origins admitted besides the deployment's own, such as a native build's. */
|
|
20
|
+
extraOrigins?: ReadonlySet<string>;
|
|
21
|
+
/** Largest body forwarded, in bytes. */
|
|
22
|
+
maxBodySize: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** A POST always carries `Origin`, so a missing one is refused. */
|
|
26
|
+
const isAllowedOrigin = (request: Request, origin: string | null, extraOrigins?: ReadonlySet<string>): boolean =>
|
|
27
|
+
origin !== null && (origin === new URL(request.url).origin || extraOrigins?.has(origin) === true);
|
|
28
|
+
|
|
29
|
+
const corsHeaders = (
|
|
30
|
+
request: Request,
|
|
31
|
+
origin: string | null,
|
|
32
|
+
extraOrigins?: ReadonlySet<string>,
|
|
33
|
+
): Record<string, string> => ({
|
|
34
|
+
'Access-Control-Allow-Origin': isAllowedOrigin(request, origin, extraOrigins) ? (origin ?? '') : '',
|
|
35
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
36
|
+
'Access-Control-Allow-Headers': 'Content-Type, Content-Encoding',
|
|
37
|
+
'Vary': 'Origin',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Forwards an OTLP request on `/api/otel/v1/{traces,logs,metrics}` to PostHog with the project token.
|
|
42
|
+
* Returns `undefined` for any other path, so the caller can route it elsewhere.
|
|
43
|
+
*/
|
|
44
|
+
export const handle = (request: Request, options: Options): Promise<Response> | undefined => {
|
|
45
|
+
const { pathname } = new URL(request.url);
|
|
46
|
+
const signal = pathname.startsWith(`${PREFIX}/`) ? pathname.slice(PREFIX.length) : undefined;
|
|
47
|
+
return signal && SIGNALS.has(signal) ? forward(request, options, signal) : undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const forward = async (
|
|
51
|
+
request: Request,
|
|
52
|
+
{ url, token, extraOrigins, maxBodySize }: Options,
|
|
53
|
+
signal: string,
|
|
54
|
+
): Promise<Response> => {
|
|
55
|
+
const origin = request.headers.get('Origin');
|
|
56
|
+
const cors = corsHeaders(request, origin, extraOrigins);
|
|
57
|
+
if (request.method === 'OPTIONS') {
|
|
58
|
+
return new Response(null, { status: 204, headers: cors });
|
|
59
|
+
}
|
|
60
|
+
if (request.method !== 'POST') {
|
|
61
|
+
return new Response('Method not allowed', { status: 405, headers: cors });
|
|
62
|
+
}
|
|
63
|
+
if (!isAllowedOrigin(request, origin, extraOrigins)) {
|
|
64
|
+
return new Response('Forbidden', { status: 403, headers: cors });
|
|
65
|
+
}
|
|
66
|
+
if (!url || !token) {
|
|
67
|
+
return new Response('OTel proxy not configured', { status: 503, headers: cors });
|
|
68
|
+
}
|
|
69
|
+
if (!request.body) {
|
|
70
|
+
return new Response('Empty body', { status: 400, headers: cors });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const headers: Record<string, string> = {
|
|
74
|
+
'Content-Type': request.headers.get('Content-Type') ?? 'application/json',
|
|
75
|
+
'Authorization': `Bearer ${token}`,
|
|
76
|
+
};
|
|
77
|
+
for (const name of ['Content-Encoding', 'Content-Length']) {
|
|
78
|
+
const value = request.headers.get(name);
|
|
79
|
+
if (value) {
|
|
80
|
+
headers[name] = value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let size = 0;
|
|
85
|
+
let tooLarge = false;
|
|
86
|
+
const { readable, writable } = new TransformStream<Uint8Array, Uint8Array>({
|
|
87
|
+
transform: (chunk, controller) => {
|
|
88
|
+
size += chunk.byteLength;
|
|
89
|
+
if (size > maxBodySize) {
|
|
90
|
+
tooLarge = true;
|
|
91
|
+
controller.error(new Error('Payload too large'));
|
|
92
|
+
} else {
|
|
93
|
+
controller.enqueue(chunk);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const piped = request.body.pipeTo(writable).catch(() => {});
|
|
98
|
+
|
|
99
|
+
let upstream: Response | undefined;
|
|
100
|
+
try {
|
|
101
|
+
upstream = await fetch(`${url.replace(/\/$/, '')}${signal}`, { method: 'POST', headers, body: readable });
|
|
102
|
+
} catch {
|
|
103
|
+
// An aborted body stream rejects the fetch, as does an unreachable upstream. A fetch that failed before reading
|
|
104
|
+
// leaves the pipe blocked on backpressure, so the body is cancelled to end it.
|
|
105
|
+
await readable.cancel().catch(() => {});
|
|
106
|
+
}
|
|
107
|
+
await piped;
|
|
108
|
+
|
|
109
|
+
if (tooLarge) {
|
|
110
|
+
return new Response('Payload too large', { status: 413, headers: cors });
|
|
111
|
+
}
|
|
112
|
+
if (!upstream) {
|
|
113
|
+
return new Response('Bad gateway', { status: 502, headers: cors });
|
|
114
|
+
}
|
|
115
|
+
return new Response(upstream.body, {
|
|
116
|
+
status: upstream.status,
|
|
117
|
+
headers: { 'Content-Type': upstream.headers.get('Content-Type') ?? 'application/json', ...cors },
|
|
118
|
+
});
|
|
119
|
+
};
|
|
@@ -14,7 +14,7 @@ import * as SpanAttributes from '@dxos/effect/SpanAttributes';
|
|
|
14
14
|
* cannot know that the span will fail, and it sees the span name before the provider has annotated
|
|
15
15
|
* it. Both decisions are only available once the span has ended — which is what "tail" means. The
|
|
16
16
|
* canonical implementation of this is the OpenTelemetry Collector's tail-sampling processor, which
|
|
17
|
-
* buffers whole traces server-side; there is no collector between Composer and
|
|
17
|
+
* buffers whole traces server-side; there is no collector between Composer and PostHog, so the same
|
|
18
18
|
* decisions are made here instead, on the spans this realm produced.
|
|
19
19
|
*
|
|
20
20
|
* The rules are the canonical tail-sampling set — keep what errored, keep what was slow, sample the
|
package/{dist/types/src/extensions/otel/sinks.d.ts → src/extensions/otel/worker-entrypoints.ts}
RENAMED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
1
5
|
export * as OtelLogSink from './OtelLogSink.ts';
|
|
2
6
|
export * as OtelMetricsSink from './OtelMetricsSink.ts';
|
|
7
|
+
export * as OtelProxy from './OtelProxy.ts';
|
|
3
8
|
export * as OtelSpanSink from './OtelSpanSink.ts';
|
|
4
|
-
//# sourceMappingURL=sinks.d.ts.map
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type CaptureResult } from 'posthog-js';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import { dropBenignExceptions } from './before-send.ts';
|
|
8
|
+
import { dropBenignExceptions, redactInvitationCodes } from './before-send.ts';
|
|
9
9
|
|
|
10
10
|
const exception = (...values: string[]): CaptureResult => ({
|
|
11
11
|
uuid: '00000000-0000-0000-0000-000000000000',
|
|
@@ -34,3 +34,71 @@ describe('dropBenignExceptions', () => {
|
|
|
34
34
|
expect(dropBenignExceptions(pageview)).toBe(pageview);
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
|
+
|
|
38
|
+
describe('redactInvitationCodes', () => {
|
|
39
|
+
const capture = (properties: CaptureResult['properties'], $set_once?: CaptureResult['$set_once']): CaptureResult => ({
|
|
40
|
+
uuid: '00000000-0000-0000-0000-000000000000',
|
|
41
|
+
event: '$pageview',
|
|
42
|
+
properties,
|
|
43
|
+
...($set_once && { $set_once }),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('removes the code from URLs and leaves the rest of each URL as it was', () => {
|
|
47
|
+
const result = redactInvitationCodes(
|
|
48
|
+
capture(
|
|
49
|
+
{
|
|
50
|
+
$current_url: 'https://drawing.sh/space/diagram?spaceInvitationCode=SECRET',
|
|
51
|
+
$referrer: 'https://drawing.sh/?a=1&spaceInvitationCode=SECRET&b=2#top',
|
|
52
|
+
$pathname: '/space/diagram',
|
|
53
|
+
count: 3,
|
|
54
|
+
},
|
|
55
|
+
{ $initial_current_url: 'https://drawing.sh/?a=1&spaceInvitationCode=SECRET' },
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
expect(result?.properties).toEqual({
|
|
59
|
+
$current_url: 'https://drawing.sh/space/diagram',
|
|
60
|
+
$referrer: 'https://drawing.sh/?a=1&b=2#top',
|
|
61
|
+
$pathname: '/space/diagram',
|
|
62
|
+
count: 3,
|
|
63
|
+
});
|
|
64
|
+
expect(result?.$set_once).toEqual({ $initial_current_url: 'https://drawing.sh/?a=1' });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('removes every occurrence of a repeated parameter', () => {
|
|
68
|
+
const result = redactInvitationCodes(
|
|
69
|
+
capture({
|
|
70
|
+
$current_url: 'https://drawing.sh/?spaceInvitationCode=FIRST&spaceInvitationCode=SECOND',
|
|
71
|
+
$referrer: 'https://drawing.sh/?spaceInvitationCode=FIRST&a=1&spaceInvitationCode=SECOND#top',
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
expect(result?.properties).toEqual({
|
|
75
|
+
$current_url: 'https://drawing.sh/',
|
|
76
|
+
$referrer: 'https://drawing.sh/?a=1#top',
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('matches the parameter by its decoded name', () => {
|
|
81
|
+
const result = redactInvitationCodes(
|
|
82
|
+
capture({ $current_url: 'https://drawing.sh/?spaceInvitation%43ode=SECRET&a=1' }),
|
|
83
|
+
);
|
|
84
|
+
expect(result?.properties).toEqual({ $current_url: 'https://drawing.sh/?a=1' });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('removes the code from person properties nested in the event properties', () => {
|
|
88
|
+
const result = redactInvitationCodes(
|
|
89
|
+
capture({
|
|
90
|
+
$set: { $initial_current_url: 'https://drawing.sh/?spaceInvitationCode=SECRET' },
|
|
91
|
+
$set_once: { urls: ['https://drawing.sh/?spaceInvitationCode=SECRET'] },
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
expect(result?.properties).toEqual({
|
|
95
|
+
$set: { $initial_current_url: 'https://drawing.sh/' },
|
|
96
|
+
$set_once: { urls: ['https://drawing.sh/'] },
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('leaves strings without the parameter untouched', () => {
|
|
101
|
+
const properties = { $current_url: 'https://drawing.sh/?q=a%20b', title: 'what? no', count: 1 };
|
|
102
|
+
expect(redactInvitationCodes(capture(properties))?.properties).toEqual(properties);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2026 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type BeforeSendFn } from 'posthog-js';
|
|
5
|
+
import { type BeforeSendFn, type Properties } from 'posthog-js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Browser-raised errors with no stack and no effect on the user: a ResizeObserver callback that resized an element
|
|
@@ -24,3 +24,47 @@ export const dropBenignExceptions: BeforeSendFn = (capture) => {
|
|
|
24
24
|
);
|
|
25
25
|
return benign ? null : capture;
|
|
26
26
|
};
|
|
27
|
+
|
|
28
|
+
const INVITATION_PARAM = 'spaceInvitationCode';
|
|
29
|
+
|
|
30
|
+
const redactUrl = (value: string): string => {
|
|
31
|
+
if (!value.includes('?')) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
let url: URL;
|
|
35
|
+
try {
|
|
36
|
+
url = new URL(value);
|
|
37
|
+
} catch {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
if (!url.searchParams.has(INVITATION_PARAM)) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
url.searchParams.delete(INVITATION_PARAM);
|
|
44
|
+
return url.toString();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Redacts every string in a property value, including person properties nested as `properties.$set`. */
|
|
48
|
+
const redactValue = (value: unknown): unknown => {
|
|
49
|
+
if (typeof value === 'string') {
|
|
50
|
+
return redactUrl(value);
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return value.map(redactValue);
|
|
54
|
+
}
|
|
55
|
+
if (value !== null && typeof value === 'object') {
|
|
56
|
+
return redactProperties(value);
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const redactProperties = (properties: object): Properties =>
|
|
62
|
+
Object.fromEntries(Object.entries(properties).map(([key, value]) => [key, redactValue(value)]));
|
|
63
|
+
|
|
64
|
+
export const redactInvitationCodes: BeforeSendFn = (capture) =>
|
|
65
|
+
capture && {
|
|
66
|
+
...capture,
|
|
67
|
+
properties: redactProperties(capture.properties),
|
|
68
|
+
...(capture.$set && { $set: redactProperties(capture.$set) }),
|
|
69
|
+
...(capture.$set_once && { $set_once: redactProperties(capture.$set_once) }),
|
|
70
|
+
};
|
|
@@ -13,7 +13,7 @@ import { gzip, isNode } from '@dxos/util';
|
|
|
13
13
|
import * as ObservabilityExtension from '../../ObservabilityExtension.ts';
|
|
14
14
|
import { DXOS_VERSION } from '../../version.ts';
|
|
15
15
|
import { stubExtension } from '../stub.ts';
|
|
16
|
-
import { dropBenignExceptions } from './before-send.ts';
|
|
16
|
+
import { dropBenignExceptions, redactInvitationCodes } from './before-send.ts';
|
|
17
17
|
import {
|
|
18
18
|
AI_GENERATION_EVENT,
|
|
19
19
|
AI_SPAN_EVENT,
|
|
@@ -174,7 +174,7 @@ export const extensions: (options: ExtensionsOptions) => Effect.Effect<Observabi
|
|
|
174
174
|
blockSelector: `:not(body):has(> iframe:not(.${REPLAY_IFRAME_CLASS}))`,
|
|
175
175
|
...posthogConfig?.session_recording,
|
|
176
176
|
},
|
|
177
|
-
before_send: [dropBenignExceptions, ...[posthogConfig?.before_send ?? []].flat()],
|
|
177
|
+
before_send: [dropBenignExceptions, redactInvitationCodes, ...[posthogConfig?.before_send ?? []].flat()],
|
|
178
178
|
...(recordingStart ? { disable_session_recording: true } : {}),
|
|
179
179
|
});
|
|
180
180
|
if (recordingStart) {
|
package/src/index.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
export * as Observability from './Observability.ts';
|
|
6
6
|
export * as ObservabilityExtension from './ObservabilityExtension.ts';
|
|
7
7
|
export * from './ai/index.ts';
|
|
8
|
-
export * from './extensions/otel/
|
|
8
|
+
export * from './extensions/otel/worker-entrypoints.ts';
|
|
9
9
|
export * from './providers/index.ts';
|
package/src/version.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sinks.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/otel/sinks.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sinks.js","sourceRoot":"","sources":["../../../../../src/extensions/otel/sinks.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF,gGAAgG;AAChG,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC"}
|