🐛 Bug Report: Bedrock instrumentation: uninstrument() does not remove tracing from clients created while instrumented
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- aws, python
- Lĩnh vực
- observability
Hướng nghiên cứu
Start with _wrap and _uninstrument in packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py, then inspect the existing Bedrock instrumentation tests for client creation and teardown coverage. Reproduce with a client created before uninstrument() and verify it no longer emits spans afterward, including the async path if covered by the tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Which component is this bug for?
Bedrock Instrumentation
📜 Description
After BedrockInstrumentor().uninstrument(), a bedrock-runtime client that was created while the instrumentation was active keeps creating spans. Only clients created after uninstrument() are untraced. Clients are usually created once at start-up, so in practice uninstrument() has no effect on an application's existing clients (and on test suites that instrument / uninstrument around a shared client).
Cause: _wrap replaces the API methods on each new client instance (client.invoke_model = ..., client.converse = ..., and the streaming variants; same in the aiobotocore path), but _uninstrument only unwraps create_client. The replaced methods on existing clients are never restored, and the wrappers do not check whether the instrumentor is still active.
_wrapL166: https://github.com/traceloop/openllmetry/blob/df4921a40940cdce136c4409380a55e9d4c7a96d/packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py#L166_uninstrumentL1259: https://github.com/traceloop/openllmetry/blob/df4921a40940cdce136c4409380a55e9d4c7a96d/packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py#L1259
This is different from #4552 (OpenAI unwrap() being a no-op): here create_client is unwrapped correctly, but clients that already exist stay instrumented.
👟 Reproduction steps
pip install boto3 opentelemetry-instrumentation-bedrock opentelemetry-sdk
python repro.py
import json, logging
from importlib.metadata import version
logging.disable(logging.WARNING)
import boto3
from botocore.awsrequest import AWSResponse
from botocore.config import Config
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.instrumentation.bedrock import BedrockInstrumentor
exporter = InMemorySpanExporter()
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(exporter))
class Raw: # a canned Converse response, no network
def __init__(self, data): self.data = data
def stream(self, *a, **k): yield self.data
def read(self, amt=None): return self.data
def close(self): pass
release_conn = close
def before_send(request, **_):
out = {"output": {"message": {"role": "assistant", "content": [{"text": "hi"}]}}, "stopReason": "end_turn",
"usage": {"inputTokens": 3, "outputTokens": 1, "totalTokens": 4}, "metrics": {"latencyMs": 1}}
return AWSResponse(request.url, 200, {"content-type": "application/json"}, Raw(json.dumps(out).encode()))
def new_client():
c = boto3.client("bedrock-runtime", region_name="us-east-1", aws_access_key_id="x", aws_secret_access_key="x",
config=Config(retries={"total_max_attempts": 1}))
c.meta.events.register("before-send.bedrock-runtime.*", before_send)
return c
def spans_for(client):
exporter.clear()
client.converse(modelId="anthropic.claude-3-haiku-20240307-v1:0",
messages=[{"role": "user", "content": [{"text": "hi"}]}])
return len(exporter.get_finished_spans())
print("boto3", version("boto3"), "| opentelemetry-instrumentation-bedrock", version("opentelemetry-instrumentation-bedrock"))
BedrockInstrumentor().instrument(tracer_provider=provider)
early = new_client() # created while instrumented (typical: at app start-up)
print("instrumented: client created before ->", spans_for(early), "span(s)")
BedrockInstrumentor().uninstrument()
print("uninstrumented: client created before ->", spans_for(early), "span(s) (expected 0)")
print("uninstrumented: client created after ->", spans_for(new_client()), "span(s) (expected 0)")
👍 Expected behavior
After uninstrument(), no client creates spans, including clients created earlier.
Possible fixes: have the per-client wrappers call straight through to the original method once the instrumentor is uninstrumented (a flag checked at call time), or keep a weakref.WeakSet of instrumented clients and restore their original methods in _uninstrument.
👎 Actual Behavior with Screenshots
The client created before uninstrument() is still traced:
boto3 1.43.108 | opentelemetry-instrumentation-bedrock 0.62.4
instrumented: client created before -> 1 span(s)
uninstrumented: client created before -> 1 span(s) (expected 0)
uninstrumented: client created after -> 0 span(s) (expected 0)
🤖 Python Version
3.12
📃 Provide any additional context for the Bug.
OS: Ubuntu Linux. boto3 / botocore 1.43.108, opentelemetry-instrumentation-bedrock 0.62.4.
👀 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?
Yes I am willing to submit a PR!
- Ngôn ngữ chính
- Python
- Star
- 7.5k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của traceloop/openllmetry
-
🐛 Bug Report: OpenAI Responses: with_raw_response.create() raises when the body can't be parsed, though the uninstrumented call returnsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4717 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentationCó thể đã có người làm @Quantum-Enigma-dot đã nhận 21 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4665 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completionsCó thể đã có người làm @jayfeng7 đã nhận 23 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
traceloop/openllmetry#4660 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Report: Failed dataset deletes still remove local rows and columnsCó thể đã có người làm @inchang-ing đã nhận 32 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
traceloop/openllmetry#4630 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penaltyCó thể đã có người làm @shantam77 đã nhận 38 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
traceloop/openllmetry#4598 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của traceloop/openllmetry
Issue tương tự
-
CI flake: test-windows times out spawning Node in tests/test_antigravity_node_hooks.py (develop red)Đang mởarea/ci P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
benchmark
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
mozilla-ai/cq#601 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bump Python to 3.14 or 3.15Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày