Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.59k stars 2.8k forks source link

Azure Function Event Hub Trigger - event.iothub_metadata returns empty dict #8533

Closed bran-ch closed 4 years ago

bran-ch commented 4 years ago

When streaming IoT Hub data into Event Hub, the fields in the EventHubEvent are not correctly populated.

import logging
import azure.functions as func

def main(event: func.EventHubEvent):
    body = event.get_body().decode('utf-8')
    logging.info('Body: ' + body) # Returns the body as expected
    logging.info('IoT Hub Metadata: ' + str(event.iothub_metadata)) # Returns an empty dict, not expected

I am using IoT Central and the same data stream to a blob storage provides a Properties and SystemProperties field. On further investigation, the SDK seems to use EventHubTriggerConverter (in functions/eventhub.py) to convert the incoming event and extracts the metadata like so:

class EventHubTriggerConverter(EventHubConverter,
                               binding='eventHubTrigger', trigger=True):
...
    @classmethod
    def decode_single_event(cls, data,
                            trigger_metadata) -> _eventhub.EventHubEvent:
...
        iothub_metadata = {}
        for f in trigger_metadata:
            if f.startswith('iothub-'):
                v = cls._decode_trigger_metadata_field(
                    trigger_metadata, f, python_type=str)
                iothub_metadata[f[len('iothub-'):]] = v

but the trigger_metadata is a dict with Properties and SystemProperties included.

kaerm commented 4 years ago

@bran-ch thanks for reporting this, our team will look into this. //cc: @mayurid @yunhaoling

etf5000 commented 4 years ago

Seeing the same issue. The metadata seems to be exposed correctly using the JavaScript and .net SDK.

annatisch commented 4 years ago

@kaerm - This seems to be related to Azure Functions and/or IoT Hub - do you know the best person to direct it to?

ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ ahmedelnably, @fabiocav

ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @iluican @jlian

jlian commented 4 years ago

@iluican can you assign someone to look at this?

jlian commented 4 years ago

@jebrando is this part of the python client SDK?

jebrando commented 4 years ago

@jlian I believe this is from the Eventhub SDK and not the IoTHub SDK. You may have to ping someone in that area.

jlian commented 4 years ago

@kaerm can you help redirect?

kaerm commented 4 years ago

@yunhaoling can you take a look?

yunhaoling commented 4 years ago

Hi @kaerm , I don't think the code is part of our python EventHub SDK but it could be the Azure Function Event Hub Trigger that uses our sdk. Anyway I think we'd better reach out to the related Azure Function Team for more information.

kaerm commented 4 years ago

Thanks @yunhaoling //cc: @mayurid

YijunXieMS commented 4 years ago

Azure function team is looking

Hazhzeng commented 4 years ago

Hey @bran-ch,

After investigation, this is due to a schema change in function triggers metadata. https://github.com/Azure/azure-functions-python-worker/issues/418

Hazhzeng commented 4 years ago

This issue should be fixed in the next release.

ramya-rao-a commented 4 years ago

Looks like the upstream issue https://github.com/Azure/azure-functions-python-worker/issues/418 is closed as fixed, but folks are still reporting problems.

If anyone here is still seeing this issue, please log a new GitHub issue at https://github.com/Azure/azure-functions-python-worker

Closing this issue as there are nothing that can be done from the Python Event Hubs SDK perspective.

ramya-rao-a commented 4 years ago

Also, based on https://github.com/Azure/azure-functions-python-worker/issues/639 and https://github.com/Azure/azure-functions-python-worker/issues/698, it looks like we are just waiting for the next deployment of the python worker