azure-sdk-for-python: Azure Function Event Hub Trigger - event.iothub_metadata returns empty dict

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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 17 (11 by maintainers)

Most upvoted comments

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