Coffee journaling on ATProto (alpha) alpha.arabica.social
coffee
17
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: improved multi-request otel tracing

authored by

Patrick Dewey and committed by tangled.org 3ed1099c 75e29b74

+38
+26
internal/web/bff/tracing.go
··· 1 + package bff 2 + 3 + import ( 4 + "context" 5 + "fmt" 6 + 7 + "go.opentelemetry.io/otel/trace" 8 + ) 9 + 10 + // Traceparent returns the W3C traceparent header value for the current span, 11 + // or an empty string if no active trace exists. This is intended to be called 12 + // from templ templates so that client-side requests (HTMX) can propagate the 13 + // trace context back to the server. 14 + func Traceparent(ctx context.Context) string { 15 + sc := trace.SpanFromContext(ctx).SpanContext() 16 + if !sc.HasTraceID() || !sc.HasSpanID() { 17 + return "" 18 + } 19 + 20 + flags := "00" 21 + if sc.IsSampled() { 22 + flags = "01" 23 + } 24 + 25 + return fmt.Sprintf("00-%s-%s-%s", sc.TraceID(), sc.SpanID(), flags) 26 + }
+12
internal/web/components/layout.templ
··· 219 219 // Increase history cache size to prevent cache misses 220 220 htmx.config.historyCacheSize = 20; 221 221 222 + // Propagate W3C traceparent to HTMX requests so sub-requests 223 + // (e.g. /api/feed, /api/popular-recipes) share the page's trace 224 + var tp = document.querySelector('meta[name="traceparent"]'); 225 + if (tp) { 226 + document.body.addEventListener('htmx:configRequest', function(evt) { 227 + evt.detail.headers['traceparent'] = tp.content; 228 + }); 229 + } 230 + 222 231 // Show session-expired modal on 401 responses 223 232 document.body.addEventListener('htmx:afterRequest', function(evt) { 224 233 if (evt.detail.xhr && evt.detail.xhr.status === 401) { ··· 263 272 <script src="/static/js/data-cache.js?v=0.3.0"></script> 264 273 <script src="/static/js/sw-register.js?v=0.2.0"></script> 265 274 </head> 275 + if tp := bff.Traceparent(ctx); tp != "" { 276 + <meta name="traceparent" content={ tp }/> 277 + } 266 278 <body 267 279 class="min-h-full flex flex-col" 268 280 style="background-color: var(--page-bg); color: var(--page-text);"