Skip to content

Commit efce8eb

Browse files
committed
fix the authorizer span's start time
1 parent 63d1777 commit efce8eb

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

datadog_lambda/tracing.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def is_api_gateway_invocation_async(event):
643643

644644

645645
def insert_upstream_authorizer_span(
646-
kwargs_to_start_span, other_tags_for_span, start_time_s, finish_time_s=None
646+
kwargs_to_start_span, other_tags_for_span, start_time_ns, finish_time_s=None
647647
):
648648
"""Insert the authorizer span.
649649
Without this: parent span --child-> inferred span
@@ -652,7 +652,7 @@ def insert_upstream_authorizer_span(
652652
Args:
653653
kwargs_to_start_span (Dict): the same keyword arguments used for the inferred span
654654
other_tags_for_span (Dict): the same tag keyword arguments used for the inferred span
655-
start_time_s (int): the start time of the span in seconds
655+
start_time_ns (int): the start time of the span in nanoseconds
656656
finish_time_s (int): the finish time of the sapn in seconds
657657
"""
658658

@@ -663,7 +663,7 @@ def insert_upstream_authorizer_span(
663663
upstream_authorizer_span.set_tag("operation_name", "aws.apigateway.authorizer")
664664
# always sync for the authorizer invocation
665665
InferredSpanInfo.set_tags_to_span(upstream_authorizer_span, synchronicity="sync")
666-
upstream_authorizer_span.start = start_time_s
666+
upstream_authorizer_span.start_ns = start_time_ns
667667
upstream_authorizer_span.finish(finish_time=finish_time_s)
668668
return upstream_authorizer_span
669669

@@ -704,9 +704,8 @@ def create_inferred_span_from_api_gateway_websocket_event(event, context):
704704
)
705705
if injected_authorizer_data:
706706
try:
707-
start_time_s = (
708-
int(injected_authorizer_data.get(Headers.Parent_Span_Finish_Time))
709-
/ 1000
707+
start_time_ns = int(
708+
injected_authorizer_data.get(Headers.Parent_Span_Finish_Time)
710709
)
711710
finish_time_s = (
712711
request_time_epoch_s
@@ -720,7 +719,7 @@ def create_inferred_span_from_api_gateway_websocket_event(event, context):
720719
/ 1000
721720
)
722721
upstream_authorizer_span = insert_upstream_authorizer_span(
723-
args, tags, start_time_s, finish_time_s
722+
args, tags, start_time_ns, finish_time_s
724723
)
725724
# trace context needs to be set again as it is reset by upstream_authorizer_span.finish
726725
tracer.context_provider.activate(trace_ctx)
@@ -781,9 +780,8 @@ def create_inferred_span_from_api_gateway_event(event, context):
781780
)
782781
if injected_authorizer_data:
783782
try:
784-
start_time_s = (
785-
int(injected_authorizer_data.get(Headers.Parent_Span_Finish_Time))
786-
/ 1000
783+
start_time_ns = int(
784+
injected_authorizer_data.get(Headers.Parent_Span_Finish_Time)
787785
)
788786
finish_time_s = (
789787
request_time_epoch_s
@@ -797,7 +795,7 @@ def create_inferred_span_from_api_gateway_event(event, context):
797795
/ 1000
798796
)
799797
upstream_authorizer_span = insert_upstream_authorizer_span(
800-
args, tags, start_time_s, finish_time_s
798+
args, tags, start_time_ns, finish_time_s
801799
)
802800
# trace context needs to be set again as it is reset by upstream_authorizer_span.finish
803801
tracer.context_provider.activate(trace_ctx)
@@ -861,13 +859,14 @@ def create_inferred_span_from_http_api_event(event, context):
861859
)
862860
if injected_authorizer_data:
863861
try:
864-
start_time_s = (
865-
int(injected_authorizer_data.get(Headers.Parent_Span_Finish_Time))
866-
/ 1000
862+
start_time_ns = int(
863+
injected_authorizer_data.get(Headers.Parent_Span_Finish_Time)
867864
)
868-
finish_time_s = start_time_s # no integrationLatency info in this case
865+
finish_time_s = (
866+
start_time_ns / 1000
867+
) # no integrationLatency info in this case
869868
upstream_authorizer_span = insert_upstream_authorizer_span(
870-
args, tags, start_time_s, finish_time_s
869+
args, tags, start_time_ns, finish_time_s
871870
)
872871
# trace context needs to be set again as it is reset by upstream_authorizer_span.finish
873872
tracer.context_provider.activate(trace_ctx)

datadog_lambda/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _inject_authorizer_span_headers(self, request_id, finish_time_ns):
174174
HTTPPropagator.inject(source_span.context, injected_headers)
175175
# remove unused header
176176
injected_headers.pop(Headers.TAGS_HEADER_TO_DELETE, None)
177-
injected_headers[Headers.Parent_Span_Finish_Time] = finish_time_ns / 1e6
177+
injected_headers[Headers.Parent_Span_Finish_Time] = finish_time_ns
178178
if request_id is not None:
179179
injected_headers[Headers.Authorizing_Request_Id] = request_id
180180
datadog_data = base64.b64encode(json.dumps(injected_headers).encode())

0 commit comments

Comments
 (0)