From f43456f430adce1183842e626a421e3b5567cb29 Mon Sep 17 00:00:00 2001 From: Shubham Padkonde Date: Thu, 24 Sep 2026 08:45:25 +0000 Subject: [PATCH] fix: accept X-Cloud-Trace-Context headers without the options suffix The ";o=OPTIONS" part of the X-Cloud-Trace-Context header is optional, but the trace context regex required it, so a header such as "TRACE_ID/SPAN_ID" was treated as malformed and the span ID was not added to the execution ID log entries. --- src/functions_framework/execution_id.py | 3 ++- tests/test_execution_id.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/functions_framework/execution_id.py b/src/functions_framework/execution_id.py index df412187..f8451b68 100644 --- a/src/functions_framework/execution_id.py +++ b/src/functions_framework/execution_id.py @@ -32,8 +32,9 @@ _EXECUTION_ID_CHARSET = string.digits + string.ascii_letters _LOGGING_API_LABELS_FIELD = "logging.googleapis.com/labels" _LOGGING_API_SPAN_ID_FIELD = "logging.googleapis.com/spanId" +# The ";o=OPTIONS" suffix of the trace context header is optional. _TRACE_CONTEXT_REGEX_PATTERN = re.compile( - r"^(?P[\w\d]+)/(?P\d+);o=(?P[01])$" + r"^(?P[\w\d]+)/(?P\d+)(?:;o=(?P[01]))?$" ) EXECUTION_ID_REQUEST_HEADER = "Function-Execution-Id" TRACE_CONTEXT_REQUEST_HEADER = "X-Cloud-Trace-Context" diff --git a/tests/test_execution_id.py b/tests/test_execution_id.py index b8c5b9f0..5c2b6405 100644 --- a/tests/test_execution_id.py +++ b/tests/test_execution_id.py @@ -201,6 +201,14 @@ def test_generate_execution_id(): TEST_EXECUTION_ID, TEST_SPAN_ID, ), + ( + { + "X-Cloud-Trace-Context": f"TRACE_ID/{TEST_SPAN_ID}", + "Function-Execution-Id": TEST_EXECUTION_ID, + }, + TEST_EXECUTION_ID, + TEST_SPAN_ID, + ), ({}, None, None), ( {