From 176fd615df1a8b3afa4016fe71ff90b39a1fc939 Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Fri, 17 Nov 2023 16:05:21 -0800 Subject: [PATCH 1/4] Test: c-lib 14 stg --- Makefile | 6 +----- solarwinds_apm/extension/VERSION | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 70f85646..72da9dd6 100644 --- a/Makefile +++ b/Makefile @@ -52,11 +52,7 @@ LIBOBOESERVERLESSX86 := "liboboe-1.0-lambda-x86_64.so" OBOEVERSION := $(shell cat ./solarwinds_apm/extension/VERSION) # specification of source of header and library files -ifdef STAGING_OBOE - OBOEREPO := "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/${OBOEVERSION}" -else - OBOEREPO := "https://agent-binaries.cloud.solarwinds.com/apm/c-lib/${OBOEVERSION}" -endif +OBOEREPO := "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/${OBOEVERSION}" verify-oboe-version: @echo -e "Downloading Oboe VERSION file from ${OBOEREPO}" diff --git a/solarwinds_apm/extension/VERSION b/solarwinds_apm/extension/VERSION index 02161ca8..4b964e96 100644 --- a/solarwinds_apm/extension/VERSION +++ b/solarwinds_apm/extension/VERSION @@ -1 +1 @@ -13.0.0 +14.0.0 From 0e5d43c3cd103883746e29c30cc8d5e635eb33dc Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Fri, 17 Nov 2023 16:56:10 -0800 Subject: [PATCH 2/4] build_ext does what build_ext_lambda did --- Makefile | 4 +++- setup.py | 17 ++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 72da9dd6..6d715550 100644 --- a/Makefile +++ b/Makefile @@ -182,6 +182,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"; \ @@ -199,7 +201,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" diff --git a/setup.py b/setup.py index 5d301c32..7748ec36 100644 --- a/setup.py +++ b/setup.py @@ -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 @@ -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) @@ -126,7 +126,6 @@ def run(self): setup( cmdclass={ 'build_ext': CustomBuildExt, - 'build_ext_lambda': CustomBuildExtLambda, 'build_py': CustomBuild, }, ext_modules=ext_modules, From 63ab5996526b2944b0d1848f9bb3937cb84ab0f9 Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Fri, 17 Nov 2023 17:04:29 -0800 Subject: [PATCH 3/4] getTracingDecision receives all args --- solarwinds_apm/sampler.py | 101 +++++++++++++----------- tests/unit/test_sampler/test_sampler.py | 10 ++- 2 files changed, 62 insertions(+), 49 deletions(-) diff --git a/solarwinds_apm/sampler.py b/solarwinds_apm/sampler.py index 0a29ba7a..f44c8500 100644 --- a/solarwinds_apm/sampler.py +++ b/solarwinds_apm/sampler.py @@ -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.") ( @@ -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, @@ -209,6 +218,8 @@ def calculate_liboboe_decision( signature, timestamp, ) + + else: ( do_metrics, do_sample, diff --git a/tests/unit/test_sampler/test_sampler.py b/tests/unit/test_sampler/test_sampler.py index 9ba0fa0c..1fdf2b53 100644 --- a/tests/unit/test_sampler/test_sampler.py +++ b/tests/unit/test_sampler/test_sampler.py @@ -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( @@ -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 == { From 332c5eb49d59e57f0c554ba7786c9cb7bfa3e052 Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Fri, 17 Nov 2023 17:13:06 -0800 Subject: [PATCH 4/4] Revert "Test: c-lib 14 stg" This reverts commit 176fd615df1a8b3afa4016fe71ff90b39a1fc939. --- Makefile | 6 +++++- solarwinds_apm/extension/VERSION | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6d715550..032dad87 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,11 @@ LIBOBOESERVERLESSX86 := "liboboe-1.0-lambda-x86_64.so" OBOEVERSION := $(shell cat ./solarwinds_apm/extension/VERSION) # specification of source of header and library files -OBOEREPO := "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/${OBOEVERSION}" +ifdef STAGING_OBOE + OBOEREPO := "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/${OBOEVERSION}" +else + OBOEREPO := "https://agent-binaries.cloud.solarwinds.com/apm/c-lib/${OBOEVERSION}" +endif verify-oboe-version: @echo -e "Downloading Oboe VERSION file from ${OBOEREPO}" diff --git a/solarwinds_apm/extension/VERSION b/solarwinds_apm/extension/VERSION index 4b964e96..02161ca8 100644 --- a/solarwinds_apm/extension/VERSION +++ b/solarwinds_apm/extension/VERSION @@ -1 +1 @@ -14.0.0 +13.0.0