Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jul 18, 2024
1 parent 6eb6bd1 commit 5cfe891
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def custom_event_context_extractor(lambda_event):
from opentelemetry.trace.status import Status, StatusCode
from opentelemetry.propagate import extract

set_trace

logger = logging.getLogger(__name__)

_HANDLER = "_HANDLER"
Expand Down Expand Up @@ -128,7 +130,6 @@ def _default_event_context_extractor(lambda_event: Any) -> Context:
Returns:
A Context with configuration found in the event.
"""
set_trace()
headers = None
try:
headers = lambda_event["headers"]
Expand Down Expand Up @@ -164,10 +165,14 @@ def _determine_parent_context(
Returns:
A Context with configuration found in the carrier.
"""
set_trace()
parent_context = None
extract

# By Tyler: ensure the event context extractor is not invoked if there is an
# already active span context.

# Related PR: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2573

if (
parent_context
and get_current_span(parent_context)
Expand Down Expand Up @@ -283,13 +288,16 @@ def _instrument(
meter_provider: MeterProvider = None,
):


# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
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.

set_trace()

orig_handler_name = ".".join(
[wrapped_module_name, wrapped_function_name]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.


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 @@ -42,6 +42,7 @@
MOCK_LAMBDA_API_GATEWAY_HTTP_API_EVENT,
)
from .mocks.api_gateway_proxy_event import MOCK_LAMBDA_API_GATEWAY_PROXY_EVENT
from ipdb import set_trace


class MockLambdaContext:
Expand Down Expand Up @@ -128,8 +129,15 @@ def test_active_tracing(self):
)
test_env_patch.start()

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

set_trace()

# 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

0 comments on commit 5cfe891

Please sign in to comment.