opentelemetry-lambda
opentelemetry-lambda copied to clipboard
[Python] Tests that init OTel with otel-instrument script should not use TestBase setup method.
Description
As is common with all instrumentations upstream, AWS Lambda instrumentation testing involves using TestBase
. TestBase
has a default implementation of super().setUpClass()
which initializes OTel Python with a TracerProvider.
This is a problem because we want the tests to test the otel-instrument
command which ALSO sets the TracerProvider
. But setting the TracerProvider
a 2nd time is not allowed so the effects of otel-instrument
are ignored. What's more, otel-instrument
runs as a subshell as of #164 so we'll have to be more clever as to how we propagate its changes to the parent process while also making sure we do NOT prematurely init OTel's TracerProvider
with the TestBase
default methods.
One solution is to call the upstream opentelemetry-instrumentation
auto initialization script ourselves in the test.
I guess the actual test business logic would best be in the subprocess (currently we just print os.environ but that could be any logic, like a test file including and calling the lambda handler) - having a runner that spawns the function in a subprocess nicely models the lambda execution itself better. Test failure reporting may not be as nice because of the subprocess but these are more like integration tests anyways.