| @@ -18,6 +18,7 @@ import { · 17 unmodified lines |
| 18 | 18 | RELAY_ACTIVITY_PUBLISH_TYP, |
| 19 | 19 | signRelayJwt, |
| 20 | 20 | } from "@t3tools/shared/relayJwt"; |
| 21 | +import { getUrlDiagnostics } from "@t3tools/shared/urlDiagnostics"; |
| 21 | 22 | import * as Cause from "effect/Cause"; |
| 22 | 23 | import * as Context from "effect/Context"; |
| 23 | 24 | import * as Crypto from "effect/Crypto"; |
| @@ -98,6 +99,44 @@ export function isAgentActivityPublishingEnabled(value: string | null): boolean · 74 unmodified lines |
| 98 | 99 | return value === "true"; |
| 99 | 100 | } |
| 100 | 101 | |
| 102 | +export function relayUrlLogAttributes(relayUrl: string | undefined) { |
| 103 | + if (relayUrl === undefined) { |
| 104 | + return { relayUrlConfigured: false }; |
| 105 | + } |
| 106 | + const diagnostics = getUrlDiagnostics(relayUrl); |
| 107 | + return { |
| 108 | + relayUrlConfigured: true, |
| 109 | + relayUrlInputLength: diagnostics.inputLength, |
| 110 | + ...(diagnostics.protocol === undefined ? {} : { relayUrlProtocol: diagnostics.protocol }), |
| 111 | + ...(diagnostics.hostname === undefined ? {} : { relayUrlHostname: diagnostics.hostname }), |
| 112 | + }; |
| 113 | +} |
| 114 | + |
| 115 | +export function relayPublishCauseLogAttributes(cause: Cause.Cause<unknown>) { |
| 116 | + const failureTags = cause.reasons.flatMap((reason) => { |
| 117 | + if (!Cause.isFailReason(reason)) { |
| 118 | + return []; |
| 119 | + } |
| 120 | + const error = reason.error; |
| 121 | + if ( |
| 122 | + typeof error !== "object" || |
| 123 | + error === null || |
| 124 | + !("_tag" in error) || |
| 125 | + typeof error._tag !== "string" |
| 126 | + ) { |
| 127 | + return []; |
| 128 | + } |
| 129 | + return [error._tag]; |
| 130 | + }); |
| 131 | + return { |
| 132 | + causeReasonCount: cause.reasons.length, |
| 133 | + causeFailureCount: cause.reasons.filter(Cause.isFailReason).length, |
| 134 | + causeDefectCount: cause.reasons.filter(Cause.isDieReason).length, |
| 135 | + causeInterruptionCount: cause.reasons.filter(Cause.isInterruptReason).length, |
| 136 | + causeFailureTags: [...new Set(failureTags)], |
| 137 | + }; |
| 138 | +} |
| 139 | + |
| 101 | 140 | export function resolveAgentActivityPublishingStartupState(input: { |
| 102 | 141 | readonly relayConfigured: boolean; |
| 103 | 142 | readonly publishEnabled: boolean; |
| @@ -417,12 +456,12 @@ export const make = Effect.gen(function* () { · 313 unmodified lines |
| 417 | 456 | |
| 418 | 457 | const publishThread: AgentAwarenessRelay["Service"]["publishThread"] = (threadId) => |
| 419 | 458 | publishThreadUnsafe(threadId).pipe( |
| 420 | | − Effect.catchCause((cause) => { |
| 421 | | − return Effect.logWarning("agent activity publish failed", { |
| 459 | + Effect.catchCause((cause) => |
| 460 | + Effect.logWarning("agent activity publish failed", { |
| 422 | 461 | threadId, |
| 423 | | − cause: Cause.pretty(cause), |
| 424 | | − }); |
| 425 | | − }), |
| 462 | + ...relayPublishCauseLogAttributes(cause), |
| 463 | + }), |
| 464 | + ), |
| 426 | 465 | Effect.withSpan("AgentAwarenessRelay.publishThread"), |
| 427 | 466 | withRelayClientTracing, |
| 428 | 467 | ); |
| @@ -467,7 +506,7 @@ export const make = Effect.gen(function* () { · 38 unmodified lines |
| 467 | 506 | if (logEnabledWhenReady) { |
| 468 | 507 | const relayConfig = yield* readRelayConfig.pipe(Effect.orElseSucceed(() => null)); |
| 469 | 508 | yield* Effect.logInfo("agent activity publishing enabled after link reconciliation", { |
| 470 | | − relayUrl: relayConfig?.url, |
| 509 | + ...relayUrlLogAttributes(relayConfig?.url), |
| 471 | 510 | }); |
| 472 | 511 | } |
| 473 | 512 | return; |
| @@ -499,7 +538,7 @@ export const make = Effect.gen(function* () { · 25 unmodified lines |
| 499 | 538 | break; |
| 500 | 539 | case "enabled": |
| 501 | 540 | yield* Effect.logInfo("agent activity publishing enabled", { |
| 502 | | − relayUrl: relayConfig?.url, |
| 541 | + ...relayUrlLogAttributes(relayConfig?.url), |
| 503 | 542 | }); |
| 504 | 543 | break; |
| 505 | 544 | } |