| @@ -18,6 +18,7 @@ import { · 17 unmodified lines |
| 18 | RELAY_ACTIVITY_PUBLISH_TYP, | 18 | RELAY_ACTIVITY_PUBLISH_TYP, |
| 19 | signRelayJwt, | 19 | signRelayJwt, |
| 20 | } from "@t3tools/shared/relayJwt"; | 20 | } from "@t3tools/shared/relayJwt"; |
| | 21 | import { getUrlDiagnostics } from "@t3tools/shared/urlDiagnostics"; |
| 21 | import * as Cause from "effect/Cause"; | 22 | import * as Cause from "effect/Cause"; |
| 22 | import * as Context from "effect/Context"; | 23 | import * as Context from "effect/Context"; |
| 23 | import * as Crypto from "effect/Crypto"; | 24 | import * as Crypto from "effect/Crypto"; |
| @@ -98,6 +99,44 @@ export function isAgentActivityPublishingEnabled(value: string | null): boolean · 74 unmodified lines |
| 98 | return value === "true"; | 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 | export function resolveAgentActivityPublishingStartupState(input: { | 140 | export function resolveAgentActivityPublishingStartupState(input: { |
| 102 | readonly relayConfigured: boolean; | 141 | readonly relayConfigured: boolean; |
| 103 | readonly publishEnabled: boolean; | 142 | readonly publishEnabled: boolean; |
| @@ -417,12 +456,12 @@ export const make = Effect.gen(function* () { · 313 unmodified lines |
| 417 | | 456 | |
| 418 | const publishThread: AgentAwarenessRelay["Service"]["publishThread"] = (threadId) => | 457 | const publishThread: AgentAwarenessRelay["Service"]["publishThread"] = (threadId) => |
| 419 | publishThreadUnsafe(threadId).pipe( | 458 | publishThreadUnsafe(threadId).pipe( |
| 420 | Effect.catchCause((cause) => { | 459 | Effect.catchCause((cause) => |
| 421 | return Effect.logWarning("agent activity publish failed", { | 460 | Effect.logWarning("agent activity publish failed", { |
| 422 | threadId, | 461 | threadId, |
| 423 | cause: Cause.pretty(cause), | 462 | ...relayPublishCauseLogAttributes(cause), |
| 424 | }); | 463 | }), |
| 425 | }), | 464 | ), |
| 426 | Effect.withSpan("AgentAwarenessRelay.publishThread"), | 465 | Effect.withSpan("AgentAwarenessRelay.publishThread"), |
| 427 | withRelayClientTracing, | 466 | withRelayClientTracing, |
| 428 | ); | 467 | ); |
| @@ -467,7 +506,7 @@ export const make = Effect.gen(function* () { · 38 unmodified lines |
| 467 | if (logEnabledWhenReady) { | 506 | if (logEnabledWhenReady) { |
| 468 | const relayConfig = yield* readRelayConfig.pipe(Effect.orElseSucceed(() => null)); | 507 | const relayConfig = yield* readRelayConfig.pipe(Effect.orElseSucceed(() => null)); |
| 469 | yield* Effect.logInfo("agent activity publishing enabled after link reconciliation", { | 508 | yield* Effect.logInfo("agent activity publishing enabled after link reconciliation", { |
| 470 | relayUrl: relayConfig?.url, | 509 | ...relayUrlLogAttributes(relayConfig?.url), |
| 471 | }); | 510 | }); |
| 472 | } | 511 | } |
| 473 | return; | 512 | return; |
| @@ -499,7 +538,7 @@ export const make = Effect.gen(function* () { · 25 unmodified lines |
| 499 | break; | 538 | break; |
| 500 | case "enabled": | 539 | case "enabled": |
| 501 | yield* Effect.logInfo("agent activity publishing enabled", { | 540 | yield* Effect.logInfo("agent activity publishing enabled", { |
| 502 | relayUrl: relayConfig?.url, | 541 | ...relayUrlLogAttributes(relayConfig?.url), |
| 503 | }); | 542 | }); |
| 504 | break; | 543 | break; |
| 505 | } | 544 | } |