Skip to content

Commit

Permalink
sdf
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jul 19, 2024
1 parent 423dcc8 commit 77876f4
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ def _instrument(
def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
call_wrapped, instance, args, kwargs
):
# This function gets another one in the call_wrapped argument. It then
# instantiates a span and calls the call_wrapped function.

orig_handler_name = ".".join(
[wrapped_module_name, wrapped_function_name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@


def handler(event, context):
# The purpose of this function is to be used as the call_wrapped function
# of _instrumented_lambda_handler_call.
return "200 ok"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def __init__(self, aws_request_id, invoked_function_arn):
)

MOCK_XRAY_TRACE_ID = 0x5FB7331105E8BB83207FA31D4D9CDB4C
# hex(127227885676276211700222971224212167500)

MOCK_XRAY_TRACE_ID_STR = f"{MOCK_XRAY_TRACE_ID:x}"
MOCK_XRAY_PARENT_SPAN_ID = 0x3328B8445A6DBAD2
Expand All @@ -71,7 +70,6 @@ def __init__(self, aws_request_id, invoked_function_arn):
# https://www.w3.org/TR/trace-context/#examples-of-http-traceparent-headers

MOCK_W3C_TRACE_ID = 0x5CE0E9A56015FEC5AADFA328AE398115
# hex(123456789012345678901234567890123456789)
MOCK_W3C_PARENT_SPAN_ID = 0xAB54A98CEB1F0AD2
MOCK_W3C_TRACE_CONTEXT_SAMPLED = (
f"00-{MOCK_W3C_TRACE_ID:x}-{MOCK_W3C_PARENT_SPAN_ID:x}-01"
Expand Down Expand Up @@ -135,13 +133,8 @@ def test_active_tracing(self):
test_env_patch.start()
reload(propagate)

# This calls AwsLambdaInstrumentor._instrument which finds a function
# from os.environ[_HANDLER] and wraps it with
# _instrumented_lambda_handler_call.
AwsLambdaInstrumentor().instrument()

# This finds the _instrumented_lambda_hanlder_call uising
# os.environ[_HANDLER] and calls it.
mock_execute_lambda()

spans = self.memory_exporter.get_finished_spans()
Expand Down Expand Up @@ -224,9 +217,7 @@ def custom_event_context_extractor(lambda_event):
expected_state_value=MOCK_W3C_TRACE_STATE_VALUE,
xray_traceid=MOCK_XRAY_TRACE_CONTEXT_NOT_SAMPLED,
),
TestCase( # 2
# run this sub test case in main, see what if AwsXrayPropagator.extract
# gets called
TestCase(
name="custom_extractor_sampled_xray",
custom_extractor=custom_event_context_extractor,
context={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ typing_extensions==4.10.0
urllib3==2.2.2
wrapt==1.16.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-aws-lambda
-e propagator/opentelemetry-propagator-aws-xray
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
from requests.structures import CaseInsensitiveDict

from opentelemetry.context import get_current
from opentelemetry.instrumentation.aws_lambda import _X_AMZN_TRACE_ID
from opentelemetry.propagators.aws.aws_xray_propagator import (
TRACE_HEADER_KEY,
AwsXRayLambdaPropagator,
AwsXRayPropagator,
)
from opentelemetry.propagators.textmap import DefaultGetter
from opentelemetry.sdk.trace import ReadableSpan
Expand Down Expand Up @@ -164,45 +162,3 @@ def test_add_link_from_environment_variable(self):
self.assertEqual(
span_link_context.trace_state, TraceState.get_default()
)

@patch.dict(
environ,
{
_X_AMZN_TRACE_ID: (
"Root=1-12345678-123456789012345678901234;"
"Parent=1234567890123456;"
"Sampled=1"
),
},
)
def test_equivalent_extraction(self):

def check_context(context) -> str:

context_keys = list(context.keys())

self.assertEqual(len(context_keys), 1)

context_key = context_keys[0]

span_context = context[context_key].get_span_context()

self.assertEqual(
hex(span_context.trace_id),
"0x12345678123456789012345678901234",
)

self.assertEqual(hex(span_context.span_id), "0x1234567890123456")

self.assertEqual(hex(span_context.trace_flags), "0x1")

return context_key

self.assertEqual(
check_context(
AwsXRayPropagator().extract(
{TRACE_HEADER_KEY: environ.get(_X_AMZN_TRACE_ID)}
)
),
check_context(AwsXRayLambdaPropagator().extract({})),
)

0 comments on commit 77876f4

Please sign in to comment.