Skip to content

Commit 70c48d4

Browse files
committed
fix: also extract trace context from session variables for scan operation
1 parent a61374d commit 70c48d4

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

fdw.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,21 @@ func goFdwBeginForeignScan(node *C.ForeignScanState, eflags C.int) {
321321
plan := (*C.ForeignScan)(unsafe.Pointer(node.ss.ps.plan))
322322
var execState *C.FdwExecState = C.initializeExecState(unsafe.Pointer(plan.fdw_private))
323323

324+
// Extract trace context from session variables for scan operation
325+
var traceContext string
326+
if traceContextPtr := C.getTraceContextFromSession(); traceContextPtr != nil {
327+
traceContext = C.GoString(traceContextPtr)
328+
log.Printf("[TRACE] Extracted trace context from session for scan: %s", traceContext)
329+
} else {
330+
log.Printf("[DEBUG] No trace context found in session variables for scan")
331+
}
332+
333+
// Add trace context to options for hub layer
334+
if traceContext != "" {
335+
opts["trace_context"] = traceContext
336+
log.Printf("[DEBUG] Added trace context to scan options")
337+
}
338+
324339
log.Printf("[INFO] goFdwBeginForeignScan, canPushdownAllSortFields %v", execState.canPushdownAllSortFields)
325340
var columns []string
326341
if execState.target_list != nil {

fdw/fdw.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ static char *extractTraceContextFromSession(void)
120120
return result;
121121
}
122122

123+
/*
124+
* Public wrapper for extractTraceContextFromSession - callable from Go
125+
*/
126+
char *getTraceContextFromSession(void)
127+
{
128+
return extractTraceContextFromSession();
129+
}
130+
123131
static void fdwGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
124132
{
125133
FdwPlanState *planstate;

fdw/fdw_helpers.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,7 @@ static inline char *nameStr(Name n) { return NameStr(*n); }
105105

106106

107107
// logging
108-
char *tagTypeToString(NodeTag type);
108+
char *tagTypeToString(NodeTag type);
109+
110+
// trace context
111+
char *getTraceContextFromSession(void);

0 commit comments

Comments
 (0)