From c0ee2bbaf59441ad779fc656466cea00cd2cbcc8 Mon Sep 17 00:00:00 2001 From: Ben Drucker Date: Wed, 3 Dec 2025 14:00:59 -0800 Subject: [PATCH 1/4] botocore: document threading instrumentation for S3 multipart operations Document that users need to enable ThreadingInstrumentor alongside BotocoreInstrumentor for proper trace context propagation with S3 upload_file and download_file methods. --- .../README.rst | 16 ++++++++++++++++ .../instrumentation/botocore/__init__.py | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/README.rst b/instrumentation/opentelemetry-instrumentation-botocore/README.rst index 5b70922e07..1120aa7f73 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/README.rst +++ b/instrumentation/opentelemetry-instrumentation-botocore/README.rst @@ -46,6 +46,22 @@ Tool calls with InvokeModel and InvokeModelWithResponseStream APIs are supported If you don't have an application using Bedrock APIs yet, try our `zero-code examples `_. +Thread Context Propagation +-------------------------- + +boto3's S3 ``upload_file`` and ``download_file`` methods use background threads +for multipart transfers. To ensure trace context is propagated to these threads, +also enable the threading instrumentation:: + + from opentelemetry.instrumentation.threading import ThreadingInstrumentor + from opentelemetry.instrumentation.botocore import BotocoreInstrumentor + + ThreadingInstrumentor().instrument() + BotocoreInstrumentor().instrument() + +When using auto-instrumentation (``opentelemetry-instrument``), both instrumentors +are enabled automatically if their packages are installed. + Installation ------------ diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index bf672f7841..effd8e5553 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -78,6 +78,24 @@ def response_hook(span, service_name, operation_name, result): ) ec2 = session.create_client("ec2", region_name="us-west-2") ec2.describe_instances() + +Thread Context Propagation +-------------------------- + +boto3's S3 ``upload_file`` and ``download_file`` methods use background threads +for multipart transfers. To ensure trace context is propagated to these threads, +also enable the threading instrumentation: + +.. code:: python + + from opentelemetry.instrumentation.threading import ThreadingInstrumentor + from opentelemetry.instrumentation.botocore import BotocoreInstrumentor + + ThreadingInstrumentor().instrument() + BotocoreInstrumentor().instrument() + +When using auto-instrumentation (``opentelemetry-instrument``), both instrumentors +are enabled automatically if their packages are installed. """ import logging From eb1042968b0bd8a1596ebd5b66d281241d81cca3 Mon Sep 17 00:00:00 2001 From: Ben Drucker Date: Thu, 4 Dec 2025 09:03:44 -0800 Subject: [PATCH 2/4] botocore: move thread context docs to module docstring only README.rst is not built into the documentation, so keep the threading context propagation docs only in __init__.py where autodoc will pick them up. --- .../README.rst | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/README.rst b/instrumentation/opentelemetry-instrumentation-botocore/README.rst index 1120aa7f73..5b70922e07 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/README.rst +++ b/instrumentation/opentelemetry-instrumentation-botocore/README.rst @@ -46,22 +46,6 @@ Tool calls with InvokeModel and InvokeModelWithResponseStream APIs are supported If you don't have an application using Bedrock APIs yet, try our `zero-code examples `_. -Thread Context Propagation --------------------------- - -boto3's S3 ``upload_file`` and ``download_file`` methods use background threads -for multipart transfers. To ensure trace context is propagated to these threads, -also enable the threading instrumentation:: - - from opentelemetry.instrumentation.threading import ThreadingInstrumentor - from opentelemetry.instrumentation.botocore import BotocoreInstrumentor - - ThreadingInstrumentor().instrument() - BotocoreInstrumentor().instrument() - -When using auto-instrumentation (``opentelemetry-instrument``), both instrumentors -are enabled automatically if their packages are installed. - Installation ------------ From f510b861c4c816d68b3349c0a58cf7a01366593c Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 5 Dec 2025 16:57:01 +0100 Subject: [PATCH 3/4] Update __init__.py --- .../instrumentation/botocore/__init__.py | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index effd8e5553..11bc2b0ffd 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -42,16 +42,34 @@ ec2 = session.create_client("ec2", region_name="us-west-2") ec2.describe_instances() +Thread Context Propagation +-------------------------- + +boto3's S3 ``upload_file`` and ``download_file`` methods use background threads +for multipart transfers. To ensure trace context is propagated to these threads, +also enable the threading instrumentation: + +.. code:: python + + from opentelemetry.instrumentation.threading import ThreadingInstrumentor + from opentelemetry.instrumentation.botocore import BotocoreInstrumentor + + ThreadingInstrumentor().instrument() + BotocoreInstrumentor().instrument() + +When using auto-instrumentation (``opentelemetry-instrument``), both instrumentors +are enabled automatically if their packages are installed. + API --- The `instrument` method accepts the following keyword args: -tracer_provider (TracerProvider) - an optional tracer provider -request_hook (Callable) - a function with extra user-defined logic to be performed before performing the request -this function signature is: def request_hook(span: Span, service_name: str, operation_name: str, api_params: dict) -> None -response_hook (Callable) - a function with extra user-defined logic to be performed after performing the request -this function signature is: def response_hook(span: Span, service_name: str, operation_name: str, result: dict) -> None +* tracer_provider (TracerProvider) - an optional tracer provider +* request_hook (Callable) - a function with extra user-defined logic to be performed before performing the request +this function signature is: ``def request_hook(span: Span, service_name: str, operation_name: str, api_params: dict) -> None`` +* response_hook (Callable) - a function with extra user-defined logic to be performed after performing the request +this function signature is: ``def response_hook(span: Span, service_name: str, operation_name: str, result: dict) -> None`` for example: @@ -78,24 +96,6 @@ def response_hook(span, service_name, operation_name, result): ) ec2 = session.create_client("ec2", region_name="us-west-2") ec2.describe_instances() - -Thread Context Propagation --------------------------- - -boto3's S3 ``upload_file`` and ``download_file`` methods use background threads -for multipart transfers. To ensure trace context is propagated to these threads, -also enable the threading instrumentation: - -.. code:: python - - from opentelemetry.instrumentation.threading import ThreadingInstrumentor - from opentelemetry.instrumentation.botocore import BotocoreInstrumentor - - ThreadingInstrumentor().instrument() - BotocoreInstrumentor().instrument() - -When using auto-instrumentation (``opentelemetry-instrument``), both instrumentors -are enabled automatically if their packages are installed. """ import logging From 8a7e49beff3d4945a498be35960100c9dff41166 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 5 Dec 2025 17:05:13 +0100 Subject: [PATCH 4/4] Update __init__.py --- .../opentelemetry/instrumentation/botocore/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index 11bc2b0ffd..a5c4bd1c19 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -65,15 +65,13 @@ The `instrument` method accepts the following keyword args: -* tracer_provider (TracerProvider) - an optional tracer provider -* request_hook (Callable) - a function with extra user-defined logic to be performed before performing the request -this function signature is: ``def request_hook(span: Span, service_name: str, operation_name: str, api_params: dict) -> None`` -* response_hook (Callable) - a function with extra user-defined logic to be performed after performing the request -this function signature is: ``def response_hook(span: Span, service_name: str, operation_name: str, result: dict) -> None`` +* tracer_provider (``TracerProvider``) - an optional tracer provider +* request_hook (``Callable[[Span, str, str, dict], None]``) - a function with extra user-defined logic to be performed before performing the request +* response_hook (``Callable[[Span, str, str, dict], None]``) - a function with extra user-defined logic to be performed after performing the request for example: -.. code: python +.. code:: python from opentelemetry.instrumentation.botocore import BotocoreInstrumentor import botocore.session