mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 23:03:09 +00:00
fix(render): add end-to-end observability (#1248)
This commit is contained in:
@@ -161,6 +161,7 @@ export {
|
||||
quantizeTimeToFrame,
|
||||
type MediaVisualStyleProperty,
|
||||
} from "./inline-scripts/parityContract";
|
||||
export { redactTelemetryString } from "./telemetryRedaction";
|
||||
export type {
|
||||
HyperframePickerApi,
|
||||
HyperframePickerBoundingBox,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { redactTelemetryString } from "./telemetryRedaction.js";
|
||||
|
||||
describe("redactTelemetryString", () => {
|
||||
it("redacts macOS, Linux, Windows, file URLs, and URL query strings", () => {
|
||||
expect(
|
||||
redactTelemetryString(
|
||||
[
|
||||
"/Users/alice/project/video.mp4",
|
||||
"/home/ubuntu/project/video.mp4",
|
||||
"/workspace/app/video.mp4",
|
||||
"C:\\Users\\Alice\\project\\video.mp4",
|
||||
"file:///tmp/render/video.mp4",
|
||||
"https://example.com/video.mp4?token=secret",
|
||||
].join(" "),
|
||||
),
|
||||
).toBe("[path] [path] [path] [path] [file-url] https://example.com/video.mp4?…");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
const MAX_TELEMETRY_STRING_LENGTH = 240;
|
||||
|
||||
function truncateTelemetryString(value: string, maxLength: number): string {
|
||||
if (value.length <= maxLength) return value;
|
||||
return `${value.slice(0, maxLength - 1)}…`;
|
||||
}
|
||||
|
||||
function redactUrlQueryStrings(value: string): string {
|
||||
return value.replace(/\b(https?:\/\/[^\s?]+)\?[^\s]*/g, "$1?…");
|
||||
}
|
||||
|
||||
function redactFilePaths(value: string): string {
|
||||
return value
|
||||
.replace(/file:\/\/[^\s'")]+/g, "[file-url]")
|
||||
.replace(/\/Users\/[^\s'")]+/g, "[path]")
|
||||
.replace(/\/(?:home|root|opt|app|workspace|srv|mnt)\/[^\s'")]+/g, "[path]")
|
||||
.replace(/\/(?:private\/)?(?:var|tmp)\/[^\s'")]+/g, "[path]")
|
||||
.replace(/[A-Za-z]:\\[^\s'")]+/g, "[path]");
|
||||
}
|
||||
|
||||
export function redactTelemetryString(
|
||||
value: string,
|
||||
maxLength = MAX_TELEMETRY_STRING_LENGTH,
|
||||
): string {
|
||||
return truncateTelemetryString(redactFilePaths(redactUrlQueryStrings(value)), maxLength);
|
||||
}
|
||||
Reference in New Issue
Block a user