Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NH-64716 Fix lambda extension setup and OboeAPI call #224

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ package: sdist check-sdist-local manylinux-wheels check-wheel-local
# with extension compatible with current environment
# (x86_64 OR aarch64)
target_dir := "./tmp-lambda"
aws-lambda: export AWS_LAMBDA_FUNCTION_NAME = set-for-build
aws-lambda: export LAMBDA_TASK_ROOT = set-for-build
aws-lambda: check-zip wrapper
@if [ -f ./dist/solarwinds_apm_lambda_${platform}.zip ]; then \
echo -e "Deleting old solarwinds_apm_lambda_${platform}.zip"; \
Expand All @@ -203,7 +205,7 @@ aws-lambda: check-zip wrapper
@echo -e "Removing non-lambda C-extension library files generated by pip install under target directory."
@rm -rf ${target_dir}/nodeps/solarwinds_apm/extension/*.so*
@echo -e "Building AWS Lambda version of C-extensions for all supported Python versions in target directory."
@set -e; for PYBIN in cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311; do /opt/python/$${PYBIN}/bin/python setup.py build_ext_lambda -b ${target_dir}/nodeps; done
@set -e; for PYBIN in cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311; do /opt/python/$${PYBIN}/bin/python setup.py build_ext -b ${target_dir}/nodeps; done
@echo -e "Copying AWS Lambda specific Oboe library liboboe-1.0-lambda-${platform}.so into target directory."
@cp solarwinds_apm/extension/liboboe-1.0-lambda-${platform}.so ${target_dir}/nodeps/solarwinds_apm/extension/liboboe.so
@echo -e "Moving no-deps dependencies, needed for full opentelemetry/instrumentation path"
Expand Down
17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def is_alpine_distro():
return False

def python_version_supported():
if sys.version_info[0] == 3 and sys.version_info[1] >= 6:
if sys.version_info[0] == 3 and sys.version_info[1] >= 7:
return True
return False

Expand Down Expand Up @@ -87,14 +87,14 @@ def run(self):
return

platform_m = platform.machine()
oboe_lib = f"liboboe-1.0-alpine-{platform_m}.so" if is_alpine_distro() else f"liboboe-1.0-{platform_m}.so"
link_oboe_lib(oboe_lib)
build_ext.run(self)
oboe_lib = f"liboboe-1.0-"
if os.environ.get("AWS_LAMBDA_FUNCTION_NAME") and os.environ.get("LAMBDA_TASK_ROOT"):
oboe_lib = f"{oboe_lib}lambda-"
if is_alpine_distro():
oboe_lib = f"{oboe_lib}alpine-"
oboe_lib = f"{oboe_lib}{platform_m}.so"

class CustomBuildExtLambda(build_ext):
def run(self):
platform_m = platform.machine()
link_oboe_lib(f"liboboe-1.0-lambda-{platform_m}.so")
link_oboe_lib(oboe_lib)
build_ext.run(self)


Expand Down Expand Up @@ -126,7 +126,6 @@ def run(self):
setup(
cmdclass={
'build_ext': CustomBuildExt,
'build_ext_lambda': CustomBuildExtLambda,
'build_py': CustomBuild,
},
ext_modules=ext_modules,
Expand Down
101 changes: 56 additions & 45 deletions solarwinds_apm/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,59 @@ def calculate_liboboe_decision(
xtraceoptions: Optional[XTraceOptions] = None,
) -> dict:
"""Calculates oboe trace decision based on parent span context and APM config."""
tracestring = None
if parent_span_context.is_valid and parent_span_context.is_remote:
tracestring = W3CTransformer.traceparent_from_context(
parent_span_context
)
sw_member_value = parent_span_context.trace_state.get(
INTL_SWO_TRACESTATE_KEY
)

tracing_mode = self.calculate_tracing_mode(
name,
kind,
attributes,
)

trigger_trace_mode = OboeTracingMode.get_oboe_trigger_trace_mode(
self.apm_config.get("trigger_trace")
)
# 'sample_rate' is legacy and not supported in NH Python, so give as unset
sample_rate = self._UNSET

options = None
trigger_trace_request = 0
signature = None
timestamp = None
if xtraceoptions:
options = xtraceoptions.options_header
trigger_trace_request = xtraceoptions.trigger_trace
signature = xtraceoptions.signature
timestamp = xtraceoptions.timestamp

logger.debug(
"Creating new oboe decision with "
"tracestring: %s, "
"sw_member_value: %s, "
"tracing_mode: %s, "
"sample_rate: %s, "
"trigger_trace_request: %s, "
"trigger_trace_mode: %s, "
"options: %s, "
"signature: %s, "
"timestamp: %s",
tracestring,
sw_member_value,
tracing_mode,
sample_rate,
trigger_trace_request,
trigger_trace_mode,
options,
signature,
timestamp,
)

if self.apm_config.is_lambda:
logger.debug("Sampling in lambda mode.")
(
Expand All @@ -154,51 +207,7 @@ def calculate_liboboe_decision(
status_msg,
auth_msg,
status,
) = self.oboe_settings_api.getTracingDecision()

else:
tracestring = None
if parent_span_context.is_valid and parent_span_context.is_remote:
tracestring = W3CTransformer.traceparent_from_context(
parent_span_context
)
sw_member_value = parent_span_context.trace_state.get(
INTL_SWO_TRACESTATE_KEY
)

tracing_mode = self.calculate_tracing_mode(
name,
kind,
attributes,
)

trigger_trace_mode = OboeTracingMode.get_oboe_trigger_trace_mode(
self.apm_config.get("trigger_trace")
)
# 'sample_rate' is legacy and not supported in NH Python, so give as unset
sample_rate = self._UNSET

options = None
trigger_trace_request = 0
signature = None
timestamp = None
if xtraceoptions:
options = xtraceoptions.options_header
trigger_trace_request = xtraceoptions.trigger_trace
signature = xtraceoptions.signature
timestamp = xtraceoptions.timestamp

logger.debug(
"Creating new oboe decision with "
"tracestring: %s, "
"sw_member_value: %s, "
"tracing_mode: %s, "
"sample_rate: %s, "
"trigger_trace_request: %s, "
"trigger_trace_mode: %s, "
"options: %s, "
"signature: %s, "
"timestamp: %s",
) = self.oboe_settings_api.getTracingDecision(
tracestring,
sw_member_value,
tracing_mode,
Expand All @@ -209,6 +218,8 @@ def calculate_liboboe_decision(
signature,
timestamp,
)

else:
(
do_metrics,
do_sample,
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/test_sampler/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def test_init(self, mocker):
def test_calculate_liboboe_decision_is_lambda(
self,
mocker,
parent_span_context_invalid,
mock_xtraceoptions_signed_tt,
):
mock_apm_config = mocker.Mock()
mock_get = mocker.Mock(
Expand Down Expand Up @@ -237,11 +239,11 @@ def test_calculate_liboboe_decision_is_lambda(
test_sampler = _SwSampler(mock_apm_config)

result = test_sampler.calculate_liboboe_decision(
'unused_parent_context',
'unused_name',
parent_span_context_invalid,
'foo',
None,
{'unused': 'attrs'},
'unused_xtraceoptions',
{'foo': 'bar'},
mock_xtraceoptions_signed_tt,
)
mock_get_tracing_decision.assert_called_once()
assert result == {
Expand Down
Loading