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

OpenTelemetry code compiled with Nuitka has runtime error #3153

Closed
sorinansys opened this issue Feb 1, 2023 · 2 comments
Closed

OpenTelemetry code compiled with Nuitka has runtime error #3153

sorinansys opened this issue Feb 1, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@sorinansys
Copy link

Describe your environment
Operating system: Windows 11
Python version :3.10
Python dependencies : Nuitka 1.4.1 (https://pypi.org/project/Nuitka/1.4.1)
OpenTelemetry modules:

  • opentelemetry-distro 0.36b0
  • opentelemetry-exporter-otlp-proto-grpc 1.15.0

Checked if version has been fixed in main : Yes, but issue is not fixed

Steps to reproduce

  1. use default setup for loki and grafana
  2. create a Python virtual environment in Python 3.10
  3. install dependencies above (opentelemetry-distro, opentelemetry-exporter-otlp-proto-grpc and nuitka
  4. use Nuitka to compile test_case.py file (code just creates a log , attach an OTEL Logging handler and invokes log.info once)
  5. execute "python test_case.py"
  6. execute "test_case.exe"

Describe exactly how to reproduce the error. Include a code sample if applicable.

Content of test_case.py:

import opentelemetry.sdk.resources
import opentelemetry.sdk._logs
import opentelemetry.exporter.otlp.proto.grpc._log_exporter
import logging
import sys

otel_resource=opentelemetry.sdk.resources.Resource.create({"service.name": "Testing.Nuitka.LexicalAmbiguity"})
otel_logger_provider = opentelemetry.sdk._logs.LoggerProvider(resource=otel_resource)
otel_exporter = opentelemetry.exporter.otlp.proto.grpc._log_exporter.OTLPLogExporter(insecure=True)
otel_logger_provider.add_log_record_processor(opentelemetry.sdk._logs.export.BatchLogRecordProcessor(otel_exporter))
otel_logging_handler = opentelemetry.sdk._logs.LoggingHandler(level=logging.INFO, logger_provider=otel_logger_provider)
log=logging.getLogger("TestingLog")
log.setLevel(logging.INFO)
log.addHandler(otel_logging_handler)
print(f"Logging foo from {sys.argv[0]} ")
log.info(f"Logging foo from {sys.argv[0]} ")
logging.shutdown()
  1. execute:
python -m venv dev_venv
dev_venv\Scripts\activate
  1. execute:
python -m pip install opentelemetry-distro==0.36b0
python -m pip install opentelemetry-exporter-otlp-proto-grpc==1.15.0
python -m pip install nuitka==1.4.1
  1. execute:
    python -m nuitka test_case.py --standalone --onefile
  2. execute:
    python test_case.py
  3. execute
    test_case.exe

What is the expected behavior?
the outcome of "python test_case.py" and test_case.exe should be similar

  1. python test_case,py
    STDOUT:
    Logging foo from test_case.py
    loki :
    Logging foo from test_case.py
  2. test_case.exe
    STDOUT:
    Logging foo from test_case.exe
    loki :
    Logging foo from test_case.exe

What is the actual behavior?
This is the actual outcome :

  1. python test_case,py
    STDOUT:
    Logging foo from test_case.py
    loki :
    Logging foo from test_case.py
  2. test_case.exe
    STDOUT:
    Logging foo from test_case.exe Failed to load context: contextvars_context Traceback (most recent call last): File "C:\Users\smuntean\AppData\Local\Temp\ONE57C~1\test_case.py", line 18, in <module> log.info(f"Logging foo from {sys.argv[0]} ") File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\logging\__init__.py", line 1477, in info File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\logging\__init__.py", line 1624, in _log File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\logging\__init__.py", line 1634, in handle File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\logging\__init__.py", line 1696, in callHandlers File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\logging\__init__.py", line 968, in handle File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\opentelemetry\sdk\_logs\_internal\__init__.py", line 382, in emit File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\opentelemetry\sdk\_logs\_internal\__init__.py", line 361, in _translate File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\opentelemetry\trace\propagation\__init__.py", line 48, in get_current_span File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\opentelemetry\context\__init__.py", line 96, in get_value File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\opentelemetry\context\__init__.py", line 67, in wrapper File "C:\Users\xxxxxxxxx\AppData\Local\Temp\ONE57C~1\opentelemetry\context\__init__.py", line 131, in get_current AttributeError: 'NoneType' object has no attribute 'get_current'
    loki :
    Nothing
@sorinansys sorinansys added the bug Something isn't working label Feb 1, 2023
@sorinansys
Copy link
Author

I've run several tests with a newer Nuitka (version 1.5.3) and the compilation of next(iter) (the cause of this issue) Python code seems to generate C++ code with equivalent functionality.

A workaround to resolve this issue would be to upgrade Nuitka to a newer version (1.5.3 seems to fine, although older versions newer than 1.4.1 might also resolve the issue)

For more information see the comments in #3154

@srikanthccv
Copy link
Member

Please see #3154 (comment)

@srikanthccv srikanthccv closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants