Skip to content

🐛 Bug Report: Resetting async context doesn't work after update to 0.44.0 #3231

@zmievsa-semasoftware

Description

@zmievsa-semasoftware

Which component is this bug for?

Langchain Instrumentation

📜 Description

Ever since I updated from 0.40.14, I started getting the following errors. It seems like it happens because I am jumping from sync to async and back but I am not very sure.

Errors

This one starts at 0.44.0:

Traceback (most recent call last):
  File "<project_root>/.venv/lib/python3.12/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "<project_root>/.venv/lib/python3.12/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x103000090> at 0x15fc8a200> was created in a different Context

And looks like this is the offender: 168236a

Opentelemetry lib versions

opentelemetry-api==1.36.0
opentelemetry-distro==0.57b0
opentelemetry-exporter-otlp==1.36.0
opentelemetry-exporter-otlp-proto-common==1.36.0
opentelemetry-exporter-otlp-proto-grpc==1.36.0
opentelemetry-exporter-otlp-proto-http==1.36.0
opentelemetry-instrumentation==0.57b0
opentelemetry-instrumentation-aiohttp-client==0.57b0
opentelemetry-instrumentation-aiohttp-server==0.57b0
opentelemetry-instrumentation-asgi==0.57b0
opentelemetry-instrumentation-asyncio==0.57b0
opentelemetry-instrumentation-boto3sqs==0.57b0
opentelemetry-instrumentation-botocore==0.57b0
opentelemetry-instrumentation-click==0.57b0
opentelemetry-instrumentation-dbapi==0.57b0
opentelemetry-instrumentation-django==0.57b0
opentelemetry-instrumentation-grpc==0.57b0
opentelemetry-instrumentation-httpx==0.57b0
opentelemetry-instrumentation-jinja2==0.57b0
opentelemetry-instrumentation-langchain==0.44.1
opentelemetry-instrumentation-logging==0.57b0
opentelemetry-instrumentation-openai-v2==2.1b0
opentelemetry-instrumentation-psycopg==0.57b0
opentelemetry-instrumentation-requests==0.57b0
opentelemetry-instrumentation-sqlalchemy==0.57b0
opentelemetry-instrumentation-sqlite3==0.57b0
opentelemetry-instrumentation-threading==0.57b0
opentelemetry-instrumentation-tortoiseorm==0.57b0
opentelemetry-instrumentation-urllib==0.57b0
opentelemetry-instrumentation-urllib3==0.57b0
opentelemetry-instrumentation-wsgi==0.57b0
opentelemetry-propagator-aws-xray==1.0.2
opentelemetry-proto==1.36.0
opentelemetry-sdk==1.36.0
opentelemetry-semantic-conventions==0.57b0
opentelemetry-semantic-conventions-ai==0.4.11
opentelemetry-util-http==0.57b0

👟 Reproduction steps

Still working on it, it's a part of the big project so I'm still wondering what causes it. But it is definitely related to update of opentelemetry-instrumentation-langchain from 0.40.14.

👍 Expected behavior

It should produce no such errors as it did before

👎 Actual Behavior with Screenshots

It produces a lot of ValueErrors when trying to reset context.

🤖 Python Version

3.12.10

📃 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions