@@ -30,6 +30,7 @@ public static IServiceCollection AddDebugProbe(
3030 public static IApplicationBuilder UseDebugProbe ( this IApplicationBuilder app )
3131 {
3232 app . UseMiddleware < DebugProbeMiddleware > ( ) ;
33+ app . ApplicationServices . GetRequiredService < DebugEntryStore > ( ) ;
3334
3435 if ( app is WebApplication webApp )
3536 {
@@ -59,59 +60,83 @@ public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app)
5960 var prettyRequest = JsonUtils . Format ( item . RequestBody ) ;
6061 var prettyResponse = JsonUtils . Format ( item . ResponseBody ) ;
6162
62- var html = HtmlRenderer . RenderDetailsPage ( item , prettyRequest , prettyResponse ) ;
63+ var html = HtmlRenderer . RenderDetailsPage ( item , store . Environment , prettyRequest , prettyResponse ) ;
6364
6465 ctx . Response . ContentType = "text/html" ;
6566 await ctx . Response . WriteAsync ( html ) ;
6667 } ) . ExcludeFromDescription ( ) ;
6768
68- webApp . MapGet ( "/debug/compare/{id}" , async ( string id , string url , DebugEntryStore store ) =>
69+ webApp . MapGet ( "/debug/compare/{id}" , async ( string id , string baseUrl , string remoteTraceId , DebugEntryStore store ) =>
6970 {
70- var local = store . Get ( id ) ;
71- if ( local is null )
71+ var localEnvironment = store . Environment ;
72+ var localEntry = store . Get ( id ) ;
73+ if ( localEntry is null )
7274 {
7375 return Results . NotFound ( "Local trace not found" ) ;
7476 }
7577
76- DebugEntry ? remote ;
78+
79+ var normalizedBaseUrl = baseUrl . TrimEnd ( '/' ) ;
80+
81+ var remoteEnvironmentUrl =
82+ $ "{ normalizedBaseUrl } /debug/environment";
83+
84+ var remoteEntryUrl =
85+ $ "{ normalizedBaseUrl } /debug/json/{ remoteTraceId } ";
86+
87+ DebugEntry ? remoteEntry ;
88+ DebugEnvironment ? remoteEnvironment ;
7789
7890 try
7991 {
80- remote = await Http . GetFromJsonAsync < DebugEntry > ( url ) ;
92+ remoteEnvironment = await Http . GetFromJsonAsync < DebugEnvironment > ( remoteEnvironmentUrl ) ;
93+
94+ if ( remoteEnvironment is null )
95+ {
96+ return Results . BadRequest ( "Failed to load remote environment" ) ;
97+ }
98+
99+ remoteEntry = await Http . GetFromJsonAsync < DebugEntry > ( remoteEntryUrl ) ;
100+
101+ if ( remoteEntry is null )
102+ {
103+ return Results . NotFound ( "Remote trace not found" ) ;
104+ }
81105 }
82106 catch
83107 {
84108 return Results . BadRequest ( "Failed to reach remote server" ) ;
85109 }
86110
87- if ( remote is null )
88- {
89- return Results . NotFound ( "Remote trace not found" ) ;
90- }
91-
92- var diff = DebugEntryComparer . Compare ( local , remote ) ;
111+
112+ var diff = DebugEntryComparer . Compare ( localEntry , remoteEntry ) ;
93113
94114 return Results . Ok ( new
95115 {
96- method = new { local = local . Method , remote = remote . Method } ,
97- path = new { local = local . Path , remote = remote . Path } ,
98- status = new { local = local . StatusCode , remote = remote . StatusCode } ,
116+ method = new { local = localEntry . Method , remote = remoteEntry . Method } ,
117+ path = new { local = localEntry . Path , remote = remoteEntry . Path } ,
118+ status = new { local = localEntry . StatusCode , remote = remoteEntry . StatusCode } ,
99119
100120 requestTime = new
101121 {
102- local = local . RequestTimeUtc . ToLocalTime ( ) . ToString ( "HH:mm:ss" ) ,
103- remote = remote . RequestTimeUtc . ToLocalTime ( ) . ToString ( "HH:mm:ss" ) ,
122+ local = localEntry . RequestTimeUtc . ToLocalTime ( ) . ToString ( "HH:mm:ss" ) ,
123+ remote = remoteEntry . RequestTimeUtc . ToLocalTime ( ) . ToString ( "HH:mm:ss" ) ,
104124 } ,
105125
106- environment = new { local = local . Environment , remote = remote . Environment } ,
107- culture = new { local = local . Culture , remote = remote . Culture } ,
108- requestBody = new { local = local . RequestBody ?? "" , remote = remote . RequestBody ?? "" } ,
109- responseBody = new { local = local . ResponseBody ?? "" , remote = remote . ResponseBody ?? "" } ,
126+ environment = new { local = localEnvironment . Environment , remote = remoteEnvironment ? . Environment ?? "" } ,
127+ culture = new { local = localEnvironment . Culture , remote = remoteEnvironment ? . Culture ?? "" } ,
128+ requestBody = new { local = localEntry . RequestBody ?? "" , remote = remoteEntry . RequestBody ?? "" } ,
129+ responseBody = new { local = localEntry . ResponseBody ?? "" , remote = remoteEntry . ResponseBody ?? "" } ,
110130
111131 diffs = diff
112132 } ) ;
113133 } ) . ExcludeFromDescription ( ) ;
114134
135+ webApp . MapGet ( "/debug/environment" , ( DebugEntryStore store ) =>
136+ {
137+ return Results . Ok ( store . Environment ) ;
138+ } ) . ExcludeFromDescription ( ) ;
139+
115140 webApp . MapGet ( "/debug/json/{id}" , ( string id , DebugEntryStore store ) =>
116141 {
117142 var item = store . Get ( id ) ;
0 commit comments