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

Recursive Logging bug in Docker: Invalid type NoneType for attribute 'taskName' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types #3560

Closed
jeremydvoss opened this issue Nov 28, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@jeremydvoss
Copy link
Contributor

jeremydvoss commented Nov 28, 2023

Describe your environment Docker compose that includes 1.21/0.42b0 of the API/SDK and contrib. I manually set PYTHONPATH to point to sitecustomize in order to trigger auto-instrumentation. However, the same app and sitecustomize work outside of docker

Steps to reproduce
Dockerfile:

FROM python

# Create app directory
WORKDIR /usr/src/pythonapp

COPY test_app.py ./
# TODO: Copy json for AAD and statsbeat
# copy applicationinsights.json if it exists. This is used for AAD authentication and statsbeat
# COPY applicationinsights.json* ./

EXPOSE 8082

RUN python3 -m ensurepip && \
    python3 -m pip install flask && \
    python3 -m pip install requests && \
    pip list

EXPOSE 8082
CMD [ "python3", "test_app.py" ]

docker-compose.yml:

version: "3.9"

services:
  inprocagent:
    image: {Image with SDK/API 1.21, Instrumentations 0.42b0 and sitecustomize}
    volumes: 
      - "agentvolume:/agents"
  pythonapp:
    build:
      context: ./TestApp
    ports:
      - "${PYTHON_TEST_APP_PORT}:${PYTHON_TEST_APP_PORT}"
    volumes: 
      - "agentvolume:/agents"
    environment:
      APPLICATIONINSIGHTS_CONNECTION_STRING: ${APPLICATIONINSIGHTS_CONNECTION_STRING} 
      PYTHONPATH: ${PYTHONPATH}
      PYTHON_TEST_APP_PORT: ${PYTHON_TEST_APP_PORT}
      OTEL_TRACES_EXPORTER: ${OTEL_TRACES_EXPORTER}
      OTEL_METRICS_EXPORTER: ${OTEL_METRICS_EXPORTER}
     PYTHONPATH=/agents/python
    stdin_open: true 
    tty: true
volumes:
  agentvolume:

test_app.py:

import logging
logger = logging.getLogger(__name__)
logger.error("TEST")

Commands:

docker compose build
docker compose up

What is the expected behavior?
Logs are instrumented and exported.

What is the actual behavior?
I get an infinite stack trace loop:

…
File "/usr/local/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/agents/python/opentelemetry/sdk/_logs/_internal/__init__.py", line 541, in emit
    self._logger.emit(self._translate(record))
                      ^^^^^^^^^^^^^^^^^^^^^^^
  File "/agents/python/opentelemetry/sdk/_logs/_internal/__init__.py", line 522, in _translate
    return LogRecord(
           ^^^^^^^^^^
  File "/agents/python/opentelemetry/sdk/_logs/_internal/__init__.py", line 183, in __init__
    "attributes": BoundedAttributes(
                  ^^^^^^^^^^^^^^^^^^
  File "/agents/python/opentelemetry/attributes/__init__.py", line 154, in __init__
    self[key] = value
    ~~~~^^^^^
  File "/agents/python/opentelemetry/attributes/__init__.py", line 173, in __setitem__
    value = _clean_attribute(key, value, self.max_value_len)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/agents/python/opentelemetry/attributes/__init__.py", line 100, in _clean_attribute
    _logger.warning(
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1551, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1684, in _log
    self.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
…

By adding print statements into the attributes module, I figured out that the warning is as follows:
Invalid type NoneType for attribute 'taskName' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

My guess is that the taskName is None because it is running inside Docker or something along those lines.

Additional context
Add any other context about the problem here.

@jeremydvoss jeremydvoss added the bug Something isn't working label Nov 28, 2023
@jeremydvoss
Copy link
Contributor Author

This may be an issue with 3.12:
#3370

@jeremydvoss
Copy link
Contributor Author

Downgrading to python:3.11 works!

@jeremydvoss
Copy link
Contributor Author

#3617

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

1 participant