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), ( {