@@ -18,6 +18,7 @@ import {
1818 RELAY_ACTIVITY_PUBLISH_TYP ,
1919 signRelayJwt ,
2020} from "@t3tools/shared/relayJwt" ;
21+ import { getUrlDiagnostics } from "@t3tools/shared/urlDiagnostics" ;
2122import * as Cause from "effect/Cause" ;
2223import * as Context from "effect/Context" ;
2324import * as Crypto from "effect/Crypto" ;
@@ -98,6 +99,44 @@ export function isAgentActivityPublishingEnabled(value: string | null): boolean
9899 return value === "true" ;
99100}
100101
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+
101140export function resolveAgentActivityPublishingStartupState ( input : {
102141 readonly relayConfigured : boolean ;
103142 readonly publishEnabled : boolean ;
@@ -417,12 +456,12 @@ export const make = Effect.gen(function* () {
417456
418457 const publishThread : AgentAwarenessRelay [ "Service" ] [ "publishThread" ] = ( threadId ) =>
419458 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" , {
422461 threadId,
423- cause : Cause . pretty ( cause ) ,
424- } ) ;
425- } ) ,
462+ ... relayPublishCauseLogAttributes ( cause ) ,
463+ } ) ,
464+ ) ,
426465 Effect . withSpan ( "AgentAwarenessRelay.publishThread" ) ,
427466 withRelayClientTracing ,
428467 ) ;
@@ -467,7 +506,7 @@ export const make = Effect.gen(function* () {
467506 if ( logEnabledWhenReady ) {
468507 const relayConfig = yield * readRelayConfig . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
469508 yield * Effect . logInfo ( "agent activity publishing enabled after link reconciliation" , {
470- relayUrl : relayConfig ?. url ,
509+ ... relayUrlLogAttributes ( relayConfig ?. url ) ,
471510 } ) ;
472511 }
473512 return ;
@@ -499,7 +538,7 @@ export const make = Effect.gen(function* () {
499538 break ;
500539 case "enabled" :
501540 yield * Effect . logInfo ( "agent activity publishing enabled" , {
502- relayUrl : relayConfig ?. url ,
541+ ... relayUrlLogAttributes ( relayConfig ?. url ) ,
503542 } ) ;
504543 break ;
505544 }
0 commit comments