Skip to content

Commit e8baf08

Browse files
committed
update botocore patch function signatures
1 parent 944102e commit e8baf08

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_bedrock_patches.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
_AttributeMapT,
3232
_AwsSdkCallContext,
3333
_AwsSdkExtension,
34+
_BotocoreInstrumentorContext,
3435
_BotoResultT,
3536
)
3637
from opentelemetry.trace.span import Span
@@ -192,7 +193,7 @@ def extract_attributes(self, attributes: _AttributeMapT):
192193
if request_param_value:
193194
attributes[attribute_key] = request_param_value
194195

195-
def on_success(self, span: Span, result: _BotoResultT):
196+
def on_success(self, span: Span, result: _BotoResultT, instrumentor_context: _BotocoreInstrumentorContext):
196197
if self._operation_class is None:
197198
return
198199

@@ -229,7 +230,7 @@ class _BedrockExtension(_AwsSdkExtension):
229230
"""
230231

231232
# pylint: disable=no-self-use
232-
def on_success(self, span: Span, result: _BotoResultT):
233+
def on_success(self, span: Span, result: _BotoResultT, instrumentor_context: _BotocoreInstrumentorContext):
233234
# _GUARDRAIL_ID can only be retrieved from the response, not from the request
234235
guardrail_id = result.get(_GUARDRAIL_ID)
235236
if guardrail_id:
@@ -333,7 +334,7 @@ def _set_if_not_none(attributes, key, value):
333334
attributes[key] = value
334335

335336
# pylint: disable=too-many-branches
336-
def on_success(self, span: Span, result: Dict[str, Any]):
337+
def on_success(self, span: Span, result: Dict[str, Any], instrumentor_context: _BotocoreInstrumentorContext):
337338
model_id = self._call_context.params.get(_MODEL_ID)
338339

339340
if not model_id:

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_botocore_patches.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
from opentelemetry.instrumentation.botocore.extensions.lmbd import _LambdaExtension
2626
from opentelemetry.instrumentation.botocore.extensions.sns import _SnsExtension
2727
from opentelemetry.instrumentation.botocore.extensions.sqs import _SqsExtension
28-
from opentelemetry.instrumentation.botocore.extensions.types import _AttributeMapT, _AwsSdkExtension, _BotoResultT
28+
from opentelemetry.instrumentation.botocore.extensions.types import (
29+
_AttributeMapT,
30+
_AwsSdkExtension,
31+
_BotocoreInstrumentorContext,
32+
_BotoResultT,
33+
)
2934
from opentelemetry.semconv.trace import SpanAttributes
3035
from opentelemetry.trace.span import Span
3136

@@ -75,8 +80,8 @@ def patch_extract_attributes(self, attributes: _AttributeMapT):
7580

7681
old_on_success = _LambdaExtension.on_success
7782

78-
def patch_on_success(self, span: Span, result: _BotoResultT):
79-
old_on_success(self, span, result)
83+
def patch_on_success(self, span: Span, result: _BotoResultT, instrumentor_context: _BotocoreInstrumentorContext):
84+
old_on_success(self, span, result, instrumentor_context)
8085
lambda_configuration = result.get("Configuration", {})
8186
function_arn = lambda_configuration.get("FunctionArn")
8287
if function_arn:
@@ -180,8 +185,8 @@ def patch_extract_attributes(self, attributes: _AttributeMapT):
180185

181186
old_on_success = _SqsExtension.on_success
182187

183-
def patch_on_success(self, span: Span, result: _BotoResultT):
184-
old_on_success(self, span, result)
188+
def patch_on_success(self, span: Span, result: _BotoResultT, instrumentor_context: _BotocoreInstrumentorContext):
189+
old_on_success(self, span, result, instrumentor_context)
185190
queue_url = result.get("QueueUrl")
186191
if queue_url:
187192
span.set_attribute(AWS_SQS_QUEUE_URL, queue_url)
@@ -243,7 +248,7 @@ def extract_attributes(self, attributes: _AttributeMapT):
243248
attributes[AWS_SECRETSMANAGER_SECRET_ARN] = secret_id
244249

245250
# pylint: disable=no-self-use
246-
def on_success(self, span: Span, result: _BotoResultT):
251+
def on_success(self, span: Span, result: _BotoResultT, instrumentor_context: _BotocoreInstrumentorContext):
247252
secret_arn = result.get("ARN")
248253
if secret_arn:
249254
span.set_attribute(AWS_SECRETSMANAGER_SECRET_ARN, secret_arn)

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_instrumentation_patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ def _do_on_success(
678678
) -> Dict[str, str]:
679679
span_mock: Span = MagicMock()
680680
mock_call_context = MagicMock()
681+
mock_instrumentor_context = MagicMock()
681682
span_attributes: Dict[str, str] = {}
682683

683684
def set_side_effect(set_key, set_value):
@@ -692,6 +693,6 @@ def set_side_effect(set_key, set_value):
692693
mock_call_context.params = params
693694

694695
extension = _KNOWN_EXTENSIONS[service_name]()(mock_call_context)
695-
extension.on_success(span_mock, result)
696+
extension.on_success(span_mock, result, mock_instrumentor_context)
696697

697698
return span_attributes

0 commit comments

Comments
 (0)