opentelemetry-lambda icon indicating copy to clipboard operation
opentelemetry-lambda copied to clipboard

[BUG] boto3 invoke method can not be instrumented

Open mat-rumian opened this issue 4 years ago • 2 comments

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

mat-rumian avatar Oct 26 '21 10:10 mat-rumian

This issue was marked stale. It will be closed in 30 days without additional activity.

github-actions[bot] avatar Aug 04 '24 03:08 github-actions[bot]

@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?

serkan-ozal avatar Sep 02 '24 18:09 serkan-ozal

This issue was marked stale. It will be closed in 30 days without additional activity.

github-actions[bot] avatar Sep 07 '25 03:09 github-actions[bot]

Closed as inactive. Feel free to reopen if this issue is still relevant.

github-actions[bot] avatar Oct 08 '25 03:10 github-actions[bot]