def _get_lifetime_sequence(message):
    """Determine a suitable lifetime sequence number from a tahu birth/death message.

    Ideally this will be the bdSeq metric of the message. Since the bdSeq number
    is not guaranteed to be present, e.g. for node architectures that don't
    support it or all devices, we fall back to using timestamps as a proxy.

    Timestamps should always be present in a Sparkplug-B payload. A returned
    value of ``None`` indicates that the given message was not timestamped for
    whatever reason, and that the caller should track endpoint lifetime
    sequences manually.
    """

    for metric in message.metrics:
        if metric.name == 'bdSeq':
            return metric.long_value

    if message.HasField('timestamp'):
        return message.timestamp