Skip to content

🐛 Bug Report: Init tracing throws ValueError #2699

@obs-gh-abhishekrao

Description

@obs-gh-abhishekrao

Which component is this bug for?

Traceloop SDK

📜 Description

We're running models backed by gunicorn on Python 3.11. When we try to instrument our service, we encounter this error:

Failed to init tracing
Traceback (most recent call last):
  File "/code/python/service/ai_agents/gunicorn_conf.py", line 40, in post_fork
    Traceloop.init(
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/traceloop/sdk/__init__.py", line 154, in init
    Traceloop.__tracer_wrapper = TracerWrapper(
                                 ^^^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/traceloop/sdk/tracing/tracing.py", line 84, in __new__
    obj.__tracer_provider = init_tracer_provider(resource=obj.__resource)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/traceloop/sdk/tracing/tracing.py", line 336, in init_tracer_provider
    provider = TracerProvider(resource=resource)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/opentelemetry/sdk/trace/__init__.py", line 1212, in __init__
    self._span_limits = span_limits or SpanLimits()
                                       ^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/opentelemetry/sdk/trace/__init__.py", line 624, in __init__
    self.max_events = self._from_env_if_absent(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/opentelemetry/sdk/trace/__init__.py", line 713, in _from_env_if_absent
    raise ValueError(err_msg.format(env_var, value))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: cannot switch from manual field specification to automatic field numbering

👟 Reproduction steps

Python verison: 3.11
Dependencies:

langgraph = "^0.1.16"
gunicorn = "^22.0.0"
humanize = "^4.10.0"
uvicorn = "^0.34.0"
traceloop-sdk = "^0.38.8"
langchain-community = "^0.2.19"
langchain-openai = "0.1.25"

Please note the following is an excerpt of the a setup, not necessarily the exact reproduction steps. The main criteria here is to have a fastapi app backed by gunicorn. Our gunicorn_conf.py entrypoint looks like this:

"""Gunicorn Configuration file."""
import logging
import os
from typing import Any

from dotenv import load_dotenv
from traceloop.sdk import Traceloop

logger = logging.getLogger(__name__)

# to see available configuration values check
# https://docs.gunicorn.org/en/stable/settings.html

bind = "0.0.0.0:3000"

# Number of Gunicorn worker processes
# We set this to 1 because having more workers will affect performance
# (in terms of latency) and may explode the GPU mem usage
workers = 1
worker_class = "uvicorn.workers.UvicornWorker"

# Logging settings (optional)
accesslog = "-"  # Log to stdout
errorlog = "-"  # Log to stderr
loglevel = "info"  # Adjust log level as needed

# timeout in seconds, a worker that takes longer than this will be killed and
# restarted
# https://docs.gunicorn.org/en/stable/settings.html#timeout
timeout = 300


def post_fork(server: Any, worker: Any) -> None:
    """Perform post-fork actions."""
    server.log.info("Worker spawned (pid: %s)", worker.pid)
    load_dotenv(override=True)

    # Initialize tracing
    try:
        Traceloop.init(
            app_name=os.getenv("OTEL_SERVICE_NAME"),
            resource_attributes={
                "deployment.environment": os.getenv("TRACELOOP_ENV")},
            telemetry_enabled=False,
        )
    except Exception as e:
        logger.critical("Failed to init tracing", exc_info=e,
                        extra={"exception_message": str(e)})

Run as: poetry run gunicorn -c gunicorn_conf.py 'ai_agents.app:ServiceApp(allowed_tokens=None)'

👍 Expected behavior

It should successfully initialize the tracer.

👎 Actual Behavior with Screenshots

It throws the following error:

Failed to init tracing
Traceback (most recent call last):
  File "/code/python/service/ai_agents/gunicorn_conf.py", line 40, in post_fork
    Traceloop.init(
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/traceloop/sdk/__init__.py", line 154, in init
    Traceloop.__tracer_wrapper = TracerWrapper(
                                 ^^^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/traceloop/sdk/tracing/tracing.py", line 84, in __new__
    obj.__tracer_provider = init_tracer_provider(resource=obj.__resource)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/traceloop/sdk/tracing/tracing.py", line 336, in init_tracer_provider
    provider = TracerProvider(resource=resource)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/opentelemetry/sdk/trace/__init__.py", line 1212, in __init__
    self._span_limits = span_limits or SpanLimits()
                                       ^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/opentelemetry/sdk/trace/__init__.py", line 624, in __init__
    self.max_events = self._from_env_if_absent(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/python/service/ai_agents/.venv/lib/python3.11/site-packages/opentelemetry/sdk/trace/__init__.py", line 713, in _from_env_if_absent
    raise ValueError(err_msg.format(env_var, value))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: cannot switch from manual field specification to automatic field numbering

🤖 Python Version

3.11

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions