Skip to content

Commit 0732c54

Browse files
committed
fix(server): redact connection tickets from logged span causes
1 parent 81b9f93 commit 0732c54

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎packages/shared/src/observability.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,10 @@ describe("observability", () => {
405405
Effect.provideService(Tracer.Tracer, tracer),
406406
);
407407
yield* Effect.die(new Error(`RequestParseError (GET ${url})`)).pipe(
408+
Effect.tapCause((cause) => Effect.logError(cause)),
408409
Effect.withSpan("DeviceHubProxy.proxyWebSocket"),
409410
Effect.provideService(Tracer.Tracer, tracer),
411+
Effect.provide(Logger.layer([Logger.tracerLogger], { mergeWithExisting: false })),
410412
Effect.exit,
411413
);
412414
yield* sink.close();
@@ -415,6 +417,7 @@ describe("observability", () => {
415417
const exported = delegates.map((span) =>
416418
JSON.stringify({
417419
attributes: Object.fromEntries(span.attributes),
420+
events: span.events.map(([, , attributes]) => attributes),
418421
exit:
419422
span.status._tag === "Ended" && Exit.isFailure(span.status.exit)
420423
? Cause.pretty(span.status.exit.cause)
@@ -426,6 +429,7 @@ describe("observability", () => {
426429
assert.notInclude(text, "proof-secret");
427430
}
428431
assert.include(written, "wsTicket=<redacted>&dpop=<redacted>&clientSurface=web");
432+
assert.include(exported.join("\n"), "effect.cause");
429433
}),
430434
),
431435
);

‎packages/shared/src/observability.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,11 @@ class LocalFileSpan implements Tracer.Span {
623623
}
624624

625625
event(name: string, startTime: bigint, attributes?: Record<string, unknown>): void {
626-
const nextAttributes = attributes ?? {};
626+
const cause = attributes?.["effect.cause"];
627+
const nextAttributes =
628+
typeof cause === "string"
629+
? { ...attributes, "effect.cause": redactUrlCredentials(cause) }
630+
: (attributes ?? {});
627631
this.events.push([name, startTime, nextAttributes]);
628632
this.delegate.event(name, startTime, nextAttributes);
629633
}

0 commit comments

Comments
 (0)