Move datadog api logic into function for re-use