Skip to content

Commit

Permalink
Merge pull request #405 from solarwinds/NH-88067-setdefault-disable-a…
Browse files Browse the repository at this point in the history
…ws-lambda-inst

NH-88067 setdefault for disabling aws-lambda if outside lambda
  • Loading branch information
tammy-baylis-swi authored Aug 6, 2024
2 parents 84b8c06 + 33e971d commit 562e7fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions solarwinds_apm/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
OTEL_TRACES_EXPORTER,
)
from opentelemetry.instrumentation.distro import BaseDistro
from opentelemetry.instrumentation.environment_variables import (
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS,
)
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.logging.environment_variables import (
OTEL_PYTHON_LOG_FORMAT,
Expand Down Expand Up @@ -139,6 +142,17 @@ def _configure(self, **kwargs):
# Always opt into new semconv for all instrumentors (if supported)
environ["OTEL_SEMCONV_STABILITY_OPT_IN"] = self.get_semconv_opt_in()

# TODO: Bootstrapping and auto-instrumentation ideally
# should not load instrumentor nor instrument AWS Lambda if not in lambda
if not SolarWindsApmConfig.calculate_is_lambda():
# If user has set OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
# then they will need to add "aws-lambda" to the list
# else instrumentor Version Lookups for attributes may fail
environ.setdefault(
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS,
"aws-lambda",
)

def load_instrumentor(self, entry_point: EntryPoint, **kwargs):
"""Takes a collection of instrumentation entry points
and activates them by instantiating and calling instrument()
Expand Down
2 changes: 1 addition & 1 deletion solarwinds_apm/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.2.0.1"
__version__ = "2.2.0.3"
12 changes: 12 additions & 0 deletions tests/unit/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
OTEL_PROPAGATORS,
OTEL_TRACES_EXPORTER
)
from opentelemetry.instrumentation.environment_variables import (
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS,
)
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
OTEL_EXPORTER_OTLP_LOGS_HEADERS,
Expand Down Expand Up @@ -297,6 +300,15 @@ def test_configure_env_propagators(self, mocker):
assert os.environ[OTEL_TRACES_EXPORTER] == "solarwinds_exporter"
assert os.environ.get("OTEL_SEMCONV_STABILITY_OPT_IN") == "http"

def test_configure_env_disabled_instrumentations_default(self):
distro.SolarWindsDistro()._configure()
assert os.environ[OTEL_PYTHON_DISABLED_INSTRUMENTATIONS] == "aws-lambda"

def test_configure_env_disabled_instrumentations_user_set(self, mocker):
mocker.patch.dict(os.environ, {"OTEL_PYTHON_DISABLED_INSTRUMENTATIONS": "foo-bar,only"})
distro.SolarWindsDistro()._configure()
assert os.environ[OTEL_PYTHON_DISABLED_INSTRUMENTATIONS] == "foo-bar,only"

def test_load_instrumentor_no_commenting(self, mocker):
mock_instrument = mocker.Mock()
mock_instrumentor = mocker.Mock()
Expand Down

0 comments on commit 562e7fd

Please sign in to comment.