Skip to content

Commit 713c03d

Browse files
authored
fix(tracing): calculate traceid in python not clickhouse to avoid nullable checks (#52061)
1 parent 4734193 commit 713c03d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

products/tracing/backend/logic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,12 @@ def where(self) -> ast.Expr:
176176
)
177177

178178
if self.query.traceId:
179+
trace_id_b64 = base64.b64encode(bytes.fromhex(self.query.traceId)).decode("ascii")
179180
exprs.append(
180181
parse_expr(
181-
"trace_id = assumeNotNull(base64Encode(unhex({traceId})))",
182+
"trace_id = {traceId}",
182183
placeholders={
183-
"traceId": ast.Constant(value=self.query.traceId),
184+
"traceId": ast.Constant(value=trace_id_b64),
184185
},
185186
)
186187
)

products/tracing/backend/presentation/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def query(self, request: Request, *args, **kwargs) -> Response:
8484
def trace(self, request: Request, trace_id: str, *args, **kwargs) -> Response:
8585
query_data = request.data or {}
8686
date_range = self.get_model(query_data.get("dateRange", {"date_from": "-24h"}), DateRange)
87+
try:
88+
# verify the trace_id is valid
89+
base64.b64encode(bytes.fromhex(trace_id)).decode("ascii")
90+
except ValueError:
91+
return Response(status=status.HTTP_400_BAD_REQUEST)
8792

8893
spans_query = TraceSpansQuery(
8994
dateRange=date_range,

0 commit comments

Comments
 (0)