Using Entity API, if given an entity in a function scope, how do you get the entity type?
There are various (convoluted) methods for getting the entity type and bundle, but none that I'd consider "acceptable" on a large-scale. What I've done is implemented hook_entity_load() and added the entity_id and entity_type properties on all entities at load-time. 

The following code does this, and is part of the Devtools module I maintain:

function hook_entity_load($entities, $type) {
  // add the entity type &amp; id to all entity objects for easy data access
  // from other hooks &amp; modules
  foreach ($entities as $entity) {
    // we don't want to add these entity fields when the entity is being exported into
    // a feature, otherwise the feature will always show as overridden and will not 
    // revert
    if (  preg_match('#admin/structure/features#', $_GET['q'])  // features page
            || 
          (                                                     // drush fu command
            isset($_SERVER['SCRIPT_FILENAME']) &amp;&amp; 
            preg_match('/drush\.php$/', $_SERVER['SCRIPT_FILENAME']) &amp;&amp;
            isset($_SERVER['argv'][2]) &amp;&amp;
            $_SERVER['argv'][2] == 'fu'
          )
       ) {
      continue;
    }

    // set entity_type
      $entity_type_field = (!isset($entity-&gt;entity_type)) ? 'entity_type' : 'devtools_entity_type';
      $entity-&gt;{$entity_type_field} = $type;

    // set entity_id
      $entity_id_field = (!isset($entity-&gt;entity_id)) ? 'entity_id' : 'devtools_entity_id';
      list($entity-&gt;{$entity_id_field}, $vid, $bundle) = entity_extract_ids($type, $entity);
  }
}