opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

Import error - ImportError: cannot import name 'std_to_otel' from 'opentelemetry._logs'

Open digjanaik27193 opened this issue 4 months ago • 6 comments

Describe your environment

OS: Linux Python version: python3.12 SDK version: 1.25.0 API version: 1.25.0

What happened?

I have OTEL layer auto instrumented lambda in AWS region us-west-2 which uses OTEL layer - arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python-amd64-ver-1-29-0:2

The traces were correctly being sent to OTEL collector -> dynatrace until 21st July, but we noticed no tracing after that. I checked the logs for CloudWatch and started seeing this error as attached in - log-events-viewer-result.8.csv

log-events-viewer-result (8).csv

We tried updating the lambda layer to the latest version [arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python-amd64-ver-1-32-0:2] but still see same issue

Steps to Reproduce

Auto instrumented Lambda python function.

Expected Result

Should be able to see traces in Dynatrace.

Actual Result

No tracing.

Additional context

No response

Would you like to implement a fix?

None

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

digjanaik27193 avatar Aug 11 '25 09:08 digjanaik27193

This looks like some third party code requiring a private symbol that has been moved. Please post the full stacktrace.

xrmx avatar Aug 11 '25 15:08 xrmx

@xrmx Thanks for checking the issue, here's the stacktrace -


2025-08-11T15:04:17.301Z | Failed to auto initialize OpenTelemetry
-- | --
  | 2025-08-11T15:04:17.301Z | Traceback (most recent call last):
  | 2025-08-11T15:04:17.301Z | File "/opt/python/opentelemetry/instrumentation/auto_instrumentation/__init__.py", line 130, in initialize
  | 2025-08-11T15:04:17.301Z | distro = _load_distro()
  | 2025-08-11T15:04:17.301Z | ^^^^^^^^^^^^^^
  | 2025-08-11T15:04:17.301Z | File "/opt/python/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 52, in _load_distro
  | 2025-08-11T15:04:17.301Z | raise exc
  | 2025-08-11T15:04:17.301Z | File "/opt/python/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 37, in _load_distro
  | 2025-08-11T15:04:17.301Z | distro = entry_point.load()()
  | 2025-08-11T15:04:17.301Z | ^^^^^^^^^^^^^^^^^^
  | 2025-08-11T15:04:17.301Z | File "/var/task/importlib_metadata/__init__.py", line 221, in load
  | 2025-08-11T15:04:17.301Z | module = import_module(self.module)
  | 2025-08-11T15:04:17.301Z | ^^^^^^^^^^^^^^^^^^^^^^^^^^
  | 2025-08-11T15:04:17.301Z | File "/var/lang/lib/python3.12/importlib/__init__.py", line 90, in import_module
  | 2025-08-11T15:04:17.301Z | return _bootstrap._gcd_import(name[level:], package, level)
  | 2025-08-11T15:04:17.301Z | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | 2025-08-11T15:04:17.301Z | File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  | 2025-08-11T15:04:17.301Z | File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  | 2025-08-11T15:04:17.301Z | File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  | 2025-08-11T15:04:17.301Z | File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  | 2025-08-11T15:04:17.301Z | File "<frozen importlib._bootstrap_external>", line 999, in exec_module
  | 2025-08-11T15:04:17.301Z | File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  | 2025-08-11T15:04:17.301Z | File "/opt/python/opentelemetry/distro/__init__.py", line 23, in <module>
  | 2025-08-11T15:04:17.301Z | from opentelemetry.sdk._configuration import _OTelSDKConfigurator
  | 2025-08-11T15:04:17.301Z | File "/opt/python/opentelemetry/sdk/_configuration/__init__.py", line 39, in <module>
  | 2025-08-11T15:04:17.301Z | from opentelemetry.sdk._events import EventLoggerProvider
  | 2025-08-11T15:04:17.301Z | File "/opt/python/opentelemetry/sdk/_events/__init__.py", line 23, in <module>
  | 2025-08-11T15:04:17.301Z | from opentelemetry.sdk._logs import Logger, LoggerProvider, LogRecord
  | 2025-08-11T15:04:17.301Z | File "/opt/python/opentelemetry/sdk/_logs/__init__.py", line 16, in <module>
  | 2025-08-11T15:04:17.301Z | from opentelemetry.sdk._logs._internal import (
  | 2025-08-11T15:04:17.301Z | File "/opt/python/opentelemetry/sdk/_logs/_internal/__init__.py", line 32, in <module>
  | 2025-08-11T15:04:17.301Z | from opentelemetry._logs import (
  | 2025-08-11T15:04:17.301Z | ImportError: cannot import name 'std_to_otel' from 'opentelemetry._logs' (/var/task/opentelemetry/_logs/__init__.py)

digjanaik27193 avatar Aug 11 '25 15:08 digjanaik27193

@xrmx - What could've possibly changed inside the layer which is causing this issue, since we haven't updated the layer.

digjanaik27193 avatar Aug 12 '25 12:08 digjanaik27193

This breakage was part of this https://github.com/open-telemetry/opentelemetry-python/pull/4649

otel-lambda already bumped the dependencies: https://github.com/open-telemetry/opentelemetry-lambda/blob/main/python/src/otel/otel_sdk/requirements.txt to the latest ones Probably mix of dependencies issue?

emdneto avatar Aug 12 '25 14:08 emdneto

Thanks @emdneto. So, looks like this has already been fixed. If I point to latest otel layer - arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python-amd64-ver-1-32-0:2 I should not be seeing this issue but still not working for me. I also am using opentelemetry-api package which was earlier on lower version but now its pointing to the latest 1.36.0. My python version is 3.9, in process of upgrading it but it is supported.

Not able to understand what could be causing this issue still.

digjanaik27193 avatar Aug 12 '25 16:08 digjanaik27193

@emdneto @xrmx

It looks like dependencies are not updated inside the OTEL layer I am suspecting it is still having older version of the SDK - Do we know who's responsible for updating the later ?

arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python-amd64-ver-1-32-0:2


distro = entry_point.load()()
--
  | 2025-08-13T10:31:40.000Z | ~~~~~~~~~~~~~~~~^^
  | 2025-08-13T10:31:40.000Z | File "/var/task/importlib_metadata/__init__.py", line 221, in load
  | 2025-08-13T10:31:40.000Z | module = import_module(self.module)
  | 2025-08-13T10:31:40.000Z | File "/var/lang/lib/python3.13/importlib/__init__.py", line 88, in import_module
  | 2025-08-13T10:31:40.000Z | return _bootstrap._gcd_import(name[level:], package, level)
  | 2025-08-13T10:31:40.000Z | ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | 2025-08-13T10:31:40.000Z | File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  | 2025-08-13T10:31:40.000Z | File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  | 2025-08-13T10:31:40.000Z | File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  | 2025-08-13T10:31:40.000Z | File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  | 2025-08-13T10:31:40.000Z | File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  | 2025-08-13T10:31:40.000Z | File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  | 2025-08-13T10:31:40.000Z | File "/opt/python/opentelemetry/distro/__init__.py", line 23, in <module>
  | 2025-08-13T10:31:40.000Z | from opentelemetry.sdk._configuration import _OTelSDKConfigurator
  | 2025-08-13T10:31:40.000Z | File "/opt/python/opentelemetry/sdk/_configuration/__init__.py", line 39, in <module>
  | 2025-08-13T10:31:40.000Z | from opentelemetry.sdk._events import EventLoggerProvider
  | 2025-08-13T10:31:40.000Z | File "/opt/python/opentelemetry/sdk/_events/__init__.py", line 23, in <module>
  | 2025-08-13T10:31:40.000Z | from opentelemetry.sdk._logs import Logger, LoggerProvider, LogRecord
  | 2025-08-13T10:31:40.000Z | File "/opt/python/opentelemetry/sdk/_logs/__init__.py", line 16, in <module>
  | 2025-08-13T10:31:40.000Z | from opentelemetry.sdk._logs._internal import (
  | 2025-08-13T10:31:40.000Z | ...<8 lines>...
  | 2025-08-13T10:31:40.000Z | )
  | 2025-08-13T10:31:40.000Z | File "/opt/python/opentelemetry/sdk/_logs/_internal/__init__.py", line 32, in <module>
  | 2025-08-13T10:31:40.000Z | from opentelemetry._logs import (
  | 2025-08-13T10:31:40.000Z | ...<5 lines>...
  | 2025-08-13T10:31:40.000Z | )
  | 2025-08-13T10:31:40.000Z | ImportError: cannot import name 'std_to_otel' from 'opentelemetry._logs' (/var/task/opentelemetry/_logs/__init__.py)
  | 2025-08-13T10:31:40.003Z | Failed to auto initialize OpenTelemetry
  | 2025-08-13T10:31:40.003Z | Traceback (most recent call last):
  | 2025-08-13T10:31:40.003Z | File "/opt/python/opentelemetry/instrumentation/auto_instrumentation/__init__.py", line 130, in initialize
 

digjanaik27193 avatar Aug 13 '25 10:08 digjanaik27193