opentelemetry-lambda
opentelemetry-lambda copied to clipboard
[BUG] boto3 invoke method can not be instrumented
In case of lambda function invoking other function there is a problem with instrumentation of the invoke method.
Example lambda code:
import json
import os
import boto3
FUNCTION_NAME = os.getenv('INVOKE_FUNCTION_NAME')
client = boto3.client('lambda')
def invoke(sweets):
print('Invoke %s with data: %s' % (FUNCTION_NAME, sweets))
response = client.invoke(
FunctionName=FUNCTION_NAME,
InvocationType='RequestResponse',
Payload=json.dumps(sweets),
)
return response
def get_sweets(event, context):
body = event['body']
print('Check if %s is available' % str(body))
response = invoke(body)
payload = json.loads(response["Payload"].read())
return {'statusCode': payload['statusCode'], 'body': json.dumps(payload['body'])}
Error
[ERROR] AttributeError: 'str' object has no attribute 'get'
Traceback (most recent call last):
File "/opt/python/opentelemetry/instrumentation/aws_lambda/__init__.py", line 222, in _instrumented_lambda_handler_call
result = call_wrapped(*args, **kwargs)
File "/var/task/check_sweets.py", line 24, in get_sweets
response = invoke(body)
File "/var/task/check_sweets.py", line 12, in invoke
response = client.invoke(
File "/var/task/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/python/opentelemetry/instrumentation/botocore/__init__.py", line 215, in _patched_api_call
BotocoreInstrumentor._patch_lambda_invoke(call_context.params)
File "/opt/python/opentelemetry/instrumentation/botocore/__init__.py", line 178, in _patch_lambda_invoke
headers = payload.get("headers",
{}
)
Environment
- AWS Lambda Python 3.8 runtime
- opentelemetry-instrumentation 0.24b0 (tested also on 0.25b2)
- opentelemetry-instrumentation-boto 0.24b0 (tested also on 0.25b2)
- opentelemetry-instrumentation-botocore 0.24b0 (tested also on 0.25b2)
- boto3 - tested on various versions the same result
This issue was marked stale. It will be closed in 30 days without additional activity.
@mat-rumian I think this issue might be already fixed by this PR: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/760/files Can you verify that with the latest version?
This issue was marked stale. It will be closed in 30 days without additional activity.
Closed as inactive. Feel free to reopen if this issue is still relevant.