Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

pytest-otel seems to be broken on Python >= 3.10.0 #1687

Closed
belimawr opened this issue May 11, 2022 · 5 comments
Closed

pytest-otel seems to be broken on Python >= 3.10.0 #1687

belimawr opened this issue May 11, 2022 · 5 comments
Assignees
Labels
bug Something isn't working Team:Automation Label for the Observability productivity team

Comments

@belimawr
Copy link

OS: Linux (Arch Linux)
Python: 3.10.4

Since Python 3.10.0, whenever I run the Python tests on Beats, more specifically Filebeat, I get this error (all tests fail):

Traceback (most recent call last):
  File "/home/vagrant/beats/build/ve/linux/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/_pytest/config/__init__.py", line 185, in console_main
    code = main()
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/_pytest/config/__init__.py", line 162, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/_pytest/main.py", line 304, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/_pytest/terminal.py", line 803, in pytest_sessionfinish
    outcome.get_result()
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pytest_otel/__init__.py", line 266, in pytest_sessionfinish
    end_span(session_name, exitCodeToOutcome(exitstatus))
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/pytest_otel/__init__.py", line 163, in end_span
    spans[span_name].end()
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/opentelemetry/sdk/trace/__init__.py", line 853, in end
    self._span_processor.on_end(self._readable_span())
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/opentelemetry/sdk/trace/__init__.py", line 158, in on_end
    sp.on_end(span)
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/opentelemetry/sdk/trace/export/__init__.py", line 90, in on_end
    token = attach(set_value(_SUPPRESS_INSTRUMENTATION_KEY, True))
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/opentelemetry/context/__init__.py", line 116, in set_value
    context = get_current()
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/opentelemetry/context/__init__.py", line 67, in wrapper
    return func(*args, **kwargs)  # type: ignore[misc]
  File "/home/vagrant/beats/build/ve/linux/lib/python3.10/site-packages/opentelemetry/context/__init__.py", line 131, in get_current
    return _RUNTIME_CONTEXT.get_current()  # type:ignore
AttributeError: 'NoneType' object has no attribute 'get_current'

Removing pytest-otel solves the problem in the sense the tests can run, but I am not sure about what happens with the instrumentation.

So far I've tested it with Python (using pyenv):

  • 3.8.13
  • 3.9.12
  • 3.10.0
  • 3.10.4

Unfortunately I have not had time to create a small example to reproduce it.

@kuisathaverat
Copy link
Contributor

It seems related to OpenTelemetry open-telemetry/opentelemetry-python#2288 I will update the OpenTelemetry SDK and test if it is resolved.

@kuisathaverat kuisathaverat self-assigned this May 11, 2022
@kuisathaverat kuisathaverat added bug Something isn't working Team:Automation Label for the Observability productivity team labels May 11, 2022
@kuisathaverat
Copy link
Contributor

you are testing it locally, isn't it? because I do not see errors on any of the CIs we have, IIRC we do not have any with Python 3.10 yet

@belimawr
Copy link
Author

belimawr commented May 11, 2022

Yes, it's not affecting CI, just my local environment.

@kuisathaverat
Copy link
Contributor

it is already fixed but not released #1664

@kuisathaverat
Copy link
Contributor

the release 1.1.0 contains the fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working Team:Automation Label for the Observability productivity team
Projects
None yet
Development

No branches or pull requests

2 participants